add get_git_svn_revision and fall back to it
Now gramps developers using git need not be ashamed of their ``gramps --version'' output :) svn: r23118
This commit is contained in:
parent
7518fc5d2a
commit
5a7e4bd2c6
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
cuni = unicode
|
cuni = unicode
|
||||||
@ -30,10 +31,12 @@ else:
|
|||||||
return s.decode("utf-8", errors = 'replace')
|
return s.decode("utf-8", errors = 'replace')
|
||||||
cuni = to_utf8
|
cuni = to_utf8
|
||||||
|
|
||||||
def get_svn_revision(path=""):
|
def _get_svn_revision(path, command, stdout_to_rev):
|
||||||
stdout = ""
|
stdout = ""
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen("svnversion -n \"%s\"" % path, shell=True,
|
p = subprocess.Popen(
|
||||||
|
"{} \"{}\"".format(command, path),
|
||||||
|
shell=True,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
(stdout, stderr) = p.communicate()
|
(stdout, stderr) = p.communicate()
|
||||||
except:
|
except:
|
||||||
@ -41,10 +44,19 @@ def get_svn_revision(path=""):
|
|||||||
# subprocess worked
|
# subprocess worked
|
||||||
if stdout and len(stdout) > 0: # has output
|
if stdout and len(stdout) > 0: # has output
|
||||||
stdout = cuni(stdout) # get a proper string
|
stdout = cuni(stdout) # get a proper string
|
||||||
if stdout[0].isdigit():
|
rev = stdout_to_rev(stdout)
|
||||||
return "-r" + stdout
|
return "-r" + rev if rev else ""
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
else: # no output from svnversion
|
else: # no output from svnversion
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def get_svn_revision(path=""):
|
||||||
|
return _get_svn_revision(path, "svnversion -n",
|
||||||
|
lambda stdout: stdout if stdout[0].isdigit() else ""
|
||||||
|
) or get_git_svn_revision(path)
|
||||||
|
|
||||||
|
def get_git_svn_revision(path=""):
|
||||||
|
def stdout_to_rev(stdout):
|
||||||
|
m = re.search("Revision:\s+(\d+)", stdout, re.MULTILINE)
|
||||||
|
return m.group(1) if m else ""
|
||||||
|
|
||||||
|
return _get_svn_revision(path, "git svn info", stdout_to_rev)
|
||||||
|
Loading…
Reference in New Issue
Block a user