add jsvn Subversion wrapper and remove svn aliases
This commit is contained in:
1 parent
da46bb78f8
commit
f6781ebc8b
2 files changed
+84
-39
No files matched your search
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Josh's SVN wrapper script
|
||||
# Recommend putting in path as 'jsvn' or something other than 'svn' and
|
||||
# making an alias svn='jsvn'
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
from subprocess import *
|
||||
|
||||
PATH = os.environ['PATH'].split(os.pathsep)
|
||||
|
||||
def findInPath(cmd):
|
||||
for p in PATH:
|
||||
full_path = os.path.join(p, cmd)
|
||||
if os.path.exists(full_path):
|
||||
return full_path
|
||||
return ''
|
||||
|
||||
def getSVNURL(svn):
|
||||
for line in Popen([svn, 'info'], stdout=PIPE).communicate()[0].split('\n'):
|
||||
m = re.match('^URL:\s*(.*?)\s*$', line)
|
||||
if m is not None:
|
||||
return m.group(1)
|
||||
return ''
|
||||
|
||||
def getSVNRoot(svn):
|
||||
url = getSVNURL(svn)
|
||||
parts = url.split('/')
|
||||
for i in range(0, len(parts)):
|
||||
if parts[i] in ('trunk', 'tags', 'branches'):
|
||||
return '/'.join(parts[:i-1])
|
||||
return ''
|
||||
|
||||
def getSVNTopLevel(svn):
|
||||
url = getSVNURL(svn)
|
||||
parts = url.split('/')
|
||||
for i in range(0, len(parts)):
|
||||
if parts[i] == 'trunk' or i > 0 and parts[i-1] in ('tags', 'branches'):
|
||||
return '/'.join(parts[:i+1])
|
||||
return ''
|
||||
|
||||
def main(argv):
|
||||
realsvn = findInPath('svn')
|
||||
colorsvn = findInPath('colorsvn')
|
||||
colordiff = findInPath('colordiff')
|
||||
|
||||
if realsvn == '':
|
||||
sys.stderr.write("Error: 'svn' not found in path\n")
|
||||
return 1
|
||||
|
||||
if len(argv) >= 1 and argv[0] == "branch":
|
||||
if len(argv) < 2:
|
||||
sys.stderr.write("Must supply branch name\n")
|
||||
return 2
|
||||
branch_name = argv[1]
|
||||
origin = getSVNTopLevel(realsvn)
|
||||
root = getSVNRoot(realsvn)
|
||||
if origin == '' or root == '':
|
||||
sys.stderr.write("Could not determine origin/root URL\n")
|
||||
return 1
|
||||
comment = "Created '%s' branch" % branch_name
|
||||
branch_path = root + '/branches/' + branch_name
|
||||
Popen([realsvn, 'copy', origin, branch_path, '-m', comment]).wait()
|
||||
return 0
|
||||
|
||||
if len(argv) >= 1 and argv[0] == "diff" and colordiff != '':
|
||||
diff_out = Popen([realsvn] + argv, stdout=PIPE).stdout
|
||||
Popen([colordiff], stdin=diff_out).wait()
|
||||
return 0
|
||||
|
||||
if colorsvn != '':
|
||||
Popen([colorsvn] + argv).wait()
|
||||
return 0
|
||||
|
||||
Popen([realsvn] + argv).wait()
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
Reference in new issue
Block a user