Changeset 802

Show
Ignore:
Timestamp:
09/22/07 16:24:49 (1 year ago)
Author:
robin
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyrun/trunk/bakescripts.py

    r801 r802  
    11#!/usr/bin/env python 
    2 """usage: %prog [OPTIONS] 
    3  
     2"""usage: %prog [-qNb] paths [-s scripts] [-R requirements] [-P projects] 
     3 
     4Generate python program launcher scripts which initialise sys.path with script 
     5relative paths to their dependencies. If you move the dependencies and the 
     6scripts to a new location then the scripts do not need to be regenerated. 
     7 
     8Uses facilities from pyrun to discover the dependency paths. 
    49""" 
    510 
     
    4146            installed.''')) 
    4247        sys.exit(-1) 
    43  
    44  
    4548 
    4649isdir = os.path.isdir 
     
    189192                        sname, dist.location) 
    190193                continue 
     194            arguments = '' 
    191195            if sname is None: # dict.fromkeys does this to us 
    192196                sname = name 
    193197            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] 
    195202            if sname in entrypoints: 
    196203                log.warning( 
     
    200207                sname, entrypoints[sname].dist.location, dist.location) 
    201208 
    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) 
    204212 
    205213 
    206214    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)) 
    211218 
    212219    return locations, script_parameters 
     
    228235 
    229236 
    230     arguments = variables['arguments'] 
     237    default_arguments = variables['arguments'] or '' 
     238 
     239    if not isinstance(scripts, dict): 
     240        scripts = dict.fromkeys(list(scripts)) 
    231241 
    232242    locations, parameters = resolve_egg_scripts( 
    233             path, reqs, projects, dict.fromkeys(scripts)
     243            path, reqs, projects, scripts
    234244 
    235245    generated = [] 
    236     for sname, name, module_name, attrs in parameters: 
     246    for sname, name, module_name, attrs, arguments in parameters: 
    237247        # If we are simply given a path, generate *ALL* scripts, 
    238248        # 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: 
    240253            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) 
    256261 
    257262        sname = join(bindir, sname) 
     
    468473 
    469474 
    470     #flag_opts = set([o.dest for o in parser.option_list 
    471     #    if o.action in ('store_true', 'store_false')]) 
    472  
    473475    if argv is None: 
    474476        argv=sys.argv[:] 
     
    501503 
    502504    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) 
    503515        curoplist = legal_postpath_opts[argv[ia]] 
    504516        ia += 1 
     
    507519                curoplist = legal_postpath_opts[argv[ia]] 
    508520            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]) 
    514522                sys.exit(-1) 
    515523            else: