diff --git a/NEWS b/NEWS index b4e32c27..62dc486a 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ - add "osc build --root" option to allow to specify build root directory - add "osc build --release" option to allow to specify a package release number - added osc mv command which can rename file and leave them under version control + - added new commands "dependson" and "whatdependson" to find out which packages get + triggered before checkin/request accept. - 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 3066a50e..975450ec 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2737,6 +2737,80 @@ Please submit there instead, or use --nodevelproject to force direct submission. print_buildlog(conf.config['apiurl'], *args) + # 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') + def do_dependson(self, subcmd, opts, *args): + """${cmd_name}: Show the build dependencies + + The command dependson and whatdependson can be used to find out what + will be triggered when a certain package changes. + This is no guarantee, since the new build might have changed dependencies. + + dependson shows the build dependencies inside of a project, valid for a + given repository and architecture. + NOTE: to see all binary packages, which can trigger a build you need to + refer the buildinfo, since this command shows only the dependencies + inside of a project. + + The arguments REPOSITORY and ARCH can be taken from the first two columns + of the 'osc repos' output. + + usage in package or project directory: + osc dependson REPOSITORY ARCH + osc whatdependson REPOSITORY ARCH + + usage: + osc dependson PROJECT [PACKAGE] REPOSITORY ARCH + osc whatdependson PROJECT [PACKAGE] REPOSITORY ARCH + + ${cmd_option_list} + """ + wd = os.curdir + args = slash_split(args) + project = packages = repository = arch = reverse = None + + if ( args is None or len(args) < 2) and (is_package_dir('.') or is_project_dir('.')): + self.print_repos() + + if len(args) > 5: + raise oscerr.WrongArgs('Too many arguments.') + + if len(args) < 3: # 2 + if is_package_dir('.'): + packages = [store_read_package(wd)] + elif not is_project_dir('.'): + raise oscerr.WrongArgs('Project and package is not specified.') + project = store_read_project(wd) + apiurl = store_read_apiurl(wd) + repository = args[0] + arch = args[1] + + if len(args) == 3: + apiurl = conf.config['apiurl'] + project = args[0] + repository = args[1] + arch = args[2] + + if len(args) == 4: + apiurl = conf.config['apiurl'] + project = args[0] + packages = [args[1]] + repository = args[2] + arch = args[3] + + if subcmd == 'whatdependson': + reverse = 1 + + xml = get_dependson(apiurl, project, repository, arch, packages, reverse) + + tree = ET.fromstring(xml) + for package in tree.findall('package'): + print package.get('name'), ":" + for dep in package.findall('pkgdep'): + print " ", dep.text + + @cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append', help='Add this package when computing the buildinfo') def do_buildinfo(self, subcmd, opts, *args): diff --git a/osc/core.py b/osc/core.py index e38dd5e7..a6b289ad 100755 --- a/osc/core.py +++ b/osc/core.py @@ -3518,6 +3518,21 @@ def print_buildlog(apiurl, prj, package, repository, arch, offset = 0): if start_offset == offset: break +def get_dependson(apiurl, project, repository, arch, packages=None, reverse=None): + query = [] + if packages: + for i in packages: + query.append('package=%s' % quote_plus(i)) + + if reverse: + query.append('view=revpkgnames') + else: + query.append('view=pkgnames') + + u = makeurl(apiurl, ['build', project, repository, arch, '_builddepinfo'], query=query) + f = http_GET(u) + return f.read() + def get_buildinfo(apiurl, prj, package, repository, arch, specfile=None, addlist=None): query = [] if addlist: