-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpancreate.py
executable file
·113 lines (89 loc) · 3.62 KB
/
pancreate.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
112
113
#!/usr/bin/env python
from __future__ import with_statement
import sys, os
from fabric.api import local
from fabric.contrib.files import sed
from fabric.context_managers import cd
import yaml
from pandeploy.component import ComponentLoader
from pandeploy.project import Project
from pandeploy import no_warning
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-n", "--project-name",
action="store", dest="project_name",
help="(required) the name of the project to create")
parser.add_option("-d", "--domain",
action="store", dest="domain",
help="the name of the domain the site will be served on, by default")
parser.add_option("-a", "--appname",
action="store", dest="appname",
help="the name of the application to create")
parser.add_option("-e", "--extends",
action="store", dest="extends",
help="the name of a project whose project.yaml will be extended")
options, args = parser.parse_args()
root_wsgi = """
import os, sys
sys.path.append("/domains/%(domain)s/libs/")
os.environ['DJANGO_SETTINGS_MODULE'] = '%(project_name)s.settings'
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()
"""
def main(argv):
project_name = options.project_name
if not project_name:
sys.argv = ['pancreate.py', '--help']
parser.parse_args()
return 1
domain = options.domain
appname = options.appname
project = Project()
project.name = project_name
project.domain = domain
project.appname = appname
project.path = os.path.abspath(os.path.join('.', project_name))
def mkdir(dir, L):
local(("mkdir -p %(project_name)s/" % L) + dir)
if appname:
local("cd apps && django-admin.py startapp %s" % (appname,))
else:
mkdir("libs", locals())
mkdir("media", locals())
mkdir("apps", locals())
local("cd %(project_name)s && django-admin.py startproject %(project_name)s" % locals())
local("echo from pandeploy import \\* > %(project_name)s/fabfile.py" % locals())
local("echo project_library: %(project_name)s >> %(project_name)s/project.yaml" % locals())
local("echo hosts: [\"%(domain)s\"] >> %(project_name)s/project.yaml" % locals())
cfg_file = open(os.path.join(project_name, "project.yaml"), 'w')
cfg = {
'domain': domain,
'version': "0.1",
'project_library': project_name,
'DEBUG': True,
}
if options.extends:
os.symlink(os.path.join('..', options.extends, 'project.yaml'), os.path.join(project_name, 'project_extends.yaml'))
yaml.dump(cfg, cfg_file)
cfg_file.close()
open(os.path.join(project_name, "root.wsgi"), 'w').write(root_wsgi % locals())
gitignore_template = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'pandeploy', 'skel', 'default_gitignore'))
with cd(project_name):
with no_warning:
local('python -m djangorender -p %(gitignore_template)s -s project_name=%(project_name)s > .gitignore' % locals())
local('git init')
local('git add .')
local("git commit -m 'initial commit'")
#CL = ComponentLoader()
#CL.load_all()
#project.components = CL
project.populate_new_project()
username = os.environ.get('USER')
with cd(project_name):
local("fab allow_deploy:%(username)s" % locals())
local("fab allow_alias:%(username)s" % locals())
print local("fab deploy")
local("fab alias_version:0.1")
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))