From def2a4c05d8e6eacf979476f59bfacc835e69ac2 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sun, 4 Nov 2018 20:23:31 -0600 Subject: [PATCH] searcher does not call __init_table__ while updating removed duplicate exe options --- ext_open/ext_open.py | 90 ++++++++++++++++++++++---------------------- ext_open/opts.json | 12 +++--- ext_open/searcher.py | 3 +- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/ext_open/ext_open.py b/ext_open/ext_open.py index d7a75d8..5951d47 100644 --- a/ext_open/ext_open.py +++ b/ext_open/ext_open.py @@ -6,10 +6,11 @@ import opener import pyperclip import searcher parser = argparse.ArgumentParser(prog='ext-open',prefix_chars=prefix_char) -for opt in prefix: - parser.add_argument(*opt.pop('ostring'),**opt) sub_parsers = parser.add_subparsers(dest='ext') exe_parser = sub_parsers.add_parser('exe',prefix_chars=prefix_char) +update_parser = sub_parsers.add_parser('update',prefix_chars=prefix_char) +for opt in prefix: + update_parser.add_argument(*opt.pop('ostring'),**opt) for opt in exe: opt = opt.copy() exe_parser.add_argument(*opt.pop('ostring'),**opt) @@ -18,53 +19,54 @@ for ext in exts: for opt in ext['opts']+common: opt = opt.copy() sub_parser.add_argument(*opt.pop('ostring'),**opt) -if __name__ == '__main__': +if __name__ == "__main__": args = parser.parse_args() - print(args) ext = args.ext - s = searcher.Searcher(ext,args.case_sensitive) - if args.trim_history is not None: - if args.trim_history.lower() == 'all': - if input('Are you sure?\n(y/n): ') == 'y': - s.clear() - elif args.trim_history.isdecimal: - n = int(args.trim_history) - s.clean(n) - del args.__dict__['trim_history'] - if args.__dict__.pop('update'): + if ext == 'update': + ext = args.update_ext + s = searcher.Searcher(ext) + if args.trim_history is not None: + if args.trim_history.lower() == 'all': + if input('Are you sure?\n(y/n): ') == 'y': + s.clear() + elif args.trim_history.isdecimal: + n = int(args.trim_history) + s.clean(n) s.update() - if args.__dict__.pop('exact'): - matches = s.exact(args.query) - else: - matches = s.search(args.query,args.regex) - if len(matches) == 0: - print('No matches') - quit() - if len(matches) == 1: - row = matches[0] else: - if len(matches) <= 20: - row = picker(matches) + s = searcher.Searcher(args.ext) + if args.__dict__.pop('exact'): + matches = s.exact(args.query) else: - row = picker(matches,True) - path = row[-1] - if args.path: - print(path) - pyperclip.copy(path) - else: - if args.ext == 'exe': - opener.standalone(path,args.arg,args.windowless,args.start_in) + matches = s.search(args.query,args.regex) + if len(matches) == 0: + print('No matches') + quit() + if len(matches) == 1: + row = matches[0] + else: + if len(matches) <= 20: + row = picker(matches) + else: + row = picker(matches,True) + path = row[-1] + if args.path: + print(path) + pyperclip.copy(path) else: - if args.edit: - opener.edit(path,args.arg) + if args.ext == 'exe': + opener.standalone(path,args.arg,args.windowless,args.start_in) else: - mode = 'execute' - ext_argnames = cur.get(args.ext).argnames - bools = filter(lambda arg: isinstance(args.__dict__[arg],bool),args.__dict__.keys()) - canidates = filter(lambda arg: arg in ext_argnames,bools) - for canidate in canidates: - if canidate in config[ext].keys(): - mode = canidate - break + if args.edit: + opener.edit(path,args.arg) + else: + mode = 'execute' + ext_argnames = cur.get(args.ext).argnames + bools = filter(lambda arg: isinstance(args.__dict__[arg],bool),args.__dict__.keys()) + canidates = filter(lambda arg: arg in ext_argnames,bools) + for canidate in canidates: + if canidate in config[ext].keys(): + mode = canidate + break - opener.dependant(path,args.arg,mode,args.start_in) \ No newline at end of file + opener.dependant(path,args.arg,mode,args.start_in) \ No newline at end of file diff --git a/ext_open/opts.json b/ext_open/opts.json index 6e98722..723d128 100644 --- a/ext_open/opts.json +++ b/ext_open/opts.json @@ -1,4 +1,3 @@ - { "bools": [ { @@ -89,11 +88,6 @@ } ], "prefix": [ - { - "action": "store_true", - "help": "Update the listings for ext", - "ostring": ["+u", "++update"] - }, { "help": "Trim backup history, either all or N updates", "metavar": "(all | N)", @@ -103,6 +97,12 @@ "action": "store_true", "help": "updates the modified times for paths in config\nuseful for ensuring all new files are found", "ostring": ["+m", "++update-modified-times"] + }, + { + "ostring": [], + "metavar": "ext", + "dest": "update_ext", + "help": "file extension listing to update" } ], "prefix_char": "+" diff --git a/ext_open/searcher.py b/ext_open/searcher.py index 13182ef..028bbbe 100644 --- a/ext_open/searcher.py +++ b/ext_open/searcher.py @@ -40,7 +40,8 @@ class Searcher: self.update_proc = None self.case = case_sensitive self.index = '{}_index'.format(ext) - self.__init_table__() + if not self.updating: + self.__init_table__() def __init_table__(self): self.cur.execute('CREATE TABLE IF NOT EXISTS {} (`name` TEXT,`fullpath` TEXT, `update_time` INTEGER,UNIQUE(name,fullpath));'.format(self.ext))