def main(): parser = argparse.ArgumentParser( description='Index directories recursive.') parser.add_argument('roots', metavar='DIR', nargs='*', default=["."], help="a directory to index " + "(if not given '.' will be used)") add_common_command_line_arguments(parser) parser.add_argument('-x', '--exclude-files', metavar='GLOBPATTERNS', nargs=1, action="append", default=[DEFAULT_FILE_EXCLUDE], help=("Exclude files based on comma separated " + "glob patterns. Default is %r.") % DEFAULT_FILE_EXCLUDE) parser.add_argument('-X', '--exclude-dirs', metavar='GLOBPATTERNS', nargs=1, action="append", default=[DEFAULT_DIR_EXCLUDE], help=("Exclude directories based on comma separated " + "glob patterns. Default is %r.") % DEFAULT_DIR_EXCLUDE) args = parser.parse_args() repo = dfr.db.Database(args.db[0]) excluded_files = cleanup(args.exclude_files, DEFAULT_FILE_EXCLUDE) excluded_dirs = cleanup(args.exclude_dirs, DEFAULT_DIR_EXCLUDE) excluded_files = globs_to_regexp(excluded_files) excluded_dirs = globs_to_regexp(excluded_dirs) indexer = BitIndexer(repo, excluded_files, excluded_dirs) indexer.run(args.roots)
def test_globs_to_regexp(self): self.assertEqual(globs_to_regexp(["*"]), "(.*\\Z(?ms))") self.assertEqual(globs_to_regexp([".git", "CSV"]), "(\\.git\\Z(?ms))|(CSV\\Z(?ms))") self.assertEqual(globs_to_regexp(["*(", "[0-9]", "*foo*"]), "(.*\\(\\Z(?ms))|([0-9]\\Z(?ms))|(.*foo.*\\Z(?ms))")