This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·173 lines (130 loc) · 4.78 KB
/
configure
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /usr/bin/env python
""" Configure script for the health care portal software.
This writes buildout.cfg, bootstraps a django install, and then
runs buildout again, with a generated buildout.cfg for the project.
To create a new project::
./configure -p <name of project> -a <name of app>
Once this is created running::
./configure
Will regenerate the config should it be required.
A isotoma/<projectname>.cfg will be generated to hold the buildout options
specific to the project created.
"""
import os, sys
import subprocess
from optparse import OptionParser
app_template = """
[buildout]
develop = src
eggs += %(projectname)s
[django]
settings = settings
projectegg = %(projectname)s
eggs = ${buildout:eggs}
test = %(appname)s
project = %(projectname)s
"""
setup_template = """
from setuptools import setup
setup(
name = '%(projectname)s',
version = '0.0.1',
packages = [],
zip_safe = False,
include_package_data = True,
)
"""
def get_version(path):
try :
p = subprocess.Popen([sys.executable, "setup.py", "-V"], stdout=subprocess.PIPE, cwd=path)
o, e = p.communicate()
return o.strip()
except:
return "bootstrap"
parser = OptionParser()
parser.add_option("-e", "--environment", dest="environment",
help="What kind of deployment", default="dev")
parser.add_option("-p", "--new-project", dest="project",
help="Create a new project with the given name", default=None)
parser.add_option("-a", "--new-app", dest="app",
help="Create a new app with the given name", default=None)
options, args = parser.parse_args()
new_project = False
if options.project and options.app:
if os.path.exists(os.path.join(os.getcwd(), 'src')):
print "src directory exists, not configuring project"
sys.exit()
print "Configuring new project"
template = "[buildout]\n" \
"extends =\n" \
" isotoma/base.cfg\n" \
"cwd = %(cwd)s\n" \
open("buildout.cfg", "w").write(template % {
"environment":options.environment,
"cwd": os.getcwd(),
})
# print "Running minimal bootstrap"
# subprocess.Popen([sys.executable, "bootstrap.py"]).wait()
# print "Running minimal buildout"
# subprocess.Popen("bin/buildout").wait()
#
# print "Creating project"
# os.makedirs('src')
# srcdir = os.path.join(os.getcwd(), "src")
# isotomadir = os.path.join(os.getcwd(), "isotoma")
# subprocess.Popen(["../bin/django-admin","startproject", "%s" % options.project], cwd=srcdir).wait()
# print "Creating config files"
# setup_file = open(os.path.join(srcdir, "setup.py"), 'w')
# setup_file.write(setup_template % {'projectname': options.project})
# setup_file.close()
#
# buildout_file = open(os.path.join(isotomadir, "%s.cfg" % options.project), 'w')
# buildout_file.write(app_template % {'projectname': options.project, 'appname': options.app})
# buildout_file.close()
#
# new_project = True
# save the project name so we can use it if configure is run
# without creating a project
# needed for successfully creating the buildout config below
# print "Saving project name"
# project_file = open(os.path.join(srcdir, 'project.name'), 'w')
# project_file.write(options.project)
# project_file.close()
# project_name = options.project
if options.project and not options.app:
print "Please provide an app name"
sys.exit()
if not options.project and options.app:
print "Please provide a project name"
sys.exit()
if options.environment != "dev":
template = "[buildout]\n" \
"extends =\n" \
" isotoma/base.cfg\n" \
" isotoma/project.cfg\n" \
" isotoma/fullstack.cfg\n" \
" isotoma/environment/%(environment)s/environment.cfg\n" \
"cwd = %(cwd)s\n" \
else:
template = "[buildout]\n" \
"extends =\n" \
" isotoma/base.cfg\n" \
" isotoma/project.cfg\n" \
"cwd = %(cwd)s\n" \
# if we're creating a new project, we have the project name
# if not, we need to read it out of the file that we created
#if not new_project:
# project_name = open(os.path.join(os.path.join(os.getcwd(), 'src'), 'project.name')).read().strip()
version = get_version("src")
print "Configuring to install version", version
open("buildout.cfg", "w").write(template % {
"environment":options.environment,
"cwd": os.getcwd(),
"version": version,
})
#if new_project:
# print "Creating application"
# subprocess.Popen("bin/buildout").wait()
# subprocess.Popen(["../../bin/django", "startapp", "%s" % options.app], cwd=os.path.join(os.path.join(os.getcwd(), "src"), options.project)).wait()
#
# print "Project created"