Skip to content

Commit

Permalink
Fixed to add tabs, not spaces to the git info
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Prozesky committed Feb 10, 2016
1 parent 69e81f5 commit d49477e
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions xps_library/get_git_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
help='the file to which to append info')
parser.add_argument('--fpgstring', dest='fpgstring',
action='store_true', default=False,
help='return the result as linesof fpg meta')
help='return the result as lines of fpg meta')
args = parser.parse_args()


Expand Down Expand Up @@ -80,73 +80,73 @@ def get_status(file_or_dir):
else:
return 'unmodified'

if args.target or args.fpgstring:

def get_config(file_or_dir):
"""
Get the git config for a file or dir
:param file_or_dir:
:return: str: modified or unmodified
"""
if os.path.isdir(file_or_dir):
dirname = file_or_dir
else:
dirname = os.path.dirname(file_or_dir)
p = subprocess.Popen('git -C %s config -l' % dirname,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
(output, err) = p.communicate()
if err != '':
raise GitInfoError('%s: error running git config:\n\t%s' %
(file_or_dir, err))
outlist = output.split('\n')
output = {}
for line in outlist:
if line.strip(''):
_line = line.split('=')
output[_line[0]] = _line[1]
return output
def get_config(file_or_dir):
"""
Get the git config for a file or dir
:param file_or_dir:
:return: str: modified or unmodified
"""
if os.path.isdir(file_or_dir):
dirname = file_or_dir
else:
dirname = os.path.dirname(file_or_dir)
p = subprocess.Popen('git -C %s config -l' % dirname,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
(output, err) = p.communicate()
if err != '':
raise GitInfoError('%s: error running git config:\n\t%s' %
(file_or_dir, err))
outlist = output.split('\n')
output = {}
for line in outlist:
if line.strip(''):
_line = line.split('=')
output[_line[0]] = _line[1]
return output

if args.target:
try:
fptr = open(args.target, 'a')
except IOError:
import sys
sys.exit(-2)
_fname = args.file_dir.replace(' ', '\\_')
_prefix = '?meta 77777_git rcs %s' % _fname
try:
githash = get_commit_hash(args.file_dir)
gitstat = get_status(args.file_dir)
gitconfig = get_config(args.file_dir)
fptr.write('%s git_info_found 1\n' % _prefix)
fptr.write('%s commit_hash %s\n' % (_prefix, githash))
fptr.write('%s status %s\n' % (_prefix, gitstat))
for k in gitconfig:
param_str = k.replace(' ', '\\_')
value_str = gitconfig[k].replace(' ', '\\_')
fptr.write('%s %s %s\n' % (_prefix, param_str, value_str))
except:
fptr.write('%s git_info_found 0\n' % _prefix)
fptr.close()
elif args.fpgstring:
_fname = args.file_dir.replace(' ', '\\_')
_prefix = '?meta 77777_git rcs %s' % _fname
fpgstring = ''
try:
githash = get_commit_hash(args.file_dir)
gitstat = get_status(args.file_dir)
gitconfig = get_config(args.file_dir)
fpgstring += '%s git_info_found 1\n' % _prefix
fpgstring += '%s commit_hash %s\n' % (_prefix, githash)
fpgstring += '%s status %s\n' % (_prefix, gitstat)
for k in gitconfig:
param_str = k.replace(' ', '\\_')
value_str = gitconfig[k].replace(' ', '\\_')
fpgstring += '%s %s %s\n' % (_prefix, param_str, value_str)
except:
fpgstring += '%s git_info_found 0\n' % _prefix
print fpgstring,
def _info_to_lines(file_or_dir):
gitlines = []
try:
ghash = get_commit_hash(file_or_dir)
gstat = get_status(file_or_dir)
gconfig = get_config(file_or_dir)
gitlines.append('git_info_found\t1\n')
gitlines.append('commit_hash\t%s\n' % ghash)
gitlines.append('status\t%s\n' % gstat)
for key in gconfig:
param_str = key.replace(' ', '\\_')
value_str = gconfig[key].replace(' ', '\\_')
gitlines.append('%s\t%s\n' % (param_str, value_str))
except Exception as e:
gitlines.append('git_info_found\t0\n')
raise e
_fname = file_or_dir.replace(' ', '\\_')
prefix = '?meta 77777_git\trcs\t%s' % _fname
for ctr in range(len(gitlines)):
gitlines[ctr] = '%s\t%s' % (prefix, gitlines[ctr])
return gitlines

# get the info in a list
lines = _info_to_lines(args.file_dir)

if args.target:
try:
fptr = open(args.target, 'a')
except IOError:
import sys
sys.exit(-2)
for line in lines:
fptr.write(line)
fptr.close()
elif args.fpgstring:
fpgstring = ''
for line in lines:
fpgstring += line
print fpgstring,
else:
if not os.path.exists(args.file_dir):
print 'ERROR-no_such_file'
Expand Down

0 comments on commit d49477e

Please sign in to comment.