comparison carton.py @ 35:122c56779f2b

add functionality to run post-install python scripts
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 08 Aug 2011 18:08:49 -0700
parents 8fef97a25925
children 77285bafc36a
comparison
equal deleted inserted replaced
34:261e2d2d26ad 35:122c56779f2b
68 68
69 # packed files 69 # packed files
70 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib') 70 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib')
71 PACKAGE_SOURCES=%(PACKAGE_SOURCES)s 71 PACKAGE_SOURCES=%(PACKAGE_SOURCES)s
72 CARTON=%(CARTON)s 72 CARTON=%(CARTON)s
73
74 # post-install scripts
75 PYTHON_SCRIPTS=%(PYTHON_SCRIPTS)s
73 76
74 # parse options 77 # parse options
75 usage = os.path.basename(sys.argv[0]) + ' [options]' 78 usage = os.path.basename(sys.argv[0]) + ' [options]'
76 parser = OptionParser(usage=usage, description=__doc__) 79 parser = OptionParser(usage=usage, description=__doc__)
77 parser.add_option('--env', dest='env', help="environment name [DEFAULT: " + ENV + "]") 80 parser.add_option('--env', dest='env', help="environment name [DEFAULT: " + ENV + "]")
156 # you probably don't have os.chmod 159 # you probably don't have os.chmod
157 pass 160 pass
158 161
159 # cleanup virtualenv tempdir 162 # cleanup virtualenv tempdir
160 shutil.rmtree(tempdir) 163 shutil.rmtree(tempdir)
164
165 # run post-install scripts
166 for script in PYTHON_SCRIPTS:
167 if not os.path.isabs(script):
168 script = os.path.join(os.path.abspath(ENV), script)
169 call([python, script])
161 """ 170 """
162 171
163 def isURL(path): 172 def isURL(path):
164 return path.startswith('http://') or path.startswith('https://') 173 return path.startswith('http://') or path.startswith('https://')
165 174
176 parser.add_option('-o', dest='outfile', 185 parser.add_option('-o', dest='outfile',
177 help="specify outfile; otherwise it will come from environment_name") 186 help="specify outfile; otherwise it will come from environment_name")
178 parser.add_option('-p', '--package', dest='package', 187 parser.add_option('-p', '--package', dest='package',
179 action='store_true', default=False, 188 action='store_true', default=False,
180 help="create python packages from sources; do not take entire subdirectory") 189 help="create python packages from sources; do not take entire subdirectory")
190 parser.add_option('--python-script', dest='python_scripts', default=[],
191 action='append',
192 help="post-uncartoning python scripts to run in the virtualenv; these should be relative to $VIRTUAL_ENV")
181 parser.add_option('--virtualenv', dest='virtualenv', 193 parser.add_option('--virtualenv', dest='virtualenv',
182 help="use this virtualenv URL or file tarball") 194 help="use this virtualenv URL or file tarball")
183 options, args = parser.parse_args(args) 195 options, args = parser.parse_args(args)
184 if len(args) < 2: 196 if len(args) < 2:
185 parser.print_usage() 197 parser.print_usage()
267 if outfile is None: 279 if outfile is None:
268 outfile = environment + '.py' 280 outfile = environment + '.py'
269 variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'), 281 variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'),
270 'ENV': environment, 282 'ENV': environment,
271 'CARTON': repr(carton), 283 'CARTON': repr(carton),
284 'PYTHON_SCRIPTS': repr(options.python_scripts),
272 'PACKAGE_SOURCES': repr(source_array)} 285 'PACKAGE_SOURCES': repr(source_array)}
273 f = file(outfile, 'w') 286 f = file(outfile, 'w')
274 f.write(template % variables) 287 f.write(template % variables)
275 f.close() 288 f.close()
276 try: 289 try: