buildhistory-diff: improve command-line handling
Improve command-line argument handling of buildhistory-diff to make it easier to use. * Default buildhistory directory to buildhistory/ under the current directory and require an option to set it (since most users will likely run buildhistory-diff from the build directory and keep BUILDHISTORY_DIR at its default location) * Default from-revision to "build-minus-1" to get the difference from the previous build with no arguments * Allow from/to revisions to be specified by from..to (since git accepts this form). (From OE-Core rev: 5e2be70e89820ffc74208d225fe4414fe5182050) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
c5d2e9caca
commit
2a9d9b6a99
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import optparse
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
# Ensure PythonGit is installed (buildhistory_analysis needs it)
|
# Ensure PythonGit is installed (buildhistory_analysis needs it)
|
||||||
|
@ -17,14 +18,30 @@ except ImportError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
parser = optparse.OptionParser(
|
||||||
|
description = "Reports significant differences in the buildhistory repository.",
|
||||||
|
usage = """
|
||||||
|
%prog [options] [from-revision [to-revision]]
|
||||||
|
(if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""")
|
||||||
|
|
||||||
|
parser.add_option("-p", "--buildhistory-dir",
|
||||||
|
help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
|
||||||
|
action="store", dest="buildhistory_dir", default='buildhistory/')
|
||||||
|
|
||||||
|
options, args = parser.parse_args(sys.argv)
|
||||||
|
|
||||||
|
if len(args) > 3:
|
||||||
|
sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if LooseVersion(git.__version__) < '0.3.1':
|
if LooseVersion(git.__version__) < '0.3.1':
|
||||||
sys.stderr.write("Version of GitPython is too old, please install GitPython (python-git) 0.3.1 or later in order to use this script\n")
|
sys.stderr.write("Version of GitPython is too old, please install GitPython (python-git) 0.3.1 or later in order to use this script\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if len(sys.argv) < 3 or '--help' in sys.argv:
|
if not os.path.exists(options.buildhistory_dir):
|
||||||
print("Report significant differences in the buildhistory repository")
|
sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
|
||||||
print("Syntax: %s <buildhistory-path> <since-revision> [to-revision]" % os.path.basename(sys.argv[0]))
|
parser.print_help()
|
||||||
print("If to-revision is not specified, it defaults to HEAD")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Set path to OE lib dir so we can import the buildhistory_analysis module
|
# Set path to OE lib dir so we can import the buildhistory_analysis module
|
||||||
|
@ -47,21 +64,28 @@ def main():
|
||||||
sys.path[0:0] = [newpath, bitbakepath + '/lib']
|
sys.path[0:0] = [newpath, bitbakepath + '/lib']
|
||||||
import oe.buildhistory_analysis
|
import oe.buildhistory_analysis
|
||||||
|
|
||||||
buildhistory_dir = sys.argv[1]
|
fromrev = 'build-minus-1'
|
||||||
if not os.path.exists(buildhistory_dir):
|
torev = 'HEAD'
|
||||||
sys.stderr.write('Specified buildhistory directory "%s" does not exist\n' % buildhistory_dir)
|
if len(args) > 1:
|
||||||
sys.exit(1)
|
if len(args) == 2 and '..' in args[1]:
|
||||||
|
revs = args[1].split('..')
|
||||||
if len(sys.argv) > 3:
|
fromrev = revs[0]
|
||||||
torev = sys.argv[3]
|
if revs[1]:
|
||||||
else:
|
torev = revs[1]
|
||||||
torev = 'HEAD'
|
else:
|
||||||
|
fromrev = args[1]
|
||||||
|
if len(args) > 2:
|
||||||
|
torev = args[2]
|
||||||
|
|
||||||
import gitdb
|
import gitdb
|
||||||
try:
|
try:
|
||||||
changes = oe.buildhistory_analysis.process_changes(buildhistory_dir, sys.argv[2], torev)
|
changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev)
|
||||||
except gitdb.exc.BadObject as e:
|
except gitdb.exc.BadObject as e:
|
||||||
sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
|
if len(args) == 1:
|
||||||
|
sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
|
||||||
|
parser.print_help()
|
||||||
|
else:
|
||||||
|
sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for chg in changes:
|
for chg in changes:
|
||||||
|
|
Loading…
Reference in New Issue