-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrelease.py
executable file
·262 lines (187 loc) · 7.41 KB
/
release.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/python
"""
Ad hoc Python script for making a mobilize.js release.
.js and .css files are run through YUI Compressor.
Usage:
release.py [options] [version tag]
Create release to releases/trunk folder::
release.py trunk
Create release to /path/to/release/dir/trunk folder::
release.py -d /path/to/release/dir trunk
Use version tag trunk for running tests.
"""
import os
import shutil
import sys
import tempfile
# What our "whole package" includes
CORE_MOBILE_JS = ["jquery.js", "mobilize.onjq.js", "jquery.mobile.js", "jquery.easing.js", "jquery.mobile.scrollview.js", "mobitube.js"]
# Define different user usabble clouad service bundles
BUNDLES = [
{
"name" : "core",
"bootstrap_js" : ["mobilize.js", "mobilize.auto.js"],
"mobile_js" : CORE_MOBILE_JS,
"mobile_css" : ["jquery.mobile.css"],
"templates" : ["core.html"],
},
{
"name" : "wordpress",
"bootstrap_js" : ["mobilize.js", "mobilize.wordpress.js", "mobilize.auto.js"],
"mobile_js" : CORE_MOBILE_JS,
"mobile_css" : ["jquery.mobile.css", "jquery.mobile.scrollview.css", "wordpress.css"],
"templates" : ["wordpress.html"]
},
{
"name" : "sphinx",
"bootstrap_js" : ["mobilize.js", "mobilize.sphinx.js", "mobilize.auto.js"],
"mobile_js" : CORE_MOBILE_JS,
"mobile_css" : ["jquery.mobile.css", "jquery.mobile.scrollview.css", "sphinx.css"],
"templates" : ["sphinx.html"]
},
]
OPTIONS = None
VERSION = None
# releases folder on CDN
TARGET_PATH = None
# docs folder on CDN
DOCS_PATH = None
WORKDIR = os.getcwd()
def create_paths( ):
global TARGET_PATH
global DOCS_PATH
TARGET_PATH = os.path.join(OPTIONS.targetdir, VERSION)
TARGET_PATH = os.path.abspath(TARGET_PATH)
DOCS_PATH = os.path.join(OPTIONS.targetdir, "..", "docs", VERSION)
DOCS_PATH = os.path.abspath(DOCS_PATH)
if not os.path.exists(TARGET_PATH):
os.makedirs(TARGET_PATH)
for subpath in ["js", "css", "templates", "images"]:
os.makedirs(os.path.join(TARGET_PATH, subpath))
def add_extra_extension(filepath, extra_ext):
"""
Add .min or .debug to filename extension
"""
root, ext = os.path.splitext(filepath)
ext = ext[1:] # .js -> js
return ".".join([root, extra_ext, ext])
def process_vars(line):
"""
Update version etc. template line in the release data.
"""
# Reflect real version to file
if "$$VERSION_LINE" in line:
i = line.index('"') + 1
ie = line.index('"',i)
line = line[:i] + VERSION + line[ie:]
print "$$VERSION_LINE found. Updated version to '%s'" % VERSION
# Make sure release versions use error reporting
if "$$ERROR_REPORTING_LINE" in line:
line = '\t\terrorReportingURL : "http://cdn.mobilizejs.com/logerror/",'
print "$$ERROR_REPORTING_LINE updated"
return line
def create_bundle_core(target, sources, type):
global VERSION
print "Creating bundle:" + target
buffer = ""
for s in sources:
path = os.path.join(WORKDIR, type, s)
print "Including file:" + path
f = open(path)
buffer += f.read()
f.close()
# Update version
lines = buffer.split("\n")
lines = tuple([ process_vars(line) for line in lines ])
buffer = "\n".join(lines)
for mode in ["debug", "min"]:
output = os.path.join(TARGET_PATH, type, add_extra_extension(target, mode))
if not OPTIONS.no_compress and mode == "min" and type in ["js", "css"]:
# Implementes issue #16: Add YUI compressor to release.py
fh,path = tempfile.mkstemp(suffix = os.path.basename("."+type))
try:
f = open(path, 'wt')
f.write(buffer)
f.close()
yui = "java -jar tools/yuicompressor-2.4.2.jar -o %(TARGET)s %(SOURCE)s" % \
{"TARGET" : output, "SOURCE" : path}
print yui
os.system(yui)
finally:
os.remove(path)
else:
f = open(output, "wt")
f.write(buffer)
f.close()
def process_bundle(bundle):
""" """
# Create bootstrap
create_bundle_core("mobilize.%s.js" % bundle["name"], bundle["bootstrap_js"], "js")
create_bundle_core("mobilize.%s.mobile.js" % bundle["name"], bundle["mobile_js"], "js")
create_bundle_core("mobilize.%s.mobile.css" % bundle["name"], bundle["mobile_css"], "css")
# Local deploys can use templates as is
if not OPTIONS.localdeploy:
# Copy templates
for t in bundle["templates"]:
source = os.path.join(WORKDIR, "templates", t)
print "Copying template " + source
target = os.path.join(TARGET_PATH, "templates")
shutil.copy(source, target)
# Copy images
def prepare_images():
# Image files are shared
if OPTIONS.localdeploy:
print "Not processing images locally"
return
images_target = os.path.join(TARGET_PATH, "css", "images")
source = os.path.join(WORKDIR, "css", "images")
print "Copying images to:" + images_target + " from:" + source
if os.path.exists(os.path.join(images_target)):
shutil.rmtree(images_target)
shutil.copytree(source, images_target)
def copy_docs():
""" Copy documentation to CDN hosting under a specific version.
"""
if OPTIONS.localdeploy:
print "Not releasing docs locally"
return
if os.path.exists(os.path.join(DOCS_PATH)):
shutil.rmtree(DOCS_PATH)
print "Releasing docs to " + DOCS_PATH
source = os.path.join(WORKDIR, "docs")
shutil.copytree(os.path.join(source, "apidocs"), os.path.join(DOCS_PATH, "apidocs"))
shutil.copytree(os.path.join(source, "manual", "build", "html"), os.path.join(DOCS_PATH, "manual"))
def main():
global OPTIONS
global VERSION
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", "--dir", dest="targetdir",
help="Target directory to write the results. Default: %default",
default = os.path.join(WORKDIR, "releases"))
parser.add_option("-l", "--local-process", dest="localdeploy",
help="Compress and merge files CSS and JS files for local testing",
default = None)
parser.add_option("", "--no-compress",
help="Disable compression",
action="store_true",
default = False)
(OPTIONS, args) = parser.parse_args()
#if len(args) == 0:
# print "Usage release.py [options] [version tag]"
# print "See more help with -h"
# sys.exit(1)
if OPTIONS.localdeploy == "true":
OPTIONS.targetdir = "."
VERSION = ""
else:
VERSION = args[0]
print "mobilize.js release version %s" % VERSION
create_paths()
# Create bundles and copy bundle specific files
for b in BUNDLES:
process_bundle(b)
prepare_images()
copy_docs()
if __name__ == "__main__":
main()