Changeset 802
- Timestamp:
- 09/22/07 16:24:49 (1 year ago)
- Files:
-
- pyrun/trunk/bakescripts.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyrun/trunk/bakescripts.py
r801 r802 1 1 #!/usr/bin/env python 2 """usage: %prog [OPTIONS] 3 2 """usage: %prog [-qNb] paths [-s scripts] [-R requirements] [-P projects] 3 4 Generate python program launcher scripts which initialise sys.path with script 5 relative paths to their dependencies. If you move the dependencies and the 6 scripts to a new location then the scripts do not need to be regenerated. 7 8 Uses facilities from pyrun to discover the dependency paths. 4 9 """ 5 10 … … 41 46 installed.''')) 42 47 sys.exit(-1) 43 44 45 48 46 49 isdir = os.path.isdir … … 189 192 sname, dist.location) 190 193 continue 194 arguments = '' 191 195 if sname is None: # dict.fromkeys does this to us 192 196 sname = name 193 197 if not isinstance(sname, types.StringTypes): 194 sname = sname[0] 198 if len(sname): 199 sname = sname[0] 200 if len(sname) > 2: 201 arguments = sname[1] 195 202 if sname in entrypoints: 196 203 log.warning( … … 200 207 sname, entrypoints[sname].dist.location, dist.location) 201 208 202 entrypoints[sname] = (name, ep) 203 locations.append(dist.location) 209 entrypoints[sname] = (name, ep, arguments) 210 if dist.location not in locations: 211 locations.append(dist.location) 204 212 205 213 206 214 script_parameters = [] 207 for sname, (name, ep) in entrypoints.iteritems(): 208 script_parameters.append(( 209 sname, name, ep.module_name, 210 '.'.join(ep.attrs))) 215 for sname, (name, ep, arguments) in entrypoints.iteritems(): 216 script_parameters.append((sname, name, ep.module_name, 217 '.'.join(ep.attrs), arguments)) 211 218 212 219 return locations, script_parameters … … 228 235 229 236 230 arguments = variables['arguments'] 237 default_arguments = variables['arguments'] or '' 238 239 if not isinstance(scripts, dict): 240 scripts = dict.fromkeys(list(scripts)) 231 241 232 242 locations, parameters = resolve_egg_scripts( 233 path, reqs, projects, dict.fromkeys(scripts))243 path, reqs, projects, scripts) 234 244 235 245 generated = [] 236 for sname, name, module_name, attrs in parameters:246 for sname, name, module_name, attrs, arguments in parameters: 237 247 # If we are simply given a path, generate *ALL* scripts, 238 248 # Otherwise only generate those which are explicitly requested. 239 if name not in scripts and (reqs or projects or scripts): 249 250 # If an explicit set of scripts is specified only generate those 251 # that are in the set. 252 if scripts and name not in scripts: 240 253 continue 241 # if scripts is a flat list it is simply saying 242 # "these are the scripts I want". If its a dict of some kind, 243 # it has the oportunitity to tweak the generation in various ways. 244 try: 245 s = scripts.get(name) 246 if s is False: 247 continue 248 except AttributeError: 249 s = name 250 251 if not isinstance(s, types.StringTypes): 252 invoke_program = '%s.%s(%s)' % (module_name, attrs, s[1]) 253 else: 254 invoke_program = '%s.%s(%s)' % (module_name, attrs, 255 arguments or '') 254 # if the original scripts argument was a flat list it is simply saying 255 # "these are the scripts I want". If was a dict of some kind, 256 # resolve_egg_scripts has incorporated any supported specializations 257 # in its production of parameters. 258 259 invoke_program = '%s.%s(%s)' % (module_name, attrs, arguments or 260 default_arguments) 256 261 257 262 sname = join(bindir, sname) … … 468 473 469 474 470 #flag_opts = set([o.dest for o in parser.option_list471 # if o.action in ('store_true', 'store_false')])472 473 475 if argv is None: 474 476 argv=sys.argv[:] … … 501 503 502 504 if ia < len(argv): 505 def opt_ileagal_after_discoverypath(opt): 506 log.error(dedent('''\ 507 "%s" is ileagal after the discovery path. [%s] are the only 508 options which may follow the discovery path.''' % (opt, 509 '|'.join(legal_postpath_opts.keys()))) 510 ) 511 512 if argv[ia] not in legal_postpath_opts: 513 opt_ileagal_after_discoverypath(argv[ia]) 514 sys.exit(-1) 503 515 curoplist = legal_postpath_opts[argv[ia]] 504 516 ia += 1 … … 507 519 curoplist = legal_postpath_opts[argv[ia]] 508 520 elif argv[ia].startswith('-'): 509 log.error(dedent('''\ 510 "%s" is ileagal after the discovery path. [%s] are the only 511 options which may follow the discovery path.''' % ( argv[ia], 512 '|'.join(legal_postpath_opts.keys()))) 513 ) 521 opt_ileagal_after_discoverypath(argv[ia]) 514 522 sys.exit(-1) 515 523 else: