Beispiel #1
0
def _copy_or_move(ctx, src, dst, function, function_name):
    """
    Helper function to simplify copies and moves.
    """

    src = Path(src)
    dst = Path(dst).addroot(ctx.buildroot)

    if not dst.exists():
        # if dst ends with the separator, treat it like a directory
        if dst.endswith(os.sep):
            dst.makedirs()
            dst = dst / src.name
        else:
            dst.parent.makedirs()
    elif dst.isdir():
        # If the dst is a directory, we're just copying that file into that
        # directory.
        dst = dst / src.name

    ctx.logger.check(' * %s' % function_name, '%s -> %s' % (src, dst),
        color='yellow')
    function(src, dst)

    return dst
Beispiel #2
0
    def prune(self, prune_get_all, prune_get_bad):
        """Delete all destination files that were not referenced during this
           build. This will leave any files outside the build directory. To
           override this function's behavior, use prune_get_all and
           prune_get_bad."""
        all_targets = set(prune_get_all(self))
        bad_targets = prune_get_bad(
            self, all_targets - self.db.active_files -
            {self.options.state_file, self.options.log_file})

        def error_handler(func, path, exc):
            self.logger.log('error deleting file %s: %s' % (path, exc[1]),
                            color='red')

        for file in bad_targets:
            file = Path(file)
            # XXX: There should be a color better than 'compile' for this.
            self.logger.check(' * prune', file, color='compile')
            if file.isdir():
                file.rmtree(ignore_errors=True, on_error=error_handler)
            else:
                try:
                    file.remove()
                except:
                    error_handler(None, file, sys.exc_info())
Beispiel #3
0
def _copy_or_move(ctx, src, dst, function, function_name):
    """
    Helper function to simplify copies and moves.
    """

    src = Path(src)
    dst = Path(dst).addroot(ctx.buildroot)

    if not dst.exists():
        # if dst ends with the separator, treat it like a directory
        if dst.endswith(os.sep):
            dst.makedirs()
            dst = dst / src.name
        else:
            dst.parent.makedirs()
    elif dst.isdir():
        # If the dst is a directory, we're just copying that file into that
        # directory.
        dst = dst / src.name

    ctx.logger.check(' * %s' % function_name,
                     '%s -> %s' % (src, dst),
                     color='yellow')
    function(src, dst)

    return dst
Beispiel #4
0
 def prune(self, prune_get_all, prune_get_bad):
     """Delete all destination files that were not referenced during this
        build. This will leave any files outside the build directory. To
        override this function's behavior, use prune_get_all and
        prune_get_bad."""
     all_targets = set(prune_get_all(self))
     bad_targets = prune_get_bad(self, all_targets - self.db.active_files -
                                       {self.options.state_file,
                                        self.options.log_file})
     def error_handler(func, path, exc):
         self.logger.log('error deleting file %s: %s' % (path, exc[1]),
             color='red')
     for file in bad_targets:
         file = Path(file)
         # XXX: There should be a color better than 'compile' for this.
         self.logger.check(' * prune', file, color='compile')
         if file.isdir():
             file.rmtree(ignore_errors=True, on_error=error_handler)
         else:
             try:
                 file.remove()
             except:
                 error_handler(None, file, sys.exc_info())