refactor in preparation for #11
This commit is contained in:
parent
9b32db482a
commit
be4cbdb8cb
86
jsvn
86
jsvn
@ -12,6 +12,7 @@ import time
|
|||||||
from subprocess import *
|
from subprocess import *
|
||||||
import traceback
|
import traceback
|
||||||
import datetime
|
import datetime
|
||||||
|
import types
|
||||||
|
|
||||||
STATUS_LINE_REGEX = r'[ACDIMRX?!~ ][CM ][L ][+ ][SX ][KOTB ]..(.+)'
|
STATUS_LINE_REGEX = r'[ACDIMRX?!~ ][CM ][L ][+ ][SX ][KOTB ]..(.+)'
|
||||||
|
|
||||||
@ -109,17 +110,6 @@ def get_config(svn):
|
|||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def apply_aliases(config, argv):
|
|
||||||
if not argv[0] in config['aliases']:
|
|
||||||
return argv
|
|
||||||
alias = config['aliases'][argv[0]]
|
|
||||||
if type(alias) == str:
|
|
||||||
return [alias] + argv[1:]
|
|
||||||
elif type(alias) == list:
|
|
||||||
return alias + argv[1:]
|
|
||||||
sys.stderr.write('Unsupported type for alias "%s"\n' % alias)
|
|
||||||
return argv
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Utility Functions #
|
# Utility Functions #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
@ -1033,23 +1023,38 @@ def url(argv, svn, out):
|
|||||||
###########################################################################
|
###########################################################################
|
||||||
# Main #
|
# Main #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
def main(argv):
|
def do_cmd(argv, realsvn, config, expand=True):
|
||||||
global using_color
|
global using_color
|
||||||
|
|
||||||
realsvn = find_in_path('svn')
|
if len(argv) == 0:
|
||||||
config = get_config(realsvn)
|
Popen([realsvn]).wait()
|
||||||
if config['svn']:
|
return
|
||||||
realsvn = config['svn']
|
|
||||||
|
if expand and (argv[0] in config['aliases']):
|
||||||
|
# expand aliases
|
||||||
|
orig_subcommand = argv[0]
|
||||||
|
alias = config['aliases'][argv[0]]
|
||||||
|
if hasattr(alias, '__call__'):
|
||||||
|
# alias is a python function, call it
|
||||||
|
alias(argv)
|
||||||
|
return
|
||||||
|
elif type(alias) == types.StringType:
|
||||||
|
argv = [alias] + argv[1:]
|
||||||
|
elif type(alias) == types.ListType:
|
||||||
|
argv = alias + argv[1:]
|
||||||
|
else:
|
||||||
|
sys.stderr.write('Unsupported type for alias "%s"\n' % alias)
|
||||||
|
|
||||||
|
# after expanding the alias, check if it is an external
|
||||||
|
# command to launch
|
||||||
|
if argv[0].startswith('!'):
|
||||||
|
# execute an external program
|
||||||
|
argv[0] = argv[0][1:] # strip leading '!'
|
||||||
|
argv = [argv[0], orig_subcommand] + argv[1:]
|
||||||
|
Popen(argv, shell=True).wait()
|
||||||
|
return
|
||||||
|
|
||||||
out = sys.stdout
|
out = sys.stdout
|
||||||
orig_subcommand = argv[0] if len(argv) > 0 else ''
|
|
||||||
if len(argv) > 0:
|
|
||||||
argv = apply_aliases(config, argv)
|
|
||||||
if len(argv) > 0 and argv[0].startswith('!'):
|
|
||||||
# execute an external program
|
|
||||||
argv[0] = argv[0][1:] # strip leading '!'
|
|
||||||
argv = [argv[0], orig_subcommand] + argv[1:]
|
|
||||||
Popen(argv, shell=True).wait()
|
|
||||||
return 0
|
|
||||||
using_pager = False
|
using_pager = False
|
||||||
using_color = sys.stdout.isatty() and config['use_color']
|
using_color = sys.stdout.isatty() and config['use_color']
|
||||||
if sys.stdout.isatty() and config['use_pager']:
|
if sys.stdout.isatty() and config['use_pager']:
|
||||||
@ -1091,22 +1096,31 @@ def main(argv):
|
|||||||
'stash': stash,
|
'stash': stash,
|
||||||
}
|
}
|
||||||
|
|
||||||
do_normal_exec = True
|
do_native_exec = True
|
||||||
if len(argv) >= 1:
|
if argv[0] in handlers:
|
||||||
if argv[0] in handlers:
|
r = handlers[argv[0]](argv, realsvn, out)
|
||||||
r = handlers[argv[0]](argv, realsvn, out)
|
if r == RET_OK or r == RET_ERR:
|
||||||
if r == RET_OK or r == RET_ERR:
|
do_native_exec = False
|
||||||
do_normal_exec = False
|
elif argv[0].startswith('__'):
|
||||||
elif argv[0].startswith('__'):
|
# allow double-underscore commands to execute the native
|
||||||
# allow double-underscore commands to execute the native
|
# subversion command (e.g. "__st")
|
||||||
# subversion command (e.g. "__st")
|
argv[0] = argv[0][2:]
|
||||||
argv[0] = argv[0][2:]
|
|
||||||
|
|
||||||
if do_normal_exec:
|
if do_native_exec:
|
||||||
Popen([realsvn] + argv, stdout=out).wait()
|
Popen([realsvn] + argv, stdout=out).wait()
|
||||||
|
|
||||||
if using_pager:
|
if using_pager:
|
||||||
out.close()
|
out.close()
|
||||||
pager_proc.wait()
|
pager_proc.wait()
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
realsvn = find_in_path('svn')
|
||||||
|
config = get_config(realsvn)
|
||||||
|
if config['svn']:
|
||||||
|
realsvn = config['svn']
|
||||||
|
|
||||||
|
do_cmd(argv, realsvn, config)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user