Completed
Push — master ( bc8c97...72fe21 )
by Batiste
01:20
created

print_green()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 2
rs 10
cc 1
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
        call(['./manage.py'.format(args.create), 'createsuperuser'], cwd=absolute)
33
        call(['./manage.py'.format(args.create), 'pages_demo'], cwd=absolute)
34
        print_green('Migration done successfully, running webserver...')
35
        call(['./manage.py'.format(args.create), 'runserver'], cwd=absolute)
36
    else:
37
        parser.print_help()
38
39
40
if __name__ == "__main__":
41
    main()