mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-26 22:56:15 +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:
parent
9fb1e18470
commit
cb61461fb4
18
osc/build.py
18
osc/build.py
@ -11,6 +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
|
||||
import osc.conf
|
||||
try:
|
||||
from xml.etree import cElementTree as ET
|
||||
@ -238,10 +239,21 @@ def main(opts, argv):
|
||||
|
||||
print 'Getting buildinfo from server'
|
||||
bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = '/tmp')
|
||||
rc = os.system('osc buildinfo %s %s %s > %s' % (repo, arch, spec, bi_file.name))
|
||||
if rc:
|
||||
try:
|
||||
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?'
|
||||
sys.exit(rc)
|
||||
sys.exit(1)
|
||||
bi_file.write(bi_text)
|
||||
bi_file.flush()
|
||||
|
||||
bi = Buildinfo(bi_file.name)
|
||||
|
||||
rpmlist_prefers = []
|
||||
|
@ -944,6 +944,8 @@ class Osc(cmdln.Cmdln):
|
||||
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):
|
||||
"""${cmd_name}: Shows the build info
|
||||
|
||||
@ -993,7 +995,10 @@ class Osc(cmdln.Cmdln):
|
||||
print >>sys.stderr, e
|
||||
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):
|
||||
@ -1051,6 +1056,8 @@ class Osc(cmdln.Cmdln):
|
||||
help='Prefer packages from this directory when installing the build-root')
|
||||
@cmdln.option('-k', '--keep-pkgs', metavar='DIR',
|
||||
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):
|
||||
"""${cmd_name}: Build a package on your local machine
|
||||
|
||||
|
46
osc/core.py
46
osc/core.py
@ -307,19 +307,22 @@ class Package:
|
||||
|
||||
# escaping '+' in the URL path (note: not in the URL query string) is
|
||||
# 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':
|
||||
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))
|
||||
|
||||
shutil.copy2(os.path.join(self.dir, n), os.path.join(self.storedir, n))
|
||||
|
||||
def commit(self, msg=''):
|
||||
|
||||
u = makeurl(self.apiurl, ['source', self.prjname, self.name])
|
||||
u += '?cmd=commit&rev=upload'
|
||||
u += '&user=%s' % conf.config['user']
|
||||
u += '&comment=%s' % quote_plus(msg)
|
||||
query = []
|
||||
query.append('cmd=commit')
|
||||
query.append('rev=upload')
|
||||
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
|
||||
f = http_POST(u)
|
||||
#print f.read()
|
||||
@ -634,13 +637,13 @@ def pathjoin(a, *p):
|
||||
return path
|
||||
|
||||
|
||||
def makeurl(baseurl, l):
|
||||
def makeurl(baseurl, l, query=[]):
|
||||
"""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]
|
||||
return urlunsplit((scheme, netloc, '/'.join(l), '', ''))
|
||||
return urlunsplit((scheme, netloc, '/'.join(l), '&'.join(query), ''))
|
||||
|
||||
|
||||
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):
|
||||
"""wrapper around urllib2.urlopen for error handling"""
|
||||
|
||||
print 'core.urlopen() is deprecated -- use http_GET et al.'
|
||||
|
||||
try:
|
||||
@ -1277,8 +1281,14 @@ def get_log(apiurl, prj, package, platform, arch, offset):
|
||||
return f.read()
|
||||
|
||||
|
||||
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None):
|
||||
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_buildinfo'])
|
||||
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None, addlist=None):
|
||||
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:
|
||||
f = http_POST(u, data=specfile)
|
||||
else:
|
||||
@ -1315,18 +1325,18 @@ def get_buildhistory(apiurl, prj, package, platform, arch):
|
||||
|
||||
|
||||
def cmd_rebuild(apiurl, prj, package, repo, arch, code=None):
|
||||
cmd = prj
|
||||
cmd += '?cmd=rebuild'
|
||||
query = []
|
||||
query.append('cmd=rebuild')
|
||||
if package:
|
||||
cmd += '&package=%s' % package
|
||||
query.append('package=%s' % quote_plus(package))
|
||||
if repo:
|
||||
cmd += '&repo=%s' % repo
|
||||
query.append('repo=%s' % quote_plus(repo))
|
||||
if arch:
|
||||
cmd += '&arch=%s' % arch
|
||||
query.append('arch=%s' % quote_plus(arch))
|
||||
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:
|
||||
f = http_POST(u)
|
||||
except urllib2.HTTPError, e:
|
||||
|
Loading…
Reference in New Issue
Block a user