|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
import argparse |
|
3
|
|
|
import sys |
|
4
|
|
|
import os |
|
5
|
|
|
import shutil |
|
6
|
|
|
import stat |
|
7
|
|
|
from subprocess import call |
|
8
|
|
|
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
9
|
|
|
EXAMPLE_DIR = os.path.join(PROJECT_DIR, 'example') |
|
10
|
|
|
|
|
11
|
|
|
parser = argparse.ArgumentParser(description='Gerbi CMS console tool.') |
|
12
|
|
|
parser.add_argument('--create', type=str, |
|
13
|
|
|
help='Create a new CMS example website') |
|
14
|
|
|
|
|
15
|
|
|
def print_green(msg): |
|
16
|
|
|
print('\033[92m' + msg + '\033[0m') |
|
17
|
|
|
|
|
18
|
|
|
def main(): |
|
19
|
|
|
args = parser.parse_args() |
|
20
|
|
|
|
|
21
|
|
|
if args.create: |
|
22
|
|
|
absolute = os.path.join(os.getcwd(), args.create) |
|
23
|
|
|
print_green("Creating website {}".format(args.create)) |
|
24
|
|
|
print_green("Copying example files to {}".format(args.create)) |
|
25
|
|
|
ignore = shutil.ignore_patterns('*.db', '*.pyc', 'media', 'whoosh*') |
|
26
|
|
|
shutil.copytree(EXAMPLE_DIR, args.create, ignore=ignore) |
|
27
|
|
|
st = os.stat(os.path.join(args.create, 'manage.py')) |
|
28
|
|
|
os.chmod(os.path.join(args.create, 'manage.py'), st.st_mode | stat.S_IEXEC) |
|
29
|
|
|
ret = call(['./manage.py'.format(args.create), 'migrate'], cwd=absolute) |
|
30
|
|
|
if ret != 0: |
|
31
|
|
|
return |
|
32
|
|
|
print_green('Migration done') |
|
33
|
|
|
_input = raw_input("Would you like to create a superuser to connect to the admin? [N/y]") |
|
34
|
|
|
if _input.lower() == 'y': |
|
35
|
|
|
call(['./manage.py'.format(args.create), 'createsuperuser'], cwd=absolute) |
|
36
|
|
|
call(['./manage.py'.format(args.create), 'pages_demo'], cwd=absolute) |
|
37
|
|
|
call(['./manage.py'.format(args.create), 'rebuild_index', '--noinput'], cwd=absolute) |
|
38
|
|
|
call(['./manage.py'.format(args.create), 'runserver'], cwd=absolute) |
|
39
|
|
|
else: |
|
40
|
|
|
parser.print_help() |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
if __name__ == "__main__": |
|
44
|
|
|
main() |