From fd51fcac51d02f86c8c35e7cbc12629b95ca7715 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 19 Oct 2012 14:45:30 -0400 Subject: [PATCH] evaluate server list against file names to determine remote server name --- gvim-wrapper.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gvim-wrapper.py b/gvim-wrapper.py index ce2ccfd..f814d80 100644 --- a/gvim-wrapper.py +++ b/gvim-wrapper.py @@ -4,7 +4,7 @@ import sys config = { # path to directory containing vim.exe and gvim.exe 'vimdir': 'C:\\apps\\Vim\\vim73', - # list of (name, path) tuples defining gvim contexts + # list of (path, name) tuples defining gvim contexts 'servers': [], # default server name to use if no server paths match 'default_server': 'GVIM', @@ -27,7 +27,25 @@ def read_config_file(config, path): sys.stderr.write(' File "%s", line %d, in %s\n' % (path, lineno, fn)) +def path_contains_file(path, fname): + path = path.replace('\\', '/') + fname = fname.replace('\\', '/') + if path.endswith('/'): + path = path[:-1] + return fname.startswith(path + '/') + def get_server_name(config, fname): + for path, name in config['servers']: + path = path.replace('\\', '/') + if path.endswith('/*'): + path = path[:-2] + for dirent in os.listdir(path): + query_path = os.path.join(path, dirent) + if os.path.isdir(query_path) and path_contains_file(query_path, fname): + return name.replace('*', dirent) + else: + if path_contains_file(path, fname): + return name.replace('*', os.path.basename(path)) return config['default_server'] def main(argv):