Ejemplo n.º 1
0
  def listTargets(scripts):
    defaultTargets = []
    namedTargets = {}
    for script in scripts:
      defaultTargets.extend(flatten(script.getDefaultTarget().targets))
      for name, target in script._targets.items():
        namedTargets.setdefault(name, []).extend(flatten(target.targets))

    def targetList(targets):
      targets = sorted(set(str(t) for t in targets))
      if targets:
        return "".join("   -> " + t + "\n" for t in targets)
      else:
        return "   <no targets defined>\n"

    path = scripts[0].path

    message = "Targets for " + path + "\n"
    message += "  <default>\n"
    message += targetList(defaultTargets)
    for name in sorted(namedTargets.keys()):
      message += "  @" + name + "\n"
      message += targetList(namedTargets[name])

    logger.outputInfo(message)
Ejemplo n.º 2
0
    def listTargets(scripts):
        defaultTargets = []
        namedTargets = {}
        for script in scripts:
            defaultTargets.extend(flatten(script.getDefaultTarget().targets))
            for name, target in script._targets.items():
                namedTargets.setdefault(name,
                                        []).extend(flatten(target.targets))

        def targetList(targets):
            targets = sorted(set(str(t) for t in targets))
            if targets:
                return "".join("   -> " + t + "\n" for t in targets)
            else:
                return "   <no targets defined>\n"

        path = scripts[0].path

        message = "Targets for " + path + "\n"
        message += "  <default>\n"
        message += targetList(defaultTargets)
        for name in sorted(namedTargets.keys()):
            message += "  @" + name + "\n"
            message += targetList(namedTargets[name])

        logger.outputInfo(message)
Ejemplo n.º 3
0
    def testFlattenWithAsync(self):
        def makeAsync(value):
            task = Task(lambda: value)
            task.start()
            return DeferredResult(task)

        value = makeAsync([
            makeAsync([1, 2]), [3, makeAsync([4, 5]),
                                makeAsync(6)],
            makeAsync(7)
        ])

        result = flatten(value)

        self.assertTrue(isinstance(result, AsyncResult))

        e = threading.Event()

        result.task.addCallback(e.set)

        e.wait(0.5)

        self.assertTrue(result.task.succeeded)

        self.assertEqual(result.result, [1, 2, 3, 4, 5, 6, 7])
Ejemplo n.º 4
0
  def testFlattenWithAsync(self):

    def makeAsync(value):
      task = Task(lambda: value)
      task.start()
      return DeferredResult(task)

    value = makeAsync([
      makeAsync([1, 2]),
      [3, makeAsync([4, 5]), makeAsync(6)],
      makeAsync(7)
      ])

    result = flatten(value)

    self.assertTrue(isinstance(result, AsyncResult))

    e = threading.Event()

    result.task.addCallback(e.set)

    e.wait(0.5)

    self.assertTrue(result.task.succeeded)

    self.assertEqual(result.result, [1, 2, 3, 4, 5, 6, 7])
Ejemplo n.º 5
0
    def copyFiles(self, sources, targetDir):
        """Copy a collection of files to a target directory.
    
    @param sources: A list of files to copy.
    @type sources: list of string's, FileTargets or AsyncResult yielding
    a string, FileTarget or list of same.
    @param targetDir: The target directory to copy to.
    @type targetDir: string
    
    @return: A list of FileTarget's representing the files that will be
    copied.
    @rtype: list of L{FileTarget}
    """
        if not isinstance(targetDir, basestring):
            raise TypeError("targetDir must be a string")

        basePath = self.configuration.basePath

        sources = basePath(sources)
        targetDir = basePath(targetDir)

        @waitForAsyncResult
        def run(sources):
            results = []
            for s in sources:
                sourcePath = getPath(s)
                target = cake.path.join(targetDir,
                                        cake.path.baseName(sourcePath))
                results.append(self._copyFile(source=s, target=target))
            return results

        return run(flatten(sources))
Ejemplo n.º 6
0
 def copyFiles(self, sources, targetDir):
   """Copy a collection of files to a target directory.
   
   @param sources: A list of files to copy.
   @type sources: list of string's, FileTargets or AsyncResult yielding
   a string, FileTarget or list of same.
   @param targetDir: The target directory to copy to.
   @type targetDir: string
   
   @return: A list of FileTarget's representing the files that will be
   copied.
   @rtype: list of L{FileTarget}
   """
   if not isinstance(targetDir, basestring):
     raise TypeError("targetDir must be a string")
   
   basePath = self.configuration.basePath
   
   sources = basePath(sources)
   targetDir = basePath(targetDir)
   
   @waitForAsyncResult
   def run(sources):
     results = []
     for s in sources:
       sourcePath = getPath(s)
       target = cake.path.join(targetDir, cake.path.baseName(sourcePath))
       results.append(self._copyFile(source=s, target=target))
     return results
   
   return run(flatten(sources))
Ejemplo n.º 7
0
  def addTargets(self, targets):
    targets = flatten(targets)
    for target in targets:
      if not isinstance(target, Target):
        raise TypeError("Must specify Target object for addTargets")

    self.targets.extend(targets)
    self.task.completeAfter(t.task for t in targets)
Ejemplo n.º 8
0
    def addTargets(self, targets):
        targets = flatten(targets)
        for target in targets:
            if not isinstance(target, Target):
                raise TypeError("Must specify Target object for addTargets")

        self.targets.extend(targets)
        self.task.completeAfter(t.task for t in targets)
Ejemplo n.º 9
0
        def _start(program, results, dependencies):
            if self.alwaysRun is False:
                return

            task = self.engine.createTask(lambda: self._launchTest(
                program, results, cwd, flatten(dependencies)))
            task.parent.completeAfter(task)
            task.startAfter(getTask([program, dependencies]))
Ejemplo n.º 10
0
 def testFlattenNoAsync(self):
     self.assertEqual(flatten([]), [])
     self.assertEqual(flatten([1, 2, 3]), [1, 2, 3])
     self.assertEqual(flatten([1, [2, 3], 4]), [1, 2, 3, 4])
     self.assertEqual(flatten([[1, 2], [3, [4, 5], 6], 7]),
                      [1, 2, 3, 4, 5, 6, 7])
Ejemplo n.º 11
0
 def testFlattenNoAsync(self):
   self.assertEqual(flatten([]), [])
   self.assertEqual(flatten([1, 2, 3]), [1, 2, 3])
   self.assertEqual(flatten([1, [2, 3], 4]), [1, 2, 3, 4])
   self.assertEqual(flatten([[1, 2], [3, [4, 5], 6], 7]), [1, 2, 3, 4, 5, 6, 7])
Ejemplo n.º 12
0
                task = engine.createTask(
                    lambda t=targets, s=sources, c=cwd: spawnProcess(t, s, c))
                task.lazyStartAfter(getTasks(sources))
            else:
                task = None

            if targets:
                targets = [FileTarget(path=t, task=task) for t in targets]
                Script.getCurrent().getDefaultTarget().addTargets(targets)
                return targets
            else:
                target = Target(task)
                Script.getCurrent().getDefaultTarget().addTarget(target)
                return target

        return _run(flatten(targets), flatten(sources), cwd)

    def __iter__(self):
        return iter(self._env)

    def keys(self):
        return self._env.keys()

    def items(self):
        return self._env.items()

    def update(self, value):
        return self._env.update(value)

    def get(self, key, default=_undefined):
        if default is _undefined:
Ejemplo n.º 13
0
      if self.enabled:
        task = engine.createTask(lambda t=targets, s=sources, c=cwd: spawnProcess(t, s, c))
        task.lazyStartAfter(getTasks(sources))
      else:
        task = None
  
      if targets:
        targets = [FileTarget(path=t, task=task) for t in targets]
        Script.getCurrent().getDefaultTarget().addTargets(targets)
        return targets
      else:
        target = Target(task)
        Script.getCurrent().getDefaultTarget().addTarget(target)
        return target
    
    return _run(flatten(targets), flatten(sources), cwd)

  def __iter__(self):
    return iter(self._env)

  def keys(self):
    return self._env.keys()

  def items(self):
    return self._env.items()

  def update(self, value):
    return self._env.update(value)

  def get(self, key, default=_undefined):
    if default is _undefined: