1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-28 07:26:15 +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 import sys
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from osc.fetch import * 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 import osc.conf
try: try:
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -221,6 +221,13 @@ def main(opts, argv):
buildargs.append('--changelog') buildargs.append('--changelog')
buildargs = ' '.join(buildargs) 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): if not os.path.exists(spec):
print >>sys.stderr, 'Error: specfile \'%s\' does not exist.' % 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') bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = '/tmp')
try: try:
bi_text = ''.join(get_buildinfo(store_read_apiurl(os.curdir), bi_text = ''.join(get_buildinfo(store_read_apiurl(os.curdir),
store_read_project(os.curdir), prj,
store_read_package(os.curdir), pac,
repo, repo,
arch, arch,
specfile=open(spec).read(), specfile=open(spec).read(),
addlist=opts.extra_pkgs)) addlist=opts.extra_pkgs))
except urllib2.HTTPError, e:
except: 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?' print >>sys.stderr, 'wrong repo/arch?'
sys.exit(1) 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.write(bi_text)
bi_file.flush() bi_file.flush()
@ -312,8 +332,8 @@ def main(opts, argv):
print 'Getting buildconfig from server' print 'Getting buildconfig from server'
bc_file = NamedTemporaryFile(prefix='buildconfig.', dir = '/tmp') bc_file = NamedTemporaryFile(prefix='buildconfig.', dir = '/tmp')
rc = os.system('osc buildconfig %s %s > %s' % (repo, arch, bc_file.name)) bc_file.write(get_buildconfig(store_read_apiurl(os.curdir), prj, pac, repo, arch))
if rc: sys.exit(rc) bc_file.flush()
print 'Running build' print 'Running build'

View File

@ -1304,7 +1304,6 @@ class Osc(cmdln.Cmdln):
pacs = findpacs(args) pacs = findpacs(args)
for p in pacs: for p in pacs:
for platform in get_repos_of_project(p.apiurl, p.prjname): for platform in get_repos_of_project(p.apiurl, p.prjname):
print platform print platform
@ -1325,6 +1324,10 @@ class Osc(cmdln.Cmdln):
help='Run build as root. The default is to build as ' help='Run build as root. The default is to build as '
'unprivileged user. Note that a line "# norootforbuild" ' 'unprivileged user. Note that a line "# norootforbuild" '
'in the spec file will invalidate this option.') '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): def do_build(self, subcmd, opts, *args):
"""${cmd_name}: Build a package on your local machine """${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 build-root again, removing unneeded packages and add missing ones. This
is usually the fastest option. 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: usage:
osc build [OPTS] PLATFORM ARCH BUILD_DESCR osc build [OPTS] PLATFORM ARCH BUILD_DESCR
${cmd_option_list} ${cmd_option_list}
@ -1387,18 +1397,12 @@ class Osc(cmdln.Cmdln):
print 'you have to choose a repo to build on' print 'you have to choose a repo to build on'
print 'possible repositories on this machine are:' print 'possible repositories on this machine are:'
print print
# here, we can't simply use self.do_repos(None, None), because it doesn't for platform in get_repos_of_project(store_read_apiurl(os.curdir),
# _return_ the stuff, but prints right to stdout... in the future, store_read_project(os.curdir)):
# it would be good to make all commands return their output, but arch = platform.split()[1] # arch
# better make them generators then if arch == osc.build.hostarch or \
(i, o) = os.popen4(['osc', 'repos']) arch in osc.build.can_also_build.get(osc.build.hostarch, []):
i.close() print platform.strip()
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()
return 1 return 1
if opts.prefer_pkgs: if opts.prefer_pkgs:

View File

@ -1673,11 +1673,9 @@ def get_repos_of_project(apiurl, prj):
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
repo_line_templ = '%-15s %-10s' repo_line_templ = '%-15s %-10s'
r = []
for node in tree.findall('repository'): for node in tree.findall('repository'):
for node2 in node.findall('arch'): for node2 in node.findall('arch'):
r.append(repo_line_templ % (node.get('name'), node2.text)) yield repo_line_templ % (node.get('name'), node2.text)
return r
def get_binarylist(apiurl, prj, repo, arch, package=None): def get_binarylist(apiurl, prj, repo, arch, package=None):