@ -832,11 +832,10 @@ def default(value, function):
return function ( )
return function ( )
return value
return value
def _gitinfo ( ) :
def _gitrepoinfo ( repo_path ) :
''' returns a string containing git branch, commit id and commit date '''
''' returns a string containing git branch, commit id and commit date '''
result = None
result = None
repo_path = os . path . join ( os . path . dirname ( __file__ ) , ' .. ' , ' .. ' , ' .. ' , ' .git ' )
if os . path . exists ( repo_path ) :
if os . path . exists ( repo_path ) :
# Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
# Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
if os . path . isfile ( repo_path ) :
if os . path . isfile ( repo_path ) :
@ -857,6 +856,12 @@ def _gitinfo():
f = open ( branch_path )
f = open ( branch_path )
commit = f . readline ( ) [ : 10 ]
commit = f . readline ( ) [ : 10 ]
f . close ( )
f . close ( )
else :
# detached HEAD
commit = branch [ : 10 ]
branch = ' detached HEAD '
branch_path = os . path . join ( repo_path , " HEAD " )
date = time . localtime ( os . stat ( branch_path ) . st_mtime )
date = time . localtime ( os . stat ( branch_path ) . st_mtime )
if time . daylight == 0 :
if time . daylight == 0 :
offset = time . timezone
offset = time . timezone
@ -868,6 +873,22 @@ def _gitinfo():
result = ' '
result = ' '
return result
return result
def _gitinfo ( ) :
basedir = os . path . join ( os . path . dirname ( __file__ ) , ' .. ' , ' .. ' , ' .. ' )
repo_path = os . path . join ( basedir , ' .git ' )
result = _gitrepoinfo ( repo_path )
submodules = os . path . join ( basedir , ' .gitmodules ' )
f = open ( submodules )
for line in f :
tokens = line . strip ( ) . split ( ' ' )
if tokens [ 0 ] == ' path ' :
repo_path = tokens [ 2 ]
result + = " \n {0} : {1} " . format ( repo_path , _gitrepoinfo ( os . path . join ( basedir , repo_path , ' .git ' ) ) )
f . close ( )
return result
def version ( prog ) :
def version ( prog ) :
result = " {0} {1} " . format ( prog , __version__ )
result = " {0} {1} " . format ( prog , __version__ )
gitinfo = _gitinfo ( )
gitinfo = _gitinfo ( )