Make embedding git commit hash in the document an option (--tag)
Add exception handlers around git usage.
This commit is contained in:
@@ -46,7 +46,7 @@ def parse_arguments():
|
|||||||
description=textwrap.dedent('''\
|
description=textwrap.dedent('''\
|
||||||
Builds PDF files from (intermediate fo and) XML files.
|
Builds PDF files from (intermediate fo and) XML files.
|
||||||
|
|
||||||
Copyright (C) 2015-2016 Radically Open Security (Peter Mosmans)
|
Copyright (C) 2015-2017 Radically Open Security (Peter Mosmans)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -57,7 +57,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
parser.add_argument('-date', action='store',
|
parser.add_argument('-date', action='store',
|
||||||
help='the invoice date')
|
help='the invoice date')
|
||||||
parser.add_argument('-execsummary', action='store',
|
parser.add_argument('-execsummary', action='store',
|
||||||
help="""create an executive summary as well as a report (true/false).
|
help="""create an executive summary as well as a report (true/false).
|
||||||
Default: false """)
|
Default: false """)
|
||||||
parser.add_argument('--fop-config', action='store',
|
parser.add_argument('--fop-config', action='store',
|
||||||
default='/etc/docbuilder/rosfop.xconf',
|
default='/etc/docbuilder/rosfop.xconf',
|
||||||
@@ -86,6 +86,8 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
default='../target/report-latest.pdf',
|
default='../target/report-latest.pdf',
|
||||||
help="""output file name (default:
|
help="""output file name (default:
|
||||||
../target/report-latest.pdf""")
|
../target/report-latest.pdf""")
|
||||||
|
parser.add_argument('--tag', action='store_true',
|
||||||
|
help="""Modify GITREV with git commit hash""")
|
||||||
parser.add_argument('-v', '--verbose', action='store_true',
|
parser.add_argument('-v', '--verbose', action='store_true',
|
||||||
help='increase output verbosity')
|
help='increase output verbosity')
|
||||||
parser.add_argument('-w', '--warnings', action='store_true',
|
parser.add_argument('-w', '--warnings', action='store_true',
|
||||||
@@ -122,15 +124,18 @@ def change_tag(fop):
|
|||||||
Replaces GITREV in document by git commit shorttag.
|
Replaces GITREV in document by git commit shorttag.
|
||||||
"""
|
"""
|
||||||
cmd = ['git', 'log', '--pretty=format:%h', '-n', '1']
|
cmd = ['git', 'log', '--pretty=format:%h', '-n', '1']
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
try:
|
||||||
shorttag, _stderr = process.communicate()
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
if not process.returncode:
|
shorttag, _stderr = process.communicate()
|
||||||
fop_file = open(fop).read()
|
if not process.returncode:
|
||||||
if GITREV in fop_file:
|
fop_file = open(fop).read()
|
||||||
fop_file = fop_file.replace(GITREV, shorttag)
|
if GITREV in fop_file:
|
||||||
with open(fop, 'w') as new_file:
|
fop_file = fop_file.replace(GITREV, shorttag)
|
||||||
new_file.write(fop_file)
|
with open(fop, 'w') as new_file:
|
||||||
print('[+] Embedding git version information into document')
|
new_file.write(fop_file)
|
||||||
|
print('[+] Embedding git version information into document')
|
||||||
|
except OSError:
|
||||||
|
print('[-] could not execute git - is git installed ?')
|
||||||
|
|
||||||
|
|
||||||
def to_fo(options):
|
def to_fo(options):
|
||||||
@@ -154,7 +159,8 @@ def to_fo(options):
|
|||||||
print_exit('[-] Error creating fo file from XML input',
|
print_exit('[-] Error creating fo file from XML input',
|
||||||
process.returncode)
|
process.returncode)
|
||||||
else:
|
else:
|
||||||
change_tag(options['fop'])
|
if options['tag']:
|
||||||
|
change_tag(options['fop'])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user