def index(): dirs = filter(lambda n: not n.startswith('.'), list_dirs('.')) if len(dirs) > 1: for i, dir in enumerate(dirs): print("%*d. %s" % (3, i + 1, dir)) dirname = raw_input("Which directory should be reindexed? (number or name): ") if not isdir(dirname): dirname = dirs[int(dirname) - 1] else: dirname = dirs[0] inputfiles = filter(lambda f: f.endswith('.txt'), list_files(dirname)) print("Will reindex %s" % dirname) start = time() q, w = Droogle.index(dirname, inputfiles, r'(?:\r?\n|\n)\w*(?:\r?\n|\n)') end = time() delta = end - start print("%d questions, %d words were indexed in %dm %ds." % (q, w, delta / 60, delta % 60)) config = Serializer.from_json('config.json') if path.isfile('config.json') else {} config['index'] = dirname Serializer.to_json(config, 'config.json', gz=False)
def query(): config = { 'index': '', 'results': 5 } if path.isfile('config.json'): config.update(Serializer.from_json('config.json')) if not len(config['index']): print("No index directory is configured. Create a directory, put Drill files inside and index it.") exit(1) elif not path.isdir(config['index']): print("Directory %s doesn't exist. Create it, copy Drill files into it and index it." % config['index']) exit(1) try: droogle = Droogle(config['index']) except FileMissingError, (ex): print( "Some index file is missing in %s: %s.\nAllowed extensions are:" % (config['index'], ex.filename), ', '.join(map(lambda s: s[2:], Droogle.SUFFIXES)) ) exit(1)
def flush(self, existing=False): Serializer.flush(self, existing) self.lines = iter(self.f)
def flush(self, existing=False): Serializer.flush(self, existing)