Пример #1
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]))
Пример #2
0
        def run(source):
            if self.enabled:
                sourceTask = getTask(source)
                copyTask = self.engine.createTask(doCopy)
                copyTask.lazyStartAfter(sourceTask)
            else:
                copyTask = None

            fileTarget = FileTarget(path=target, task=copyTask)

            currentScript = Script.getCurrent()
            currentScript.getDefaultTarget().addTarget(fileTarget)

            return fileTarget
Пример #3
0
    def run(source):
      if self.enabled:  
        sourceTask = getTask(source)
        copyTask = self.engine.createTask(doCopy)
        copyTask.lazyStartAfter(sourceTask)
      else:
        copyTask = None

      fileTarget = FileTarget(path=target, task=copyTask)

      currentScript = Script.getCurrent()
      currentScript.getDefaultTarget().addTarget(fileTarget)

      return fileTarget
Пример #4
0
class ZipTool(Tool):
    def extract(
        self,
        targetDir,
        source,
        onlyNewer=True,
        removeStale=False,
        includeMatch=None,
    ):
        """Extract all files in a Zip to the specified path.
  
    @param targetDir: The directory to extract files to.
    @type targetDir: string
    
    @param source: Path to the zip file to extract files from.
    @type source: string
    
    @param onlyNewer: Only extract files that are newer than those in
    the target directory.
    @type onlyNewer: bool
    
    @param removeStale: Remove files and directories in the target
    directory that no longer exist in the zip.
    @type removeStale: bool 
    
    @param includeMatch: A callable used to decide whether to include
    certain files in the extraction. This could be a python callable that
    returns True to include the file or False to exclude it, or a regular
    expression function such as re.compile().match or re.match.
    @type includeMatch: any callable 
    
    @return: A DirectoryTarget that will complete when the extraction has finished.
    @rtype: L{DirectoryTarget} 
    """
        if not isinstance(targetDir, basestring):
            raise TypeError("targetDir must be a string")

        engine = self.engine
        configuration = self.configuration
        basePath = configuration.basePath

        targetDir = basePath(targetDir)
        source = basePath(source)

        def _extract():
            sourcePath = getPath(source)
            absTargetDir = configuration.abspath(targetDir)
            zipFile = zipfile.ZipFile(configuration.abspath(sourcePath), "r")
            try:
                zipInfos = zipFile.infolist()

                if includeMatch is not None:
                    zipInfos = [
                        z for z in zipInfos if includeMatch(z.filename)
                    ]

                if removeStale:
                    filesInZip = set()
                    for zipInfo in zipInfos:
                        filesInZip.add(
                            os.path.normcase(os.path.normpath(
                                zipInfo.filename)))

                    searchDir = os.path.normpath(absTargetDir)
                    for path in cake.filesys.walkTree(searchDir):
                        normPath = os.path.normcase(path)
                        # Skip files that also exist in the zip.
                        if normPath in filesInZip:
                            continue
                        if engine.dependencyInfoPath is None:
                            # Skip .dep files that match a file in the zip.
                            p, e = os.path.splitext(normPath)
                            if e == ".dep" and p in filesInZip:
                                continue

                        absPath = os.path.join(searchDir, path)
                        engine.logger.outputInfo(
                            "Deleting %s\n" % os.path.join(targetDir, path), )
                        if os.path.isdir(absPath):
                            cake.filesys.removeTree(absPath)
                        else:
                            cake.filesys.remove(absPath)

                for zipinfo in zipInfos:
                    _extractFile(configuration, zipFile, sourcePath, zipinfo,
                                 targetDir, absTargetDir, onlyNewer)
            finally:
                zipFile.close()

        def _run():
            try:
                _extract()
            except BuildError:
                raise
            except Exception, e:
                msg = "cake: Error extracting %s to %s: %s\n" % (
                    getPath(source), targetDir, str(e))
                engine.raiseError(msg, targets=[targetDir])

        if self.enabled:
            task = engine.createTask(_run)
            task.lazyStartAfter(getTask(source))
        else:
            task = None

        directoryTarget = DirectoryTarget(path=targetDir, task=task)

        Script.getCurrent().getDefaultTarget().addTarget(directoryTarget)

        return directoryTarget
Пример #5
0
            newDependencyInfo = configuration.createDependencyInfo(
                targets=[target],
                args=buildArgs,
                dependencies=[],
            )
            configuration.storeDependencyInfo(newDependencyInfo)

        def _run():
            try:
                return _compress()
            except BuildError:
                raise
            except Exception, e:
                msg = "cake: Error creating %s: %s\n" % (target, str(e))
                engine.raiseError(msg, targets=[target])

        if self.enabled:
            task = engine.createTask(_run)
            task.lazyStartAfter(getTask(source))
        else:
            task = None

        fileTarget = FileTarget(path=target, task=task)

        currentScript = Script.getCurrent()
        currentScript.getDefaultTarget().addTarget(fileTarget)
        currentScript.getTarget(
            cake.path.baseName(target)).addTarget(fileTarget)

        return fileTarget
