/
__main__.py
111 lines (89 loc) · 3.16 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
# Coil CMS v1.2.0
# Copyright © 2014-2017 Chris Warrick, Roberto Alsina, Henry Hirsch et al.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
u"""Coil CMS v{0}
Usage:
coil devserver [-b | --browser] [-p <port> | --port=<port>] [--no-url-fix] [--no-debug]
coil unlock
coil write_users
coil -h | --help
coil --version
Options:
-h, --help Show help screen.
--version Show version.
-b, --browser Open Coil CMS in the browser after starting.
-p <port>, --port=<port> Port to use [default: 8001].
"""
from __future__ import unicode_literals
import coil
import coil.utils
import sys
import docopt
import webbrowser
__doc__ = __doc__.format(coil.__version__)
def main():
"""The main function."""
arguments = docopt.docopt(__doc__, version='Coil CMS v{0}'.format(
coil.__version__))
if arguments['write_users']:
sys.exit(write_users(arguments))
elif arguments['devserver']:
sys.exit(devserver(arguments))
elif arguments['unlock']:
sys.exit(unlock(arguments))
def init(arguments):
"""Run coil init."""
import coil.init
return coil.init.init()
def write_users(arguments):
"""Write users to the DB."""
import coil.init
u = coil.utils.ask("Redis URL", "redis://localhost:6379/0")
return coil.init.write_users(u)
def devserver(arguments):
"""Run a development server."""
import coil.web
if coil.web.app:
port = int(arguments['--port'])
url = 'http://localhost:{0}/'.format(port)
coil.web.configure_url(url)
coil.web.app.config['DEBUG'] = True
if arguments['--browser']:
webbrowser.open(url)
coil.web.app.logger.info("Coil CMS running @ {0}".format(url))
coil.web.app.run('localhost', port, debug=True)
return 0
else:
print("FATAL: no conf.py found")
return 255
def unlock(arguments):
"""Unlock the database."""
import redis
u = coil.utils.ask("Redis URL", "redis://localhost:6379/0")
db = redis.StrictRedis.from_url(u)
db.set('site:lock', 0)
print("Database unlocked.")
return 0
if __name__ == '__main__':
main()