From 5306a785033ef1fcbfa49034502deefe2208025b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20H=C3=BCwe?= Date: Mon, 7 Jan 2008 14:54:31 +0000 Subject: [PATCH] - added two new options to osc build: * --local-package: use this option if you're trying to build a package which doesn't exist on the server * --alternative-project : use this option to specify an alternative project if the current project doesn't exist on the server, e.g.: osc build [OPTS] --alternative-project openSUSE:10.3 standard i586 BUILD_DESCR - some other minor cleanups in build.py - get_repos_of_project() is now a generator function --- osc/build.py | 56 +++++++++++++++++++++++++++++++--------------- osc/commandline.py | 30 ++++++++++++++----------- osc/core.py | 4 +--- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/osc/build.py b/osc/build.py index 51649886..b5e9d521 100644 --- a/osc/build.py +++ b/osc/build.py @@ -11,7 +11,7 @@ import os import sys from tempfile import NamedTemporaryFile from osc.fetch import * -from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package +from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig import osc.conf try: from xml.etree import cElementTree as ET @@ -221,6 +221,13 @@ def main(opts, argv): buildargs.append('--changelog') buildargs = ' '.join(buildargs) + prj = store_read_project(os.curdir) + pac = store_read_package(os.curdir) + if opts.local_package: + pac = '_repository' + if opts.alternative_project: + prj = opts.alternative_project + pac = '_repository' if not os.path.exists(spec): print >>sys.stderr, 'Error: specfile \'%s\' does not exist.' % spec @@ -244,16 +251,29 @@ def main(opts, argv): bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = '/tmp') try: bi_text = ''.join(get_buildinfo(store_read_apiurl(os.curdir), - store_read_project(os.curdir), - store_read_package(os.curdir), + prj, + pac, repo, arch, specfile=open(spec).read(), addlist=opts.extra_pkgs)) - - except: - print >>sys.stderr, 'wrong repo/arch?' - sys.exit(1) + except urllib2.HTTPError, e: + if e.code == 404: + # check what caused the 404 + if meta_exists(metatype='prj', path_args=(quote_plus(prj), ), + template_args=None, create_new=False): + if meta_exists(metatype='pkg', path_args=(quote_plus(prj), quote_plus(pac)), + template_args=None, create_new=False) or pac == '_repository': + print >>sys.stderr, 'wrong repo/arch?' + sys.exit(1) + else: + print >>sys.stderr, 'The package \'%s\' does not exists - please ' \ + 'rerun with \'--local-package\'' % pac + sys.exit(1) + else: + print >>sys.stderr, 'The project \'%s\' does not exists - please ' \ + 'rerun with \'--alternative-project \'' % prj + sys.exit(1) bi_file.write(bi_text) bi_file.flush() @@ -268,15 +288,15 @@ def main(opts, argv): for name, path in prefer_pkgs.iteritems(): if bi.has_dep(name): - # We remove a preferred package from the buildinfo, so that the - # fetcher doesn't take care about them. - # Instead, we put it in a list which is appended to the rpmlist later. - # At the same time, this will make sure that these packages are - # not verified. - bi.remove_dep(name) - rpmlist_prefers.append((name, path)) - print ' - %s (%s)' % (name, path) - continue + # We remove a preferred package from the buildinfo, so that the + # fetcher doesn't take care about them. + # Instead, we put it in a list which is appended to the rpmlist later. + # At the same time, this will make sure that these packages are + # not verified. + bi.remove_dep(name) + rpmlist_prefers.append((name, path)) + print ' - %s (%s)' % (name, path) + continue print 'Updating cache of required packages' fetcher = Fetcher(cachedir = config['packagecachedir'], @@ -312,8 +332,8 @@ def main(opts, argv): print 'Getting buildconfig from server' bc_file = NamedTemporaryFile(prefix='buildconfig.', dir = '/tmp') - rc = os.system('osc buildconfig %s %s > %s' % (repo, arch, bc_file.name)) - if rc: sys.exit(rc) + bc_file.write(get_buildconfig(store_read_apiurl(os.curdir), prj, pac, repo, arch)) + bc_file.flush() print 'Running build' diff --git a/osc/commandline.py b/osc/commandline.py index d24d6dd8..e79068d6 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1304,7 +1304,6 @@ class Osc(cmdln.Cmdln): pacs = findpacs(args) for p in pacs: - for platform in get_repos_of_project(p.apiurl, p.prjname): print platform @@ -1325,6 +1324,10 @@ class Osc(cmdln.Cmdln): help='Run build as root. The default is to build as ' 'unprivileged user. Note that a line "# norootforbuild" ' 'in the spec file will invalidate this option.') + @cmdln.option('', '--local-package', action='store_true', + help='build a package which does not exist on the server') + @cmdln.option('', '--alternative-project', metavar='PROJECT', + help='specify the build target project') def do_build(self, subcmd, opts, *args): """${cmd_name}: Build a package on your local machine @@ -1343,6 +1346,13 @@ class Osc(cmdln.Cmdln): build-root again, removing unneeded packages and add missing ones. This is usually the fastest option. + If the package doesn't exist on the server please use the --local-package + option. + If the project of the package doesn't exist on the server please use the + --alternative-project option: + Example: + osc build [OPTS] --alternative-project openSUSE:10.3 standard i586 BUILD_DESCR + usage: osc build [OPTS] PLATFORM ARCH BUILD_DESCR ${cmd_option_list} @@ -1387,18 +1397,12 @@ class Osc(cmdln.Cmdln): print 'you have to choose a repo to build on' print 'possible repositories on this machine are:' print - # here, we can't simply use self.do_repos(None, None), because it doesn't - # _return_ the stuff, but prints right to stdout... in the future, - # it would be good to make all commands return their output, but - # better make them generators then - (i, o) = os.popen4(['osc', 'repos']) - i.close() - - for line in o.readlines(): - a = line.split()[1] # arch - if a == osc.build.hostarch or \ - a in osc.build.can_also_build.get(osc.build.hostarch, []): - print line.strip() + for platform in get_repos_of_project(store_read_apiurl(os.curdir), + store_read_project(os.curdir)): + arch = platform.split()[1] # arch + if arch == osc.build.hostarch or \ + arch in osc.build.can_also_build.get(osc.build.hostarch, []): + print platform.strip() return 1 if opts.prefer_pkgs: diff --git a/osc/core.py b/osc/core.py index 1c502993..a31fe861 100755 --- a/osc/core.py +++ b/osc/core.py @@ -1673,11 +1673,9 @@ def get_repos_of_project(apiurl, prj): tree = ET.parse(StringIO(''.join(f))) repo_line_templ = '%-15s %-10s' - r = [] for node in tree.findall('repository'): for node2 in node.findall('arch'): - r.append(repo_line_templ % (node.get('name'), node2.text)) - return r + yield repo_line_templ % (node.get('name'), node2.text) def get_binarylist(apiurl, prj, repo, arch, package=None):