| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env python | 
|  | 2 |  | 
|  | 3 | # Report significant differences in the buildhistory repository since a specific revision | 
|  | 4 | # | 
|  | 5 | # Copyright (C) 2013 Intel Corporation | 
|  | 6 | # Author: Paul Eggleton <paul.eggleton@linux.intel.com> | 
|  | 7 |  | 
|  | 8 | import sys | 
|  | 9 | import os | 
|  | 10 | import optparse | 
|  | 11 | from distutils.version import LooseVersion | 
|  | 12 |  | 
|  | 13 | # Ensure PythonGit is installed (buildhistory_analysis needs it) | 
|  | 14 | try: | 
|  | 15 | import git | 
|  | 16 | except ImportError: | 
|  | 17 | print("Please install GitPython (python-git) 0.3.1 or later in order to use this script") | 
|  | 18 | sys.exit(1) | 
|  | 19 |  | 
|  | 20 | def main(): | 
|  | 21 | parser = optparse.OptionParser( | 
|  | 22 | description = "Reports significant differences in the buildhistory repository.", | 
|  | 23 | usage = """ | 
|  | 24 | %prog [options] [from-revision [to-revision]] | 
|  | 25 | (if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""") | 
|  | 26 |  | 
|  | 27 | parser.add_option("-p", "--buildhistory-dir", | 
|  | 28 | help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)", | 
|  | 29 | action="store", dest="buildhistory_dir", default='buildhistory/') | 
|  | 30 | parser.add_option("-v", "--report-version", | 
|  | 31 | help = "Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)", | 
|  | 32 | action="store_true", dest="report_ver", default=False) | 
|  | 33 | parser.add_option("-a", "--report-all", | 
|  | 34 | help = "Report all changes, not just the default significant ones", | 
|  | 35 | action="store_true", dest="report_all", default=False) | 
|  | 36 |  | 
|  | 37 | options, args = parser.parse_args(sys.argv) | 
|  | 38 |  | 
|  | 39 | if len(args) > 3: | 
|  | 40 | sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:])) | 
|  | 41 | parser.print_help() | 
|  | 42 | sys.exit(1) | 
|  | 43 |  | 
|  | 44 | if LooseVersion(git.__version__) < '0.3.1': | 
|  | 45 | 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") | 
|  | 46 | sys.exit(1) | 
|  | 47 |  | 
|  | 48 | if not os.path.exists(options.buildhistory_dir): | 
|  | 49 | sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir) | 
|  | 50 | parser.print_help() | 
|  | 51 | sys.exit(1) | 
|  | 52 |  | 
|  | 53 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) | 
|  | 54 | lib_path = scripts_path + '/lib' | 
|  | 55 | sys.path = sys.path + [lib_path] | 
|  | 56 |  | 
|  | 57 | import scriptpath | 
|  | 58 |  | 
|  | 59 | # Set path to OE lib dir so we can import the buildhistory_analysis module | 
|  | 60 | scriptpath.add_oe_lib_path() | 
|  | 61 | # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils | 
|  | 62 | bitbakepath = scriptpath.add_bitbake_lib_path() | 
|  | 63 | if not bitbakepath: | 
|  | 64 | sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n") | 
|  | 65 | sys.exit(1) | 
|  | 66 |  | 
|  | 67 | import oe.buildhistory_analysis | 
|  | 68 |  | 
|  | 69 | fromrev = 'build-minus-1' | 
|  | 70 | torev = 'HEAD' | 
|  | 71 | if len(args) > 1: | 
|  | 72 | if len(args) == 2 and '..' in args[1]: | 
|  | 73 | revs = args[1].split('..') | 
|  | 74 | fromrev = revs[0] | 
|  | 75 | if revs[1]: | 
|  | 76 | torev = revs[1] | 
|  | 77 | else: | 
|  | 78 | fromrev = args[1] | 
|  | 79 | if len(args) > 2: | 
|  | 80 | torev = args[2] | 
|  | 81 |  | 
|  | 82 | import gitdb | 
|  | 83 | try: | 
|  | 84 | changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev, options.report_all, options.report_ver) | 
|  | 85 | except gitdb.exc.BadObject as e: | 
|  | 86 | if len(args) == 1: | 
|  | 87 | sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n") | 
|  | 88 | parser.print_help() | 
|  | 89 | else: | 
|  | 90 | sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0]) | 
|  | 91 | sys.exit(1) | 
|  | 92 |  | 
|  | 93 | for chg in changes: | 
|  | 94 | print('%s' % chg) | 
|  | 95 |  | 
|  | 96 | sys.exit(0) | 
|  | 97 |  | 
|  | 98 |  | 
|  | 99 | if __name__ == "__main__": | 
|  | 100 | main() |