Example #1
0
    def __run(self, stream, dry):
        callback = None
        if dry:
            logger.info("Dry-running job for path '%s'" % self.__walker.root())

            callback = self.__show_file
        else:
            logger.info("Running job for path '%s'" % self.__walker.root())

            max_lines = 0
            for l in self.__licenses:
                max_lines          = max(max_lines, l.lines())
                self.__slurp_lines = 2 * max_lines

            logger.debug("Slurping %d maximum lines for each file" %
                         self.__slurp_lines)

            callback = self.__check_file
        assert(callback is not None)

        self.__stream = stream
        self.__walker.run(file_callback = callback)
        self.__stream = None
Example #2
0
    rets = map(lambda obj: obj.run(stream = s,
                                   dry    = args.dry_run), jobs)
    logger.debug("%d jobs completed" % len(rets))

    retval = 0
    if False in rets:
        logger.warning("Got problems")
        retval = 1

    logger.debug("Everything seems ok")

    return retval

if __name__ == "__main__":
    retval = 1
    try:
        retval = main(sys.argv[1:])
    except KeyboardInterrupt, e:
        logger.info("Bye bye ...\n")
        retval = 0
    except AssertionError, e:
        print("%s: Assertion error" % program_name)
        if len(str(e)) != 0:
            print("%s: Value is '%s'" % (program_name, str(e)))
        traceback.print_tb(sys.exc_info()[2], file = sys.stdout)
        print("Please report to <" + program_bugreport + ">")
    except Exception, e:
        print("%s: %s" % (program_name, str(e)))
    sys.exit(retval)
sys.exit(0)
Example #3
0
    def __walk(self,
               root,
               file_callback,
               directory_callback,
               globs):

        assert(globs is not None)

        current_dir = os.path.abspath(root)

        logger.debug("Walking directory '%s'" % current_dir)

        entries = os.listdir(current_dir)
        logger.debug("Directory entries are: '%s'" % entries)

        assert("."  not in entries)
        assert(".." not in entries)

        if (self.__ignore is not None) and (self.__ignore in entries):
            p = os.path.join(current_dir, self.__ignore)
            logger.debug("Found ignore file '%s'" % p)

            gf = GlobsFile(p)
            logger.debug("Globs file parsed successfully")

            gl = gf.globs()
            logger.debug("Ignore file '%s' produced %d globs" %
                         (p, len(gl)))

            globs = globs + gl
            logger.debug("Globs are now %d" % len(globs))
            entries.remove(self.__ignore)

        assert(self.__ignore not in entries)
        assert(globs is not None)

        logger.debug("We have %d globs for directory '%s': %s" %
                     (len(globs), current_dir, map(str, globs)))

        for entry in entries:
            rel_path = entry
            abs_path = os.path.abspath(os.path.join(current_dir, rel_path))

            assert(not os.path.isabs(rel_path))
            assert(    os.path.isabs(abs_path))

            skip = False
            for g in globs:
                x = None
                if g.match(rel_path):
                    logger.debug("Relative path '%s' got a match with '%s'" %
                                 (rel_path, g.pattern()))
                    if g.is_inclusive():
                        skip = False
                    else:
                        skip = True
                    continue

                if g.match(abs_path):
                    logger.debug("Absolute path '%s' got a match with '%s'" %
                                 (abs_path, g.pattern()))
                    if g.is_inclusive():
                        skip = False
                    else:
                        skip = True
                    continue
            if skip:
                logger.info("Skipping '%s'" % abs_path)
                continue

            logger.debug("Handling path '%s'" % abs_path)
            liche.utils.path_exists_barrier(abs_path)

            if os.path.isdir(abs_path):
                liche.utils.directory_exists_barrier(abs_path)

                if directory_callback is not None:
                    directory_callback(abs_path)

                self.__walk(abs_path,
                            file_callback,
                            directory_callback,
                            globs)
            elif os.path.isfile(abs_path):
                liche.utils.file_exists_barrier(abs_path)

                if file_callback is not None:
                    file_callback(abs_path)
            elif os.path.ismount(abs_path):
                logger.warning("Skipping '%s' (mount point)" %
                               abs_path)
            else:
                logger.warning("Skipping '%s' (not a file or directory)" %
                               abs_path)

        logger.debug("Completed handling directory '%s' (%d globs)" %
                     (current_dir, len(globs)))