def skip(self, path: str) -> bool: regex = utils.match(path, self.regexes) if regex: log.info(f"skipping '{path}' matched by '{regex}'") return True return False
def __iter__(self): already_searched = set() for branch in self._get_branches(): log.info(f"switching to branch '{branch}'") prev_commit = None since_commit_reached = False commits = self.repo.iter_commits(branch, max_count=self.max_depth) for curr_commit in commits: if curr_commit.hexsha == self.since_commit: since_commit_reached = True if self.since_commit and since_commit_reached: prev_commit = curr_commit continue diff_hash = str(prev_commit) + str(curr_commit) if not prev_commit or diff_hash in already_searched: prev_commit = curr_commit continue diff = prev_commit.diff(curr_commit, create_patch=True) already_searched.add(diff_hash) yield from self._diff_worker(diff, prev_commit, branch) prev_commit = curr_commit diff = curr_commit.diff(git.NULL_TREE, create_patch=True) yield from self._diff_worker(diff, prev_commit, branch)
def run(): args = _get_cmdline_args() log.setLevel(logging.ERROR - args.verbose * 10) if args.render_html: issues = [] for src in args.source: log.info(f"loading '{src}'") issues.extend(utils.load(src)) write(issues, file=args.output, format="html") return 0 if args.config: config = _load_config(args.config) rules = utils.load(args.rules) issues = [] for src in args.source: with TemporaryDirectory() as tmp: copy(src, tmp) if not args.config: config = _search_config(tmp) issues.extend(scan(tmp, config, rules)) write(issues, file=args.output, format=args.format) return bool(issues)
def copy(source: str, destination: str): log.info(f"copying '{source}' to '{destination}'") if parse.urlparse(source).scheme in ("http", "https"): git.Repo.clone_from(source, destination) else: if os.path.isdir(source): dir_util.copy_tree(source, destination, preserve_symlinks=True) else: shutil.copy2(source, destination)
def should_skip(self, match: str, line: str, path: str = "") -> bool: exclude = self.skip.get("/", []) if path in self.skip: exclude.extend(self.skip[path]) for s in exclude: if line.find(s) >= 0: log.info( f"skipping line '{line}' matched by '{s}' from '{path}'") return True return False
def _load_config(file: File = None) -> Config: config = Config() if file: user_config = utils.load(file) if user_config: config.update(**user_config) else: log.warning(f"empty config supplied: '{_name(file)}'") args = _get_cmdline_args(**config.raw) config.update(**args.__dict__) log.info(f"using config\n\n{config}") return config
def write(issues: Issues, file: File = None, format: str = "text"): if format == "text": f = TEXT elif format == "json": f = JSON elif format == "yaml": f = YAML elif format == "html": f = HTML else: raise NotImplementedError(f"unknown format: {format}") log.info(f"writing {format.upper()} to '{_name(file)}'") utils.dump(f(issues), file)