evaluate server list against file names to determine remote server name

This commit is contained in:
Josh Holtrop 2012-10-19 14:45:30 -04:00
parent cae6118e1d
commit fd51fcac51

View File

@ -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):