Skip to content
Permalink
Browse files

change the version number returned by pygit_hlper

  • Loading branch information...
sdpython committed Feb 10, 2014
1 parent c4ce311 commit 5053b74de97b28144598d4233305f9c92aa15019
@@ -34,7 +34,7 @@ def SetGuessedType(self, location):
if not svn :
git = GIT.IsRepo(location, commandline = self.commandline)
if not git :
raise Exception("unable to guess source repository type for location " + location + "({0})".format(self.commandline))
raise Exception("unable to guess source repository type for location " + location + " - (cmd={0})".format(self.commandline))
else :
self.module = GIT
else :
@@ -3,7 +3,7 @@
@brief Uses git to get version number.
"""

import os,sys
import os,sys,datetime
import xml.etree.ElementTree as ET

from ..flog import fLOG, run_cmd
@@ -128,6 +128,8 @@ def get_repo_log (path = None, file_detail = False, commandline = True) :
@code
https://github.com/sdpython/pyquickhelper/commit/8d5351d1edd4a8997f358be39da80c72b06c2272
@endcode
More: `git pretty format <http://opensource.apple.com/source/Git/Git-19/src/git-htmldocs/pretty-formats.txt>`_
"""
if file_detail :
raise NotImplementedError()
@@ -179,12 +181,15 @@ def get_repo_log (path = None, file_detail = False, commandline = True) :
res.append(row)
return res

def get_repo_version (path = None, commandline = True) :
def get_repo_version (path = None, commandline = True, usedate = True) :
"""
get the latest check in number for a specific path
Get the latest check for a specific path or version number based on the date (is usedate is True)
If usedate is False, it returns a mini hash (a string then)
@param path path to look
@param commandline if True, use the command line to get the version number, otherwise it uses pysvn
@return integer (check in number)
@param usedate if True, it uses the date to return a minor version number (1.1.thisone)
@return integer)
"""
if path == None :
path = os.path.normpath(os.path.abspath( os.path.join( os.path.split(__file__)[0], "..", "..", "..")))
@@ -196,9 +201,9 @@ def get_repo_version (path = None, commandline = True) :
return get_repo_version(path, True)
else :
if sys.platform.startswith("win32") :
cmd = r'"C:\Program Files (x86)\Git\bin\git" log --format="%h"' # %H for full commit hash
cmd = r'"C:\Program Files (x86)\Git\bin\git" log --format="%h---%ci"' # %H for full commit hash
else :
cmd = 'git log --format="%H"'
cmd = 'git log --format="%H---%ci"'

if path != None : cmd += " \"%s\"" % path

@@ -214,8 +219,11 @@ def get_repo_version (path = None, commandline = True) :
fLOG ("problem with file ", path, err)
raise Exception(err)
lines = out.split("\n")
lines = [ _ for _ in lines if len(_) > 0 ]
res = lines[0]
lines = [ _.split("---") for _ in lines if len(_) > 0 ]
temp = lines[0]
dt = str_to_datetime(temp[1].replace("T"," ").strip("Z "))
dt0 = datetime.datetime(dt.year, 1,1,0,0,0)
res = "%d" % (dt-dt0).days

if len(res) == 0 :
raise Exception("the command 'git help' should return something")
@@ -64,7 +64,7 @@ def repo_ls(full, commandline = True):
except Exception as e :
if "This client is too old to work with the working copy at" in str (e) or \
"No module named 'pysvn'" in str(e) :
cmd = "svn ls -r HEAD \"%s\"" % full
cmd = "svn ls -r HEAD \"%s\"" % full.replace("\\","/")
out,err = run_cmd( cmd,
wait = True,
do_not_log = True,
@@ -79,7 +79,7 @@ def repo_ls(full, commandline = True):
fLOG ("problem with file ", full, e)
raise e
else :
cmd = "svn ls -r HEAD \"%s\"" % full
cmd = "svn ls -r HEAD \"%s\"" % full.replace("\\","/")
out,err = run_cmd( cmd,
wait = True,
do_not_log = True,
@@ -166,7 +166,7 @@ def get_repo_log (path = None, file_detail = False, commandline = True) :
raise e

else :
cmd = "svn log -r HEAD:1 --xml \"%s\"" % path
cmd = "svn log -r HEAD:1 --xml \"%s\"" % path.replace("\\","/")
out,err = run_cmd( cmd,
wait = True,
do_not_log = True,
@@ -236,7 +236,7 @@ def get_repo_version (path = None, commandline = True) :
raise e
else :
cmd = "svn info -r HEAD"
if path != None : cmd += " \"%s\"" % path
if path != None : cmd += " \"%s\"" % path.replace("\\","/")
out,err = run_cmd( cmd,
wait = True,
do_not_log = True,

0 comments on commit 5053b74

Please sign in to comment.
You can’t perform that action at this time.