Projet

Général

Profil

Télécharger (1,93 ko) Statistiques
| Branche: | Tag: | Révision:

root / scripts / mandaye-admin.py @ 9003c07e

1
#! /usr/bin/python
2
# -*- coding: utf-8 -*-
3

    
4
""" Script to create mandaye projects
5
"""
6

    
7
import os
8
import re
9
import shutil
10
import sys
11

    
12
from optparse import OptionParser
13

    
14
from mandaye import config
15
from mandaye.log import logger
16

    
17
def get_cmd_options():
18
    usage = "usage: %prog --newproject"
19
    parser = OptionParser(usage=usage)
20
    parser.add_option("-n", "--newproject",
21
            dest="project_name",
22
            metavar="PROJECT_NAME",
23
            help="PROJECT_NAME: the name of teh new mandaye's project"
24
            )
25
    (options, args) = parser.parse_args()
26
    if not options.project_name:
27
        parser.error("You must set --newproject option")
28
    if options.project_name:
29
        if not re.search(r'^[_a-zA-Z]\w*$', options.project_name):
30
            parser.error("project_name %s is not a valid name."
31
                    "Please use use only numbers, letters and underscores.")
32
    return options
33

    
34
def main():
35
    options = get_cmd_options()
36
    if options.project_name:
37
        project_name = options.project_name
38
        module = os.path.join(project_name,
39
                project_name)
40
        modue_example = os.path.join(project_name,
41
                "example.module")
42
        skel = config.skel_root
43
        logger.info("Creating project %s ..." % project_name)
44
        if os.path.exists(project_name):
45
            print "%s folder already exist" % project_name
46
            sys.exit(1)
47
        shutil.copytree(skel, project_name)
48
        for root, dirs, files in os.walk(project_name):
49
            if not "templates" in root and not "static" in root:
50
                for filename in files:
51
                    file_path = os.path.join(root, filename)
52
                    with open(file_path, "r") as f:
53
                        content = f.read()
54
                    with open(file_path, "w") as f:
55
                        f.write(content.format(project_name=project_name))
56
        shutil.move(modue_example, module)
57

    
58
if __name__ == "__main__":
59
    main()
60

    
    (1-1/1)