diff --git a/NEWS b/NEWS index db7149c3..c0cde63c 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ - added new commands "dependson" and "whatdependson" to find out which packages get triggered before checkin/request accept. - add new "osc build --linksource" option, speeds up esp. image building a lot + - add "osc triggerreason" command to show detail reason, why a package got triggered for build - Incompatible changes: * osc se now prints Project Package, instead of Package Project for easier copy&paste. diff --git a/osc/commandline.py b/osc/commandline.py index 208f9ae8..16c53e8f 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2737,6 +2737,62 @@ Please submit there instead, or use --nodevelproject to force direct submission. print_buildlog(conf.config['apiurl'], *args) + @cmdln.alias('tr') + def do_triggerreason(self, subcmd, opts, *args): + """${cmd_name}: Show reason why a package got triggered to build + + The server decides when a package needs to get rebuild, this command + shows the detailed reason for a package. A brief reason is also stored + in the jobhistory, which can be accessed via "osc jobhistory". + + Trigger reasons might be: + - new build (never build yet or rebuild manually forced) + - source change (eg. on updating sources) + - meta change (packages which are used for building have changed) + - rebuild count sync (In case that it is configured to sync release numbers) + + usage in package or project directory: + osc reason REPOSITORY ARCH + osc reason PROJECT PACKAGE REPOSITORY ARCH + + ${cmd_option_list} + """ + wd = os.curdir + args = slash_split(args) + project = package = repository = arch = None + + if ( args is None or len(args) < 2): + self.print_repos() + + if len(args) == 2: # 2 + if is_package_dir('.'): + package = store_read_package(wd) + else: + raise oscerr.WrongArgs('package is not specified.') + project = store_read_project(wd) + apiurl = store_read_apiurl(wd) + repository = args[0] + arch = args[1] + elif len(args) == 4: + apiurl = conf.config['apiurl'] + project = args[0] + package = args[1] + repository = args[2] + arch = args[3] + else: + raise oscerr.WrongArgs('Too many arguments.') + + print apiurl, project, package, repository, arch + xml = show_package_trigger_reason(apiurl, project, package, repository, arch) + tree = ET.fromstring(xml) + reason = tree.find('explain').text + print reason + if reason == "meta change": + print "changed keys:" + for package in tree.findall('packagechange'): + print " ", package.get('change'), package.get('key') + + # FIXME: the new osc syntax should allow to specify multiple packages # FIXME: the command should optionally use buildinfo data to show all dependencies @cmdln.alias('whatdependson') diff --git a/osc/core.py b/osc/core.py index a6b289ad..e05fb0d5 100644 --- a/osc/core.py +++ b/osc/core.py @@ -2039,6 +2039,16 @@ def show_project_conf(apiurl, prj): return f.readlines() +def show_package_trigger_reason(apiurl, prj, pac, repo, arch): + url = makeurl(apiurl, ['build', prj, repo, arch, pac, '_reason']) + try: + f = http_GET(url) + return f.read() + except urllib2.HTTPError, e: + e.osc_msg = 'Error getting trigger reason for project \'%s\' package \'%s\'' % (prj, pac) + raise + + def show_package_meta(apiurl, prj, pac): url = makeurl(apiurl, ['source', prj, pac, '_meta']) try: