diff --git a/ext_open/config.py b/ext_open/config.py index 2c59cbb..d707556 100644 --- a/ext_open/config.py +++ b/ext_open/config.py @@ -19,5 +19,6 @@ class MyParser(configparser.ConfigParser): def getpaths(self,section,option,fallback=None): data = self.getlist(section,option,fallback) return list(map(osp.expandvars,data)) + config = MyParser() config.read(CONFIG_PATH) \ No newline at end of file diff --git a/ext_open/ext_open.py b/ext_open/ext_open.py index 7288540..0175826 100644 --- a/ext_open/ext_open.py +++ b/ext_open/ext_open.py @@ -2,17 +2,18 @@ from opts import * import searcher import opener import argparse -parser = argparse.ArgumentParser(prog='ext-open',prefix_chars = '+') +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() -exe_parser = sub_parsers.add_parser('exe',prefix_chars='+') +sub_parsers = parser.add_subparsers(dest='ext') +exe_parser = sub_parsers.add_parser('exe',prefix_chars=prefix_char) for opt in exe: exe_parser.add_argument(*opt.pop('ostring'),**opt) for ext in exts: - sub_parser = sub_parsers.add_parser(ext['ext'],prefix_chars = '+') + sub_parser = sub_parsers.add_parser(ext['ext'],prefix_chars=prefix_char) for opt in ext['opts']+common: opt = opt.copy() sub_parser.add_argument(*opt.pop('ostring'),**opt) if __name__ == '__main__': - args = parser.parse_args() \ No newline at end of file + args = parser.parse_args() + print(args) \ No newline at end of file diff --git a/ext_open/opener.py b/ext_open/opener.py index 3916cc8..02f488f 100644 --- a/ext_open/opener.py +++ b/ext_open/opener.py @@ -27,6 +27,8 @@ def standalone(path,params=[],windowless =False,cwd = None): params = list(map(os.path.expandvars,params)) if not cwd: cwd = os.path.dirname(path) + if cwd == '': + cwd = os.getcwd() else: cwd = os.path.expandvars(cwd) if windowless: @@ -36,7 +38,11 @@ def standalone(path,params=[],windowless =False,cwd = None): subprocess.Popen([path]+params,cwd=cwd) -def dependant(path,params=[],mode = 'execute'): +def dependant(path,params=[],mode = 'execute',cwd = None): + if not cwd: + cwd = os.path.dirname(path) + if cwd == '': + cwd = os.getcwd() params = list(map(os.path.expandvars,params)) ext = get_ext(path) if ext: @@ -44,4 +50,4 @@ def dependant(path,params=[],mode = 'execute'): handler = shlex.split(config.getpath(ext,mode)) args = handler+[path]+params - subprocess.Popen(args) + subprocess.Popen(args,cwd=cwd) diff --git a/ext_open/opts.py b/ext_open/opts.py index d115b37..cb0cb76 100644 --- a/ext_open/opts.py +++ b/ext_open/opts.py @@ -1,40 +1,35 @@ +prefix_char = '+' prefix = [ { 'ostring':['+u','++update'], - 'help':'update the listings for ext', + 'help': 'Update the listings for ext', 'action':'store_true', }, { - 'ostring':['+t','++trim+history'], - 'help': 'trim backup history, either all or N updates', + 'ostring':['+t','++trim-history'], + 'help': 'Trim backup history, either all or N updates', 'metavar': '(all | N)' }, { - 'ostring':['+m','++update+modified+times'], + 'ostring':['+m','++update-modified-times'], 'help': '''updates the modified times for paths in config useful for ensuring all new files are found''', }, - ] -common = [ - { - 'ostring':['+e','++edit'], - 'help': 'open in editor', - 'action': 'store_true', - }, - { - 'ostring':['+r','++regex'], - 'action':'store_true', - 'help':'use regex to search', - }, +bools = [ + {'action': 'store_true', 'ostring': ['+i', '++case-insensitive']}, + {'action': 'store_true', 'help': 'Search for exact application name', 'ostring': ['+E', '++exact']}, + {'action': 'store_true', 'help': 'Use regex to search', 'ostring': ['+r', '++regex']}, + {'action': 'store_true', 'help': 'Prints path instead of opening application', 'ostring': ['+p', '++path']}, + {'action': 'store_true', 'help': 'Open in editor', 'ostring': ['+e', '++edit']}, + ] - { - 'ostring':['arg'], - 'help':'command-line args', - 'action':'store', - 'nargs':'*' - } -] +other = [ + {'help': 'Directory to start in', 'ostring': ['+d', '++start-in'],'metavar':'dir'}, + {'ostring':['query'],'help':'Query to search for'}, + {'action': 'store', 'help': 'Command-line args', 'nargs': '*', 'ostring': ['arg']}, + ] +common = bools+other exts = [ { 'ext' : 'py', @@ -48,7 +43,7 @@ exts = [ exe = [ { 'ostring':['+w','++windowless'], - 'help':'open windowless', + 'help': 'Open windowless', 'action': 'store_true', }, ] \ No newline at end of file diff --git a/ext_open/update.py b/ext_open/update.py index 024139c..a6e0be4 100644 --- a/ext_open/update.py +++ b/ext_open/update.py @@ -21,7 +21,9 @@ def update_mtimes(starts): if not is_admin() and FORCE_ADMIN: raise Exception("Process must be admin") for start in starts: - subprocess.check_call([EXE_PATH,'/stext','nul','/BaseFolder',start]) + EXE_PATH = shlex.split(EXE_PATH) + EXE_PATH.append(start) + subprocess.check_call(EXE_PATH) def build(after,starts): if isinstance(after,datetime.datetime): @@ -32,10 +34,7 @@ def build(after,starts): try: for file in files: yield os.path.join(root,file) - dirs[:] = list(filter( - lambda p: osp.getmtime(osp.join(root,p)) > after, - dirs - )) + dirs[:] = list(filter(lambda p: osp.getmtime(osp.join(root,p)) > after,dirs)) except: print('Error',root,sep= ': ') @@ -102,5 +101,4 @@ if __name__ == "__main__": parser.add_argument('ext') parser.add_argument('-m','--update-modified-time',action='store_true') args = parser.parse_args() - print(args) update(args.ext,args.update_modified_time)