1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-27 07:06:13 +01:00

- build & buildinfo:

- implement --extra-pkgs option
  - pass the list of extra packages to the backend, as "add=pkg" query parameters
  - use osc.core.get_buildinfo(), instead of os.system('osc buildinfo ...')
- implement adding query parameters to constructed URLs in a more generic way
This commit is contained in:
Dr. Peter Poeml 2007-05-09 09:36:55 +00:00
parent 9fb1e18470
commit cb61461fb4
3 changed files with 51 additions and 22 deletions

View File

@ -11,6 +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
import osc.conf import osc.conf
try: try:
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -238,10 +239,21 @@ def main(opts, argv):
print 'Getting buildinfo from server' print 'Getting buildinfo from server'
bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = '/tmp') bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = '/tmp')
rc = os.system('osc buildinfo %s %s %s > %s' % (repo, arch, spec, bi_file.name)) try:
if rc: bi_text = ''.join(get_buildinfo(store_read_apiurl(os.curdir),
store_read_project(os.curdir),
store_read_package(os.curdir),
repo,
arch,
specfile=spec,
addlist=opts.extra_pkgs))
except:
print >>sys.stderr, 'wrong repo/arch?' print >>sys.stderr, 'wrong repo/arch?'
sys.exit(rc) sys.exit(1)
bi_file.write(bi_text)
bi_file.flush()
bi = Buildinfo(bi_file.name) bi = Buildinfo(bi_file.name)
rpmlist_prefers = [] rpmlist_prefers = []

View File

@ -944,6 +944,8 @@ class Osc(cmdln.Cmdln):
pass pass
@cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append',
help='Add this package when computing the buildinfo')
def do_buildinfo(self, subcmd, opts, *args): def do_buildinfo(self, subcmd, opts, *args):
"""${cmd_name}: Shows the build info """${cmd_name}: Shows the build info
@ -993,7 +995,10 @@ class Osc(cmdln.Cmdln):
print >>sys.stderr, e print >>sys.stderr, e
return 1 return 1
print ''.join(get_buildinfo(apiurl, project, package, platform, arch, specfile=spec)) print ''.join(get_buildinfo(apiurl,
project, package, platform, arch,
specfile=spec,
addlist=opts.extra_pkgs))
def do_buildconfig(self, subcmd, opts, platform, arch): def do_buildconfig(self, subcmd, opts, platform, arch):
@ -1051,6 +1056,8 @@ class Osc(cmdln.Cmdln):
help='Prefer packages from this directory when installing the build-root') help='Prefer packages from this directory when installing the build-root')
@cmdln.option('-k', '--keep-pkgs', metavar='DIR', @cmdln.option('-k', '--keep-pkgs', metavar='DIR',
help='Save built packages into this directory') help='Save built packages into this directory')
@cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append',
help='Add this package when installing the build-root')
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

View File

@ -307,19 +307,22 @@ class Package:
# escaping '+' in the URL path (note: not in the URL query string) is # escaping '+' in the URL path (note: not in the URL query string) is
# only a workaround for ruby on rails, which swallows it otherwise # only a workaround for ruby on rails, which swallows it otherwise
u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)]) query = []
if conf.config['do_commits'] == '1': if conf.config['do_commits'] == '1':
u += '?rev=upload' query.append('rev=upload')
u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query)
http_PUT(u, file = os.path.join(self.dir, n)) http_PUT(u, file = os.path.join(self.dir, n))
shutil.copy2(os.path.join(self.dir, n), os.path.join(self.storedir, n)) shutil.copy2(os.path.join(self.dir, n), os.path.join(self.storedir, n))
def commit(self, msg=''): def commit(self, msg=''):
u = makeurl(self.apiurl, ['source', self.prjname, self.name]) query = []
u += '?cmd=commit&rev=upload' query.append('cmd=commit')
u += '&user=%s' % conf.config['user'] query.append('rev=upload')
u += '&comment=%s' % quote_plus(msg) query.append('user=%s' % conf.config['user'])
query.append('comment=%s' % quote_plus(msg))
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
#print u #print u
f = http_POST(u) f = http_POST(u)
#print f.read() #print f.read()
@ -634,13 +637,13 @@ def pathjoin(a, *p):
return path return path
def makeurl(baseurl, l): def makeurl(baseurl, l, query=[]):
"""given a list of path compoments, construct a complete URL""" """given a list of path compoments, construct a complete URL"""
#print 'makeurl:', baseurl, l #print 'makeurl:', baseurl, l, query
scheme, netloc = urlsplit(baseurl)[0:2] scheme, netloc = urlsplit(baseurl)[0:2]
return urlunsplit((scheme, netloc, '/'.join(l), '', '')) return urlunsplit((scheme, netloc, '/'.join(l), '&'.join(query), ''))
def http_request(method, url, data=None, file=None): def http_request(method, url, data=None, file=None):
@ -687,6 +690,7 @@ def http_DELETE(*args, **kwargs): return http_request('DELETE', *args, **kwargs)
def urlopen(url, data=None): def urlopen(url, data=None):
"""wrapper around urllib2.urlopen for error handling""" """wrapper around urllib2.urlopen for error handling"""
print 'core.urlopen() is deprecated -- use http_GET et al.' print 'core.urlopen() is deprecated -- use http_GET et al.'
try: try:
@ -1277,8 +1281,14 @@ def get_log(apiurl, prj, package, platform, arch, offset):
return f.read() return f.read()
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None): def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None, addlist=None):
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_buildinfo']) query = []
if addlist:
for i in addlist:
query.append('add=%s' % quote_plus(i))
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_buildinfo'], query=query)
if specfile: if specfile:
f = http_POST(u, data=specfile) f = http_POST(u, data=specfile)
else: else:
@ -1315,18 +1325,18 @@ def get_buildhistory(apiurl, prj, package, platform, arch):
def cmd_rebuild(apiurl, prj, package, repo, arch, code=None): def cmd_rebuild(apiurl, prj, package, repo, arch, code=None):
cmd = prj query = []
cmd += '?cmd=rebuild' query.append('cmd=rebuild')
if package: if package:
cmd += '&package=%s' % package query.append('package=%s' % quote_plus(package))
if repo: if repo:
cmd += '&repo=%s' % repo query.append('repo=%s' % quote_plus(repo))
if arch: if arch:
cmd += '&arch=%s' % arch query.append('arch=%s' % quote_plus(arch))
if code: if code:
cmd += '&code=%s' % code query.append('code=%s' % quote_plus(code))
u = makeurl(apiurl, ['build', cmd]) u = makeurl(apiurl, ['build', prj], query=query)
try: try:
f = http_POST(u) f = http_POST(u)
except urllib2.HTTPError, e: except urllib2.HTTPError, e: