1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-13 17:16:23 +01:00

- 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 <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
This commit is contained in:
Marcus Hüwe 2008-01-07 14:54:31 +00:00
parent 53e1640b1e
commit 5306a78503
3 changed files with 56 additions and 34 deletions

View File

@ -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 <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'

View File

@ -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 <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:

View File

@ -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):