示例#1
0
def step(self, name, rule, **kwds):
    '''
    Make a worch installation step.  

    This invokes the build context on the rule with the following augmentations:

    - the given step name is prefixed with the package name
    - if the rule is a string (scriptlet) then the worch exec_command is used
    - successful execution of the rule leads to a worch control file being produced.
    '''
    step_name = '%s_%s' % (self.worch.package, name)

    # append control file as an additional output
    target = string2list(kwds.get('target', ''))
    if not isinstance(target, list):
        target = [target]
    cn = self.control_node(name)
    if not cn in target:
        target.append(cn)
    kwds['target'] = target
    
    kwds.setdefault('env', self.env)

    cwd = kwds.get('cwd')
    if not cwd:
        cwd = default_step_cwd.get(name)
    if cwd:
        cwd = self.worch.format(cwd)
        cwd = self.make_node(cwd)
        msg.debug('orch: using cwd for step "%s": %s' % (step_name, cwd.abspath()))
        kwds['cwd'] = cwd.abspath()


    depends = self.worch.depends_step(name)
    after = string2list(kwds.get('after',[])) + depends
    if after:
        kwds['after'] = after
        msg.debug('orch: run %s AFTER: %s' % (step_name, after))

    # functionalize scriptlet
    rulefun = rule
    if isinstance(rule, type('')):
        rulefun = lambda t: exec_command(t, rule)

    # curry the real rule function in order to write control file if successful
    def runit(t):
        rc = rulefun(t)
        if not rc:
            msg.debug('orch: successfully ran %s' % step_name)
            cn.write(time.asctime(time.localtime()) + '\n')
        return rc

    # msg.debug('orch: step "%s" with %s in %s\nsource=%s\ntarget=%s' % \
    #           (step_name, rulefun, cwd, kwds.get('source'), kwds.get('target')))

    # have to switch group each time as steps are called already asynchronously
    self.bld.set_group(self.worch.group)
    return self.bld(name=step_name, rule = runit, **kwds)
示例#2
0
 def depends_step(self, step):
     '''
     Return a list of steps that this step depends on
     '''
     d = self._config.get('depends')
     if not d: return list()
     ds = [x[1] for x in [s.split(':') for s in string2list(d)] if x[0] == step]
     return ds
示例#3
0
文件: tools.py 项目: brettviren/worch
def assert_features(pkgcfg):
    features = string2list(pkgcfg["features"])
    for feat in features:
        assert feat in available_features.keys(), 'Unknown feature "%s" for package "%s" (out of %s)' % (
            feat,
            pkgcfg["package"],
            ", ".join(available_features),
        )
示例#4
0
文件: tools.py 项目: brettviren/worch
 def depends_step(self, step):
     """
     Return a list of steps that this step depends on
     """
     d = self._config.get("depends")
     if not d:
         return list()
     ds = [x[1] for x in [s.split(":") for s in string2list(d)] if x[0] == step]
     return ds
示例#5
0
def test_load_config_file():
    'Test reading in some real config files'
    t1 = time.time()
    top = deconf.load(config_file, **fake_worch_data)
    t2 = time.time()
    print 'Created in %.3f' % (t2-t1)

    def dump_node(n):
        print n
        for k,v in n.local_items():
            print '%s = %s' % (k,v)
        print

    ngroups = 0
    npackages = 0
    for gname in string2list(top['groups']):
        g = top.owner().node(gname)
        for gk,gv in g.items():
            ngroups += 1

        for pname in string2list(g['packages']):
            p = top.owner().node(pname)
            for pk,pv in p.items():
                npackages += 1

    t3 = time.time()
    print 'Iterated in %.3f (#g=%d, #p=%d)' % (t3-t2, ngroups, npackages)

    ngroups = 0
    npackages = 0
    for gname in string2list(top['groups']):
        g = top.owner().node(gname)
        for gk,gv in g.items():
            ngroups += 1

        for pname in string2list(g['packages']):
            p = top.owner().node(pname)
            for pk,pv in p.items():
                npackages += 1

    t4 = time.time()
    print 'Iterated again in %.3f (#g=%d, #p=%d)' % (t4-t3, ngroups, npackages)
示例#6
0
def test_iterate():
    'Test iterating down the nodes'

    t1 = time.time()
    Node = deconf.NodeGroup(keytype = dict(groups='group', packages='package'))
    top = Node('start', version='0', label='{group}-{package}-{version}')
    groups, packages = create_packages(top, 10, 10)
    t2 = time.time()
    print 'Created in %.3f' % (t2-t1)
    
    got_groups = list()
    got_packages = list()
    for gname in string2list(top['groups']):
        #assert g in groups
        got_groups.append(gname)
        g = top.owner().node(gname)
        for p in string2list(g['packages']):
            #assert p in packages
            got_packages.append(p)
    t3 = time.time()
    print 'Iterated in %.3f' % (t3-t2)

    assert len(groups) == len(got_groups)
    assert len(packages) == len(got_packages)
示例#7
0
def worch_package(ctx, worch_config, *args, **kw):

    # transfer waf-specific keywords explicitly
    kw['name'] = worch_config['package']
    kw['features'] = ' '.join(string2list(worch_config['features']))
    kw['use'] = worch_config.get('use')

    # make the TaskGen object for the package
    worch=WorchConfig(**worch_config)
    tgen = ctx(*args, worch=worch, **kw)
    tgen.env = ctx.all_envs[worch.package]
    tgen.env.env = tgen.env.munged_env
    msg.debug('orch: package "%s" with features: %s' % \
              (kw['name'], ', '.join(kw['features'].split())))
    return tgen
示例#8
0
 def dependencies(self):
     '''
     Return all dependencies set via "depends" configuration items 
     return list of tuples: (mystep, package, package_step)
     eg: ('prepare', 'gcc', 'install')
     '''
     ret = list()
     try:
         deps = getattr(self, 'depends', None)
     except KeyError:
         return list()
     for dep in string2list(deps):
         mystep, other = dep.split(':')
         pkg,pkg_step = other.split('_',1)
         ret.append((mystep, pkg, pkg_step))
     return ret
示例#9
0
文件: tools.py 项目: brettviren/worch
def worch_package(ctx, pkgname, *args, **kw):

    wenv = ctx.all_envs[pkgname]
    pkgcfg = wenv.orch_package
    assert_features(pkgcfg)

    # transfer waf-specific keywords explicitly
    kw["name"] = pkgcfg["package"]
    kw["use"] = pkgcfg.get("use")
    kw["features"] = " ".join(string2list(pkgcfg["features"]))

    # make the TaskGen object for the package
    worch = WorchConfig(**pkgcfg)
    tgen = ctx(*args, worch=worch, **kw)
    tgen.env = wenv
    tgen.env.env = tgen.env.munged_env
    msg.debug('orch: package "%s" with features: %s' % (kw["name"], ", ".join(kw["features"].split())))
    return tgen
示例#10
0
文件: tools.py 项目: brettviren/worch
 def dependencies(self):
     """
     Return all dependencies set via "depends" configuration items 
     return list of tuples: (mystep, package, package_step)
     eg: ('prepare', 'gcc', 'install')
     """
     ret = list()
     try:
         deps = getattr(self, "depends", None)
     except KeyError:
         return list()
     for dep in string2list(deps):
         mystep, other = dep.split(":")
         try:
             pkg, pkg_step = other.split("_", 1)
         except ValueError:
             print '%s: step="%s", dep="%s"' % (self.package, mystep, other)
             raise
         ret.append((mystep, pkg, pkg_step))
     return ret