Completed
Push — master ( 5dabf5...3b22a3 )
by Batiste
01:36
created

main()   B

Complexity

Conditions 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 23
rs 8.7972
cc 4
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()