示例#1
0
文件: main.py 项目: IDCH/lha
    def add_file(self, p):
        """ Adds the specified file to the import queue.
        """
        log = self._app.log

        # Sanity checks
        if not p.exists():
            raise IOError((errno.ENOENT, "Cannot add file: does not exist.", p))
        if not p.isfile():
            raise IOError((errno.ENOTDIR, "Cannot add file: not a file.", p))
        if self.rootpath.relpathto(p).startswith(".."):
            raise ValueError("The supplied file is not a child of the document root.")

        if p.ext not in FILETYPES:
            log.debug("Skipping file %s. Filetype not supported." % (p))
            return

        if self.has_been_imported(p):
            # TODO check datestamp to see if it needs to be updated
            log.debug("Skipping file %s. Already processed.")
            return

        log.info("Queueing file for import: '%s'" % (p))
        parser = DocumentFileParser(p, self.rootpath, log)
        parser.parse()
        self.import_queue.append(parser)
示例#2
0
文件: main.py 项目: IDCH/lha
    def add_dir(self, directory):
        """ Adds all files in a given directory tree to the import queue.
        """
        log = self._app.log
        if self.rootpath is None:
            self.rootpath = directory

        # Sanity checks
        if not directory.exists():
            raise IOError((errno.ENOENT, "Cannot add directory: does not exist.", directory))
        if not directory.isdir():
            raise IOError((errno.ENOTDIR, "Cannot add directory: not a directory.", directory))
        if self.rootpath.relpathto(directory).startswith(".."):
            raise ValueError("The supplied directory is not a child of the document root.")

        # Skip hidden files (i.e. files that begin with a dot)
        dirname = directory.basename()
        if dirname.startswith("."):
            log.debug("Skipping: '" + directory + "'")
            return

        log.debug("Adding directory: '" + directory + "'")

        for f in directory.files():  # add files to queue
            self.add_file(f)

        for d in directory.dirs():  # process directories recursively
            self.add_dir(d)
示例#3
0
def parse_common_args(args: NamedTuple):
    if args.verbose:
        logger.setup_logging(True)
        log.debug("Verbose logging enabled")
    else:
        logger.setup_logging(False)
示例#4
0
文件: lsc.py 项目: asteven/cli
 def setup(self):
     cli.log.LoggingApp.setup(self)
     cli.complete.CompletionMixin.setup(self)
     log.debug('MyApp.setup')