def index(): from optparse import OptionParser parser = OptionParser(usage="usage: %prog indexer.ini") parser.add_option("-f", "--full-index", dest="full", action="store_true", default=False, help="Index all files matching allfileglob instead of fileglob") (options, args) = parser.parse_args() if not args: parser.print_help() return 1 the_glob = options.full and 'allfileglob' or 'fileglob' cfg_data = config.read_config(args[0]) skiptime = int(cfg_data['skip_time']) files = sorted(glob.glob(cfg_data[the_glob])) if not files and not options.full: print "No files matched 'fileglob', perhaps you need --full-index?" return 1 if skiptime > 0: files = filter_by_mtime(files, skiptime) return do_index(cfg_data['indexer'], cfg_data, files)
def cleanup(): from optparse import OptionParser parser = OptionParser(usage="usage: %prog indexer.ini") parser.add_option("-d", "--delete", dest="delete", action="store_true", default=False, help="Delete old database files, don't just print a report") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() return 1 cfg_data = config.read_config(args[0]) indexer = get_indexer(cfg_data['indexer']) i = indexer(cfg_data) databases = sorted([x for x in os.listdir(cfg_data['dbpath']) if x.endswith(".db")]) data_files = glob.glob(cfg_data['allfileglob']) needed_databases = set([i.fn_to_db(f) for f in data_files]) to_delete = [x for x in databases if x not in needed_databases] for x in to_delete: full_path = os.path.join(cfg_data['dbpath'], x) if options.delete: print "Deleting", full_path shutil.rmtree(full_path) else: print "Need to delete:", full_path
def cleanup(): from optparse import OptionParser parser = OptionParser(usage = "usage: %prog indexer.ini") parser.add_option("-d", "--delete", dest="delete", action="store_true", default=False, help="Delete old database files, don't just print a report") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() return 1 cfg_data = config.read_config(args[0]) indexer = get_indexer(cfg_data['indexer']) i = indexer(cfg_data) databases = sorted([x for x in os.listdir(cfg_data['dbpath']) if x.endswith(".db")]) data_files = glob.glob(cfg_data['allfileglob']) needed_databases = set([i.fn_to_db(f) for f in data_files]) to_delete = [x for x in databases if x not in needed_databases] for x in to_delete: full_path = os.path.join(cfg_data['dbpath'], x) if options.delete: print "Deleting", full_path shutil.rmtree(full_path) else: print "Need to delete:", full_path
def index(): from optparse import OptionParser parser = OptionParser(usage = "usage: %prog indexer.ini") parser.add_option("-f", "--full-index", dest="full", action="store_true", default=False, help="Index all files matching allfileglob instead of fileglob") (options, args) = parser.parse_args() if not args: parser.print_help() return 1 the_glob = options.full and 'allfileglob' or 'fileglob' cfg_data = config.read_config(args[0]) files = sorted(glob.glob(cfg_data[the_glob])) if not files and not options.full: print "No files matched 'fileglob', perhaps you need --full-index?" return 1 return do_index(cfg_data['indexer'], cfg_data, files)
def __init__(self, ini_file): self.cfg_data = config.read_config(ini_file) self.searcher = get_searcher(self.cfg_data['indexer'])