Пример #6
0
      # Now that the zip has been written successfully, save the new dependency file 
      newDependencyInfo = configuration.createDependencyInfo(
        targets=[target],
        args=buildArgs,
        dependencies=[],
        )
      configuration.storeDependencyInfo(newDependencyInfo)

    def _run():
      try:
        return _compress()
      except BuildError:
        raise
      except Exception, e:
        msg = "cake: Error creating %s: %s\n" % (target, str(e))
        engine.raiseError(msg, targets=[target])
      
    if self.enabled:
      task = engine.createTask(_run)
      task.lazyStartAfter(getTask(source))
    else:
      task = None

    fileTarget = FileTarget(path=target, task=task)

    currentScript = Script.getCurrent()
    currentScript.getDefaultTarget().addTarget(fileTarget)
    currentScript.getTarget(cake.path.baseName(target)).addTarget(fileTarget)

    return fileTarget
Пример #7
0
    def run(self, func, args=None, targets=None, sources=[]):
        """Execute the specified python function as a task.

    Only executes the function after the sources have been built and only
    if the target exists, args is the same as last run and the sources
    haven't changed.

    @note: I couldn't think of a better class to put this function in so
    for now it's here although it doesn't really belong.
    """
        engine = self.engine
        configuration = self.configuration

        basePath = configuration.basePath

        targets = basePath(targets)
        sources = basePath(sources)

        def _run():
            sourcePaths = getPaths(sources)
            if targets:
                buildArgs = (args, sourcePaths)
                try:
                    _, reason = configuration.checkDependencyInfo(
                        targets[0],
                        buildArgs,
                    )
                    if reason is None:
                        # Up to date
                        return

                    engine.logger.outputDebug(
                        "reason",
                        "Building '%s' because '%s'\n" % (targets[0], reason),
                    )
                except EnvironmentError:
                    pass

            try:
                result = func()
            except Exception:
                if targets:
                    append = engine.failedTargets.append
                    for t in targets:
                        append(t)
                raise

            if targets:
                newDependencyInfo = configuration.createDependencyInfo(
                    targets=targets,
                    args=buildArgs,
                    dependencies=sourcePaths,
                )
                configuration.storeDependencyInfo(newDependencyInfo)

            return result

        if self.enabled:
            task = engine.createTask(_run)
            task.lazyStartAfter(getTask(sources))
        else:
            task = None

        currentScript = Script.getCurrent()

        if targets is not None:
            targets = [FileTarget(path=t, task=task) for t in targets]
            currentScript.getDefaultTarget().addTargets(targets)
            return targets
        else:
            target = Target(task)
            currentScript.getDefaultTarget().addTarget(target)
            return target
Пример #8
0
  def run(self, func, args=None, targets=None, sources=[]):
    """Execute the specified python function as a task.

    Only executes the function after the sources have been built and only
    if the target exists, args is the same as last run and the sources
    haven't changed.

    @note: I couldn't think of a better class to put this function in so
    for now it's here although it doesn't really belong.
    """
    engine = self.engine
    configuration = self.configuration

    basePath = configuration.basePath
    
    targets = basePath(targets)
    sources = basePath(sources)

    def _run():
      sourcePaths = getPaths(sources)
      if targets:
        buildArgs = (args, sourcePaths)
        try:
          _, reason = configuration.checkDependencyInfo(
            targets[0],
            buildArgs,
            )
          if reason is None:
            # Up to date
            return
          
          engine.logger.outputDebug(
            "reason",
            "Building '%s' because '%s'\n" % (targets[0], reason),
            )
        except EnvironmentError:
          pass

      try:
        result = func()
      except Exception:
        if targets:
          append = engine.failedTargets.append
          for t in targets:
            append(t)
        raise
      
      if targets:
        newDependencyInfo = configuration.createDependencyInfo(
          targets=targets,
          args=buildArgs,
          dependencies=sourcePaths,
          )
        configuration.storeDependencyInfo(newDependencyInfo)
        
      return result

    if self.enabled:
      task = engine.createTask(_run)
      task.lazyStartAfter(getTask(sources))
    else:
      task = None

    currentScript = Script.getCurrent()

    if targets is not None:
      targets = [FileTarget(path=t, task=task) for t in targets]
      currentScript.getDefaultTarget().addTargets(targets)
      return targets
    else:
      target = Target(task)
      currentScript.getDefaultTarget().addTarget(target)
      return target