1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 09:16:16 +02:00
- save api server url to .osc/_apiurl. This requires changing makeurl() and all
  calls to it.
- implement 'info' subcommand, essential for debugging these changes.
- use new api routes in all places
- buildhistory works again
- copypac: implement package copy from one buildservice instance to another
  (--to-apiurl option)
- the results subcommand handles <working copy> arguments now
This commit is contained in:
Dr. Peter Poeml 2007-05-04 21:51:54 +00:00
parent 1c6f303c70
commit 90ca587cd0
2 changed files with 198 additions and 144 deletions

View File

@ -54,6 +54,7 @@ class Osc(cmdln.Cmdln):
if self.global_opts.apisrv: if self.global_opts.apisrv:
conf.config['scheme'], conf.config['apisrv'] = \ conf.config['scheme'], conf.config['apisrv'] = \
conf.parse_apisrv_url(conf.config['scheme'], self.global_opts.apisrv) conf.parse_apisrv_url(conf.config['scheme'], self.global_opts.apisrv)
conf.config['apiurl'] = conf.config['scheme'] + '://' + conf.config['apisrv']
# finally, initialize urllib2 for to use the credentials for Basic Authentication # finally, initialize urllib2 for to use the credentials for Basic Authentication
conf.init_basicauth(conf.config) conf.init_basicauth(conf.config)
@ -78,7 +79,7 @@ class Osc(cmdln.Cmdln):
project = args[0] project = args[0]
package = args[1] package = args[1]
init_package_dir(project, package, os.path.curdir) init_package_dir(conf.config['apiurl'], project, package, os.path.curdir)
print 'Initializing %s (Project: %s, Package: %s)' % (os.curdir, project, package) print 'Initializing %s (Project: %s, Package: %s)' % (os.curdir, project, package)
@ -98,14 +99,14 @@ class Osc(cmdln.Cmdln):
""" """
if not args: if not args:
print '\n'.join(meta_get_project_list()) print '\n'.join(meta_get_project_list(conf.config['apiurl']))
elif len(args) == 1: elif len(args) == 1:
project = args[0] project = args[0]
print '\n'.join(meta_get_packagelist(project)) print '\n'.join(meta_get_packagelist(conf.config['apiurl'], project))
elif len(args) == 2: elif len(args) == 2:
project = args[0] project = args[0]
package = args[1] package = args[1]
print '\n'.join(meta_get_filelist(project, package)) print '\n'.join(meta_get_filelist(conf.config['apiurl'], project, package))
def do_meta(self, subcmd, opts, *args): def do_meta(self, subcmd, opts, *args):
@ -126,12 +127,12 @@ class Osc(cmdln.Cmdln):
if len(args) == 2: if len(args) == 2:
project = args[0] project = args[0]
package = args[1] package = args[1]
print ''.join(show_package_meta(project, package)) print ''.join(show_package_meta(conf.config['apiurl'], project, package))
print ''.join(show_files_meta(project, package)) print ''.join(show_files_meta(conf.config['apiurl'], project, package))
elif len(args) == 1: elif len(args) == 1:
project = args[0] project = args[0]
print ''.join(show_project_meta(project)) print ''.join(show_project_meta(conf.config['apiurl'], project))
@cmdln.alias("createpac") @cmdln.alias("createpac")
@ -244,6 +245,8 @@ class Osc(cmdln.Cmdln):
link_pac(src_project, src_package, dst_project, dst_package) link_pac(src_project, src_package, dst_project, dst_package)
@cmdln.option('-t', '--to-apiurl', metavar='URL',
help='URL of destination api server. Default is the source api server.')
def do_copypac(self, subcmd, opts, *args): def do_copypac(self, subcmd, opts, *args):
"""${cmd_name}: Copy a package """${cmd_name}: Copy a package
@ -270,10 +273,19 @@ class Osc(cmdln.Cmdln):
else: else:
dst_package = src_package dst_package = src_package
if src_project == dst_project and src_package == dst_package: src_apiurl = conf.config['apiurl']
if opts.to_apiurl:
dst_apiurl = opts.to_apiurl
else:
dst_apiurl = src_apiurl
if src_project == dst_project and \
src_package == dst_package and \
src_apiurl == dst_apiurl:
print >>sys.stderr, 'Error: source and destination are the same.' print >>sys.stderr, 'Error: source and destination are the same.'
return 1 return 1
copy_pac(src_project, src_package, dst_project, dst_package) copy_pac(src_apiurl, src_project, src_package,
dst_apiurl, dst_project, dst_package)
def do_deletepac(self, subcmd, opts, project, package): def do_deletepac(self, subcmd, opts, project, package):
@ -286,7 +298,7 @@ class Osc(cmdln.Cmdln):
project = args[0] project = args[0]
package = args[1] package = args[1]
delete_package(project, package) delete_package(conf.config['apisrv'], project, package)
def do_deleteprj(self, subcmd, opts, project): def do_deleteprj(self, subcmd, opts, project):
@ -299,10 +311,10 @@ class Osc(cmdln.Cmdln):
${cmd_option_list} ${cmd_option_list}
""" """
if meta_get_packagelist(project) != []: if meta_get_packagelist(conf.config['apisrv'], project) != []:
print >>sys.stderr, 'Project contains packages. It must be empty before deleting it.' print >>sys.stderr, 'Project contains packages. It must be empty before deleting it.'
return 1 return 1
delete_project(project) delete_project(conf.config['apisrv'], project)
def do_updatepacmetafromspec(self, subcmd, opts, *args): def do_updatepacmetafromspec(self, subcmd, opts, *args):
@ -378,7 +390,7 @@ class Osc(cmdln.Cmdln):
url_tmpl = 'http://software.opensuse.org/download/%s/%s/%s.repo' url_tmpl = 'http://software.opensuse.org/download/%s/%s/%s.repo'
for p in pacs: for p in pacs:
platforms = get_platforms_of_project(p.prjname) platforms = get_platforms_of_project(p.apiurl, p.prjname)
for platform in platforms: for platform in platforms:
print url_tmpl % (p.prjname.replace(':', ':/'), platform, p.prjname) print url_tmpl % (p.prjname.replace(':', ':/'), platform, p.prjname)
@ -410,15 +422,15 @@ class Osc(cmdln.Cmdln):
pass pass
if filename: if filename:
get_source_file(project, package, filename) get_source_file(conf.config['apiurl'], project, package, filename)
elif package: elif package:
checkout_package(project, package) checkout_package(conf.config['apiurl'], project, package)
elif project: elif project:
# all packages # all packages
for package in meta_get_packagelist(project): for package in meta_get_packagelist(conf.config['apiurl'], project):
checkout_package(project, package) checkout_package(conf.config['apiurl'], project, package)
else: else:
print >>sys.stderr, 'Missing argument.' print >>sys.stderr, 'Missing argument.'
self.do_help(['foo', 'checkout']) self.do_help(['foo', 'checkout'])
@ -588,7 +600,7 @@ class Osc(cmdln.Cmdln):
for p in pacs: for p in pacs:
# commit only if the upstream revision is the same as the working copy's # commit only if the upstream revision is the same as the working copy's
upstream_rev = show_upstream_rev(p.prjname, p.name) upstream_rev = show_upstream_rev(p.apiurl, p.prjname, p.name)
if p.rev != upstream_rev: if p.rev != upstream_rev:
print >>sys.stderr, 'Working copy \'%s\' is out of date (rev %s vs rev %s).' \ print >>sys.stderr, 'Working copy \'%s\' is out of date (rev %s vs rev %s).' \
% (p.absdir, p.rev, upstream_rev) % (p.absdir, p.rev, upstream_rev)
@ -797,7 +809,7 @@ class Osc(cmdln.Cmdln):
${cmd_option_list} ${cmd_option_list}
""" """
r = get_user_meta(name) r = get_user_meta(conf.config['apiurl'], name)
if r: if r:
print ''.join(r) print ''.join(r)
@ -818,25 +830,27 @@ class Osc(cmdln.Cmdln):
if args: if args:
project = args[0] project = args[0]
print '\n'.join(get_platforms_of_project(project)) print '\n'.join(get_platforms_of_project(conf.config['apiurl'], project))
else: else:
print '\n'.join(get_platforms()) print '\n'.join(get_platforms(conf.config['apiurl']))
def do_results_meta(self, subcmd, opts): def do_results_meta(self, subcmd, opts, *args):
"""${cmd_name}: Shows raw build results of a package """${cmd_name}: Shows raw build results of a package
Shows the build results of the package in raw XML. Shows the build results of the package in raw XML.
Must be run in a package directory.
ARG, if specified, is the working copy of a package.
${cmd_usage} ${cmd_usage}
${cmd_option_list} ${cmd_option_list}
""" """
wd = os.curdir args = parseargs(args)
package = store_read_package(wd) pacs = findpacs(args)
project = store_read_project(wd)
print ''.join(show_results_meta(project, package)) for pac in pacs:
print ''.join(show_results_meta(pac.apiurl, pac.prjname, pac.name))
def do_results(self, subcmd, opts, *args): def do_results(self, subcmd, opts, *args):
@ -848,24 +862,15 @@ class Osc(cmdln.Cmdln):
${cmd_option_list} ${cmd_option_list}
""" """
if args and len(args) > 1:
print >>sys.stderr, 'getting results for more than one package is not supported'
self.do_help(['foo', 'results'])
return 2
if args:
wd = args[0]
else:
wd = os.curdir
try: try:
package = store_read_package(wd) args = parseargs(args)
project = store_read_project(wd) pacs = findpacs(args)
except: except:
print >>sys.stderr, '\'%s\' is not an osc package directory' % wd print >>sys.stderr, '\'%s\' is not an osc package directory' % wd
return 1 return 1
print '\n'.join(get_results(project, package)) for pac in pacs:
print '\n'.join(get_results(pac.apiurl, pac.prjname, pac.name))
@cmdln.option('-l', '--legend', action='store_true', @cmdln.option('-l', '--legend', action='store_true',
@ -896,11 +901,12 @@ class Osc(cmdln.Cmdln):
try: try:
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd)
except: except:
print >>sys.stderr, '\'%s\' is neither an osc project or package directory' % wd print >>sys.stderr, '\'%s\' is neither an osc project or package directory' % wd
return 1 return 1
print '\n'.join(get_prj_results(project, show_legend=opts.legend)) print '\n'.join(get_prj_results(apiurl, project, show_legend=opts.legend))
def do_log(self, subcmd, opts, platform, arch): def do_log(self, subcmd, opts, platform, arch):
@ -920,11 +926,12 @@ class Osc(cmdln.Cmdln):
wd = os.curdir wd = os.curdir
package = store_read_package(wd) package = store_read_package(wd)
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd)
offset = 0 offset = 0
try: try:
while True: while True:
log_chunk = get_log(project, package, platform, arch, offset) log_chunk = get_log(apiurl, project, package, platform, arch, offset)
if len(log_chunk) == 0: if len(log_chunk) == 0:
break break
offset += len(log_chunk) offset += len(log_chunk)
@ -960,6 +967,7 @@ class Osc(cmdln.Cmdln):
wd = os.curdir wd = os.curdir
package = store_read_package(wd) package = store_read_package(wd)
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd)
if args is None or len(args) < 2: if args is None or len(args) < 2:
print >>sys.stderr, 'Missing argument.' print >>sys.stderr, 'Missing argument.'
@ -981,7 +989,7 @@ class Osc(cmdln.Cmdln):
print >>sys.stderr, e print >>sys.stderr, e
return 1 return 1
print ''.join(get_buildinfo(project, package, platform, arch, specfile=spec)) print ''.join(get_buildinfo(apiurl, project, package, platform, arch, specfile=spec))
def do_buildconfig(self, subcmd, opts, platform, arch): def do_buildconfig(self, subcmd, opts, platform, arch):
@ -1005,8 +1013,9 @@ class Osc(cmdln.Cmdln):
wd = os.curdir wd = os.curdir
package = store_read_package(wd) package = store_read_package(wd)
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd)
print ''.join(get_buildconfig(project, package, platform, arch)) print ''.join(get_buildconfig(apiurl, project, package, platform, arch))
def do_repos(self, subcmd, opts, *args): def do_repos(self, subcmd, opts, *args):
@ -1026,7 +1035,7 @@ class Osc(cmdln.Cmdln):
for p in pacs: for p in pacs:
for platform in get_repos_of_project(p.prjname): for platform in get_repos_of_project(p.apiurl, p.prjname):
print platform print platform
@ -1137,8 +1146,9 @@ class Osc(cmdln.Cmdln):
wd = os.curdir wd = os.curdir
package = store_read_package(wd) package = store_read_package(wd)
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd)
print '\n'.join(get_buildhistory(project, package, platform, arch)) print '\n'.join(get_buildhistory(apiurl, project, package, platform, arch))
@cmdln.option('-f', '--failed', action='store_true', @cmdln.option('-f', '--failed', action='store_true',
@ -1182,9 +1192,26 @@ class Osc(cmdln.Cmdln):
if opts.failed: if opts.failed:
code = 'failed' code = 'failed'
print cmd_rebuild(project, package, repo, arch, code) print cmd_rebuild(conf.config['apiurl'], project, package, repo, arch, code)
def do_info(self, subcmd, opts, *args):
"""${cmd_name}: Print information about a working copy
Print information about each ARG (default: '.')
ARG is a working-copy path.
${cmd_usage}
${cmd_option_list}
"""
args = parseargs(args)
pacs = findpacs(args)
for p in pacs:
print p.info()
if __name__ == '__main__': if __name__ == '__main__':
osc = Osc() osc = Osc()

View File

@ -5,13 +5,13 @@
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version. # either version 2, or (at your option) any later version.
__version__ = '0.95' __version__ = '0.96'
import os import os
import sys import sys
import urllib2 import urllib2
from urllib import pathname2url, quote_plus from urllib import pathname2url, quote_plus
from urlparse import urlunsplit from urlparse import urlsplit, urlunsplit
from cStringIO import StringIO from cStringIO import StringIO
import shutil import shutil
import conf import conf
@ -89,7 +89,7 @@ HERE
<!-- <!--
use on of the examples below to disable building of this package use one of the examples below to disable building of this package
on a certain architecture, in a certain repository, on a certain architecture, in a certain repository,
or a combination thereof: or a combination thereof:
@ -121,6 +121,13 @@ new_user_template = """\
</person> </person>
""" """
info_templ = """\
Path: %s
API URL: %s
Repository UUID: %s
Revision: %s
"""
buildstatus_symbols = {'succeeded': '.', buildstatus_symbols = {'succeeded': '.',
'disabled': ' ', 'disabled': ' ',
'expansion error': 'E', 'expansion error': 'E',
@ -150,8 +157,9 @@ class Project:
self.absdir = os.path.abspath(dir) self.absdir = os.path.abspath(dir)
self.name = store_read_project(self.dir) self.name = store_read_project(self.dir)
self.apiurl = store_read_apiurl(self.dir)
self.pacs_available = meta_get_packagelist(self.name) self.pacs_available = meta_get_packagelist(self.apiurl, self.name)
self.pacs_have = [ i for i in os.listdir(self.dir) if i in self.pacs_available ] self.pacs_have = [ i for i in os.listdir(self.dir) if i in self.pacs_available ]
@ -162,7 +170,7 @@ class Project:
print 'checking out new package %s' % pac print 'checking out new package %s' % pac
olddir = os.getcwd() olddir = os.getcwd()
os.chdir(os.pardir) os.chdir(os.pardir)
checkout_package(self.name, pac) checkout_package(self.apiurl, self.name, pac)
os.chdir(olddir) os.chdir(olddir)
@ -189,11 +197,13 @@ class Package:
self.prjname = store_read_project(self.dir) self.prjname = store_read_project(self.dir)
self.name = store_read_package(self.dir) self.name = store_read_package(self.dir)
self.apiurl = store_read_apiurl(self.dir)
files_tree = read_filemeta(self.dir) files_tree = read_filemeta(self.dir)
files_tree_root = files_tree.getroot() files_tree_root = files_tree.getroot()
self.rev = files_tree_root.get('rev') self.rev = files_tree_root.get('rev')
self.srcmd5 = files_tree_root.get('srcmd5')
self.filenamelist = [] self.filenamelist = []
self.filelist = [] self.filelist = []
@ -224,6 +234,9 @@ class Package:
if i not in self.excluded if i not in self.excluded
if i not in self.filenamelist ] if i not in self.filenamelist ]
def info(self):
return info_templ % (self.dir, self.apiurl, self.srcmd5, self.rev)
def addfile(self, n): def addfile(self, n):
st = os.stat(os.path.join(self.dir, n)) st = os.stat(os.path.join(self.dir, n))
f = File(n, None, st.st_size, st.st_mtime) f = File(n, None, st.st_size, st.st_mtime)
@ -284,7 +297,7 @@ class Package:
def delete_source_file(self, n): def delete_source_file(self, n):
u = makeurl(['source', self.prjname, self.name, pathname2url(n)]) u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)])
http_DELETE(u) http_DELETE(u)
self.delete_localfile(n) self.delete_localfile(n)
@ -294,7 +307,7 @@ 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(['source', self.prjname, self.name, pathname2url(n)]) u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)])
if conf.config['do_commits'] == '1': if conf.config['do_commits'] == '1':
u += '?rev=upload' u += '?rev=upload'
http_PUT(u, file = os.path.join(self.dir, n)) http_PUT(u, file = os.path.join(self.dir, n))
@ -303,7 +316,7 @@ class Package:
def commit(self, msg=''): def commit(self, msg=''):
u = makeurl(['source', self.prjname, self.name]) u = makeurl(self.apiurl, ['source', self.prjname, self.name])
u += '?cmd=commit&rev=upload' u += '?cmd=commit&rev=upload'
u += '&user=%s' % conf.config['user'] u += '&user=%s' % conf.config['user']
u += '&comment=%s' % quote_plus(msg) u += '&comment=%s' % quote_plus(msg)
@ -326,7 +339,7 @@ class Package:
storefilename = os.path.join(self.storedir, n) storefilename = os.path.join(self.storedir, n)
mtime = self.findfilebyname(n).mtime mtime = self.findfilebyname(n).mtime
get_source_file(self.prjname, self.name, n, targetfilename=filename) get_source_file(self.apiurl, self.prjname, self.name, n, targetfilename=filename)
os.utime(filename, (-1, mtime)) os.utime(filename, (-1, mtime))
shutil.copy2(filename, storefilename) shutil.copy2(filename, storefilename)
@ -339,7 +352,7 @@ class Package:
os.rename(filename, myfilename) os.rename(filename, myfilename)
mtime = self.findfilebyname(n).mtime mtime = self.findfilebyname(n).mtime
get_source_file(self.prjname, self.name, n, targetfilename=upfilename) get_source_file(self.apiurl, self.prjname, self.name, n, targetfilename=upfilename)
os.utime(upfilename, (-1, mtime)) os.utime(upfilename, (-1, mtime))
if binary_file(myfilename) or binary_file(upfilename): if binary_file(myfilename) or binary_file(upfilename):
@ -379,13 +392,13 @@ class Package:
def update_filesmeta(self): def update_filesmeta(self):
meta = ''.join(show_files_meta(self.prjname, self.name)) meta = ''.join(show_files_meta(self.apiurl, self.prjname, self.name))
f = open(os.path.join(self.storedir, '_files'), 'w') f = open(os.path.join(self.storedir, '_files'), 'w')
f.write(meta) f.write(meta)
f.close() f.close()
def update_pacmeta(self): def update_pacmeta(self):
meta = ''.join(show_package_meta(self.prjname, self.name)) meta = ''.join(show_package_meta(self.apiurl, self.prjname, self.name))
f = open(os.path.join(self.storedir, '_meta'), 'w') f = open(os.path.join(self.storedir, '_meta'), 'w')
f.write(meta) f.write(meta)
f.close() f.close()
@ -493,7 +506,7 @@ rev: %s
(fd, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp') (fd, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp')
try: try:
u = makeurl(['source', self.prjname, self.name, '_meta']) u = makeurl(self.apiurl, ['source', self.prjname, self.name, '_meta'])
m = http_GET(u).readlines() m = http_GET(u).readlines()
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
if e.code == 404: if e.code == 404:
@ -525,7 +538,7 @@ rev: %s
repl = raw_input('Write? (y/N) ') repl = raw_input('Write? (y/N) ')
if repl == 'y': if repl == 'y':
print 'Sending meta data...', print 'Sending meta data...',
u = makeurl(['source', self.prjname, self.name, '_meta']) u = makeurl(self.apiurl, ['source', self.prjname, self.name, '_meta'])
http_PUT(u, file=filename) http_PUT(u, file=filename)
print 'Done.' print 'Done.'
else: else:
@ -537,19 +550,13 @@ rev: %s
def is_project_dir(d): def is_project_dir(d):
if os.path.exists(os.path.join(d, store, '_project')) and not \ return os.path.exists(os.path.join(d, store, '_project')) and not \
os.path.exists(os.path.join(d, store, '_package')): os.path.exists(os.path.join(d, store, '_package'))
return True
else:
return False
def is_package_dir(d): def is_package_dir(d):
if os.path.exists(os.path.join(d, store, '_project')) and \ return os.path.exists(os.path.join(d, store, '_project')) and \
os.path.exists(os.path.join(d, store, '_package')): os.path.exists(os.path.join(d, store, '_package'))
return True
else:
return False
def findpacs(files): def findpacs(files):
@ -627,9 +634,13 @@ def pathjoin(a, *p):
return path return path
def makeurl(l): def makeurl(baseurl, l):
"""given a list of path compoments, construct a complete URL""" """given a list of path compoments, construct a complete URL"""
return urlunsplit((conf.config['scheme'], conf.config['apisrv'], '/'.join(l), '', ''))
#print 'makeurl:', baseurl, l
scheme, netloc = urlsplit(baseurl)[0:2]
return urlunsplit((scheme, netloc, '/'.join(l), '', ''))
def http_request(method, url, data=None, file=None): def http_request(method, url, data=None, file=None):
@ -695,7 +706,7 @@ def urlopen(url, data=None):
return fd return fd
def init_package_dir(project, package, dir): def init_package_dir(apiurl, project, package, dir):
if not os.path.isdir(store): if not os.path.isdir(store):
os.mkdir(store) os.mkdir(store)
os.chdir(store) os.chdir(store)
@ -707,13 +718,15 @@ def init_package_dir(project, package, dir):
f.close f.close
f = open('_files', 'w') f = open('_files', 'w')
f.write(''.join(show_files_meta(project, package))) f.write(''.join(show_files_meta(apiurl, project, package)))
f.close() f.close()
f = open('_osclib_version', 'w') f = open('_osclib_version', 'w')
f.write(__version__ + '\n') f.write(__version__ + '\n')
f.close() f.close()
store_write_apiurl(os.path.pardir, apiurl)
os.chdir(os.pardir) os.chdir(os.pardir)
return return
@ -730,7 +743,7 @@ def check_store_version(dir):
sys.exit(1) sys.exit(1)
if v != __version__: if v != __version__:
if v in ['0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9']: if v in ['0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '0.95']:
# version is fine, no migration needed # version is fine, no migration needed
f = open(versionfile, 'w') f = open(versionfile, 'w')
f.write(__version__ + '\n') f.write(__version__ + '\n')
@ -744,38 +757,38 @@ def check_store_version(dir):
sys.exit(1) sys.exit(1)
def meta_get_packagelist(prj): def meta_get_packagelist(apiurl, prj):
u = makeurl(['source', prj]) u = makeurl(apiurl, ['source', prj])
f = http_GET(u) f = http_GET(u)
root = ET.parse(f).getroot() root = ET.parse(f).getroot()
return [ node.get('name') for node in root.findall('entry') ] return [ node.get('name') for node in root.findall('entry') ]
def meta_get_filelist(prj, package): def meta_get_filelist(apiurl, prj, package):
u = makeurl(['source', prj, package]) u = makeurl(apiurl, ['source', prj, package])
f = http_GET(u) f = http_GET(u)
root = ET.parse(f).getroot() root = ET.parse(f).getroot()
return [ node.get('name') for node in root ] return [ node.get('name') for node in root ]
def meta_get_project_list(): def meta_get_project_list(apiurl):
u = makeurl(['source']) u = makeurl(apiurl, ['source'])
f = http_GET(u) f = http_GET(u)
root = ET.parse(f).getroot() root = ET.parse(f).getroot()
return sorted([ node.get('name') for node in root ]) return sorted([ node.get('name') for node in root ])
def show_project_meta(prj): def show_project_meta(apiurl, prj):
url = makeurl(['source', prj, '_meta']) url = makeurl(apiurl, ['source', prj, '_meta'])
f = http_GET(url) f = http_GET(url)
return f.readlines() return f.readlines()
def show_package_meta(prj, pac): def show_package_meta(apiurl, prj, pac):
try: try:
url = makeurl(['source', prj, pac, '_meta']) url = makeurl(apiurl, ['source', prj, pac, '_meta'])
f = http_GET(url) f = http_GET(url)
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
print >>sys.stderr, 'error getting meta for project \'%s\' package \'%s\'' % (prj, pac) print >>sys.stderr, 'error getting meta for project \'%s\' package \'%s\'' % (prj, pac)
@ -785,6 +798,7 @@ def show_package_meta(prj, pac):
sys.exit(1) sys.exit(1)
return f.readlines() return f.readlines()
class metafile: class metafile:
"""metafile that can be manipulated and is stored back after manipulation.""" """metafile that can be manipulated and is stored back after manipulation."""
def __init__(self, prj, pac, template=new_package_templ, change_is_required=True): def __init__(self, prj, pac, template=new_package_templ, change_is_required=True):
@ -797,7 +811,7 @@ class metafile:
if pac: if pac:
# package meta # package meta
self.url = makeurl(['source', prj, pac, '_meta']) self.url = makeurl(conf.config['apiurl'], ['source', prj, pac, '_meta'])
try: try:
m = http_GET(self.url).readlines() m = http_GET(self.url).readlines()
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
@ -810,7 +824,7 @@ class metafile:
else: else:
# project meta # project meta
self.url = makeurl(['source', prj, '_meta']) self.url = makeurl(conf.config['apiurl'], ['source', prj, '_meta'])
try: try:
m = http_GET(self.url).readlines() m = http_GET(self.url).readlines()
# when testing this offline: # when testing this offline:
@ -853,7 +867,7 @@ def edit_meta(prj, pac, template=new_package_templ, change_is_required=True):
def edit_user_meta(user, change_is_required=True): def edit_user_meta(user, change_is_required=True):
import tempfile import tempfile
u = makeurl(['person', quote_plus(user)]) u = makeurl(conf.config['apiurl'], ['person', quote_plus(user)])
try: try:
m = http_GET(u).readlines() m = http_GET(u).readlines()
@ -885,13 +899,13 @@ def edit_user_meta(user, change_is_required=True):
print 'Done.' print 'Done.'
def show_files_meta(prj, pac): def show_files_meta(apiurl, prj, pac):
f = http_GET(makeurl(['source', prj, pac])) f = http_GET(makeurl(apiurl, ['source', prj, pac]))
return f.readlines() return f.readlines()
def show_upstream_rev(prj, pac): def show_upstream_rev(apiurl, prj, pac):
m = show_files_meta(prj, pac) m = show_files_meta(apiurl, prj, pac)
return ET.parse(StringIO(''.join(m))).getroot().get('rev') return ET.parse(StringIO(''.join(m))).getroot().get('rev')
@ -924,8 +938,8 @@ def read_meta_from_spec(specfile):
return name, summary, descr return name, summary, descr
def get_user_meta(user): def get_user_meta(apiurl, user):
u = makeurl(['person', quote_plus(user)]) u = makeurl(apiurl, ['person', quote_plus(user)])
try: try:
f = http_GET(u) f = http_GET(u)
return ''.join(f.readlines()) return ''.join(f.readlines())
@ -934,8 +948,8 @@ def get_user_meta(user):
return None return None
def get_source_file(prj, package, filename, targetfilename=None): def get_source_file(apiurl, prj, package, filename, targetfilename=None):
u = makeurl(['source', prj, package, pathname2url(filename)]) u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)])
f = http_GET(u) f = http_GET(u)
o = open(targetfilename or filename, 'w') o = open(targetfilename or filename, 'w')
@ -1000,16 +1014,15 @@ def get_source_file_diff(dir, filename, rev):
return ''.join(d) return ''.join(d)
def make_dir(project, package): def make_dir(apiurl, project, package):
#print "creating directory '%s'" % project #print "creating directory '%s'" % project
if not os.path.exists(project): if not os.path.exists(project):
print statfrmt('A', project) print statfrmt('A', project)
os.mkdir(project) os.mkdir(project)
os.mkdir(os.path.join(project, store)) os.mkdir(os.path.join(project, store))
f = open(os.path.join(project, store, '_project'), 'w') store_write_project(project, project)
f.write(project + '\n') store_write_apiurl(project, apiurl)
f.close()
#print "creating directory '%s/%s'" % (project, package) #print "creating directory '%s/%s'" % (project, package)
if not os.path.exists(os.path.join(project, package)): if not os.path.exists(os.path.join(project, package)):
@ -1020,11 +1033,11 @@ def make_dir(project, package):
return(os.path.join(project, package)) return(os.path.join(project, package))
def checkout_package(project, package): def checkout_package(apiurl, project, package):
olddir = os.getcwd() olddir = os.getcwd()
os.chdir(make_dir(project, package)) os.chdir(make_dir(apiurl, project, package))
init_package_dir(project, package, store) init_package_dir(apiurl, project, package, store)
p = Package(os.curdir) p = Package(os.curdir)
for filename in p.filenamelist: for filename in p.filenamelist:
@ -1044,7 +1057,7 @@ def link_pac(src_project, src_package, dst_project, dst_package):
import tempfile import tempfile
src_meta = show_package_meta(src_project, src_package) src_meta = show_package_meta(conf.config['apiurl'], src_project, src_package)
# replace package name and username # replace package name and username
# using a string buffer # using a string buffer
@ -1062,7 +1075,7 @@ def link_pac(src_project, src_package, dst_project, dst_package):
# create the _link file # create the _link file
# but first, make sure not to overwrite an existing one # but first, make sure not to overwrite an existing one
if '_link' in meta_get_filelist(dst_project, dst_package): if '_link' in meta_get_filelist(conf.config['apiurl'], dst_project, dst_package):
print >>sys.stderr print >>sys.stderr
print >>sys.stderr, '_link file already exists...! Aborting' print >>sys.stderr, '_link file already exists...! Aborting'
sys.exit(1) sys.exit(1)
@ -1077,19 +1090,20 @@ def link_pac(src_project, src_package, dst_project, dst_package):
</link> </link>
""" % (src_project, src_package) """ % (src_project, src_package)
u = makeurl(['source', dst_project, dst_package, '_link']) u = makeurl(conf.config['apiurl'], ['source', dst_project, dst_package, '_link'])
http_PUT(u, data=link_template) http_PUT(u, data=link_template)
print 'Done.' print 'Done.'
def copy_pac(src_project, src_package, dst_project, dst_package): def copy_pac(src_apiurl, src_project, src_package,
dst_apiurl, dst_project, dst_package):
""" """
create a copy of a package create a copy of a package
""" """
import tempfile import tempfile
src_meta = show_package_meta(src_project, src_package) src_meta = show_package_meta(src_apiurl, src_project, src_package)
# replace project and package name # replace project and package name
# using a string buffer # using a string buffer
@ -1103,53 +1117,53 @@ def copy_pac(src_project, src_package, dst_project, dst_package):
src_meta = buf.getvalue() src_meta = buf.getvalue()
print 'Sending meta data...' print 'Sending meta data...'
u = makeurl(['source', dst_project, dst_package, '_meta']) u = makeurl(dst_apiurl, ['source', dst_project, dst_package, '_meta'])
http_PUT(u, data=src_meta) http_PUT(u, data=src_meta)
# copy one file after the other # copy one file after the other
print 'Copying files...' print 'Copying files...'
tmpdir = tempfile.mkdtemp(prefix='osc_copypac', dir = '/tmp') tmpdir = tempfile.mkdtemp(prefix='osc_copypac', dir = '/tmp')
os.chdir(tmpdir) os.chdir(tmpdir)
for n in meta_get_filelist(src_project, src_package): for n in meta_get_filelist(src_apiurl, src_project, src_package):
print ' ', n print ' ', n
get_source_file(src_project, src_package, n, targetfilename=n) get_source_file(src_apiurl, src_project, src_package, n, targetfilename=n)
u = makeurl(['source', dst_project, dst_package, pathname2url(n)]) u = makeurl(dst_apiurl, ['source', dst_project, dst_package, pathname2url(n)])
http_PUT(u, file = n) http_PUT(u, file = n)
os.unlink(n) os.unlink(n)
print 'Done.' print 'Done.'
os.rmdir(tmpdir) os.rmdir(tmpdir)
def delete_package(prj, pac): def delete_package(apiurl, prj, pac):
u = makeurl(['source', prj, pac]) u = makeurl(apiurl, ['source', prj, pac])
http_DELETE(u) http_DELETE(u)
def delete_project(prj): def delete_project(apiurl, prj):
u = makeurl(['source', prj]) u = makeurl(apiurl, ['source', prj])
http_DELETE(u) http_DELETE(u)
def get_platforms(): def get_platforms(apiurl):
f = http_GET(makeurl(['platform'])) f = http_GET(makeurl(apiurl, ['platform']))
tree = ET.parse(f) tree = ET.parse(f)
r = [ node.get('name') for node in tree.getroot() ] r = [ node.get('name') for node in tree.getroot() ]
r.sort() r.sort()
return r return r
def get_platforms_of_project(prj): def get_platforms_of_project(apiurl, prj):
f = show_project_meta(prj) f = show_project_meta(apiurl, prj)
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
r = [ node.get('name') for node in tree.findall('repository')] r = [ node.get('name') for node in tree.findall('repository')]
return r return r
def get_repos_of_project(prj): def get_repos_of_project(apiurl, prj):
f = show_project_meta(prj) f = show_project_meta(apiurl, prj)
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
repo_line_templ = '%-15s %-10s' repo_line_templ = '%-15s %-10s'
@ -1160,23 +1174,23 @@ def get_repos_of_project(prj):
return r return r
def show_results_meta(prj, package): def show_results_meta(apiurl, prj, package):
u = makeurl(['build', prj, '_result?package=%s' % pathname2url(package)]) u = makeurl(apiurl, ['build', prj, '_result?package=%s' % pathname2url(package)])
f = http_GET(u) f = http_GET(u)
return f.readlines() return f.readlines()
def show_prj_results_meta(prj): def show_prj_results_meta(apiurl, prj):
u = makeurl(['build', prj, '_result']) u = makeurl(apiurl, ['build', prj, '_result'])
f = http_GET(u) f = http_GET(u)
return f.readlines() return f.readlines()
def get_results(prj, package): def get_results(apiurl, prj, package):
r = [] r = []
result_line_templ = '%(rep)-15s %(arch)-10s %(status)s' result_line_templ = '%(rep)-15s %(arch)-10s %(status)s'
f = show_results_meta(prj, package) f = show_results_meta(apiurl, prj, package)
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
root = tree.getroot() root = tree.getroot()
@ -1200,14 +1214,14 @@ def get_results(prj, package):
r.append(result_line_templ % rmap) r.append(result_line_templ % rmap)
return r return r
def get_prj_results(prj, show_legend=False): def get_prj_results(apiurl, prj, show_legend=False):
#print '----------------------------------------' #print '----------------------------------------'
r = [] r = []
#result_line_templ = '%(prj)-15s %(pac)-15s %(rep)-15s %(arch)-10s %(status)s' #result_line_templ = '%(prj)-15s %(pac)-15s %(rep)-15s %(arch)-10s %(status)s'
result_line_templ = '%(rep)-15s %(arch)-10s %(status)s' result_line_templ = '%(rep)-15s %(arch)-10s %(status)s'
f = show_prj_results_meta(prj) f = show_prj_results_meta(apiurl, prj)
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
root = tree.getroot() root = tree.getroot()
@ -1257,15 +1271,14 @@ def get_prj_results(prj, show_legend=False):
return r return r
def get_log(prj, package, platform, arch, offset): def get_log(apiurl, prj, package, platform, arch, offset):
u = makeurl(['result', prj, platform, package, arch, 'log?nostream=1&start=%s' % offset]) u = makeurl(apiurl, ['build', prj, platform, arch, package, '_log?nostream=1&start=%s' % offset])
f = http_GET(u) f = http_GET(u)
return f.read() return f.read()
def get_buildinfo(prj, package, platform, arch, specfile=None): def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None):
# http://api.opensuse.org/rpm/Subversion/Apache_SuSE_Linux_10.1/i586/subversion/buildinfo u = makeurl(apiurl, ['build', prj, platform, arch, package, '_buildinfo'])
u = makeurl(['rpm', prj, platform, arch, package, 'buildinfo'])
if specfile: if specfile:
f = http_POST(u, data=specfile) f = http_POST(u, data=specfile)
else: else:
@ -1273,17 +1286,15 @@ def get_buildinfo(prj, package, platform, arch, specfile=None):
return f.read() return f.read()
def get_buildconfig(prj, package, platform, arch): def get_buildconfig(apiurl, prj, package, platform, arch):
# http://api.opensuse.org/rpm/<proj>/<repo>/_repository/<arch>/_buildconfig u = makeurl(apiurl, ['build', prj, platform, '_buildconfig'])
u = makeurl(['rpm', prj, platform, '_repository', arch, '_buildconfig'])
f = http_GET(u) f = http_GET(u)
return f.read() return f.read()
def get_buildhistory(prj, package, platform, arch): def get_buildhistory(apiurl, prj, package, platform, arch):
import time import time
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_history'])
u = makeurl(['rpm', prj, platform, arch, package, 'history'])
f = http_GET(u) f = http_GET(u)
root = ET.parse(f).getroot() root = ET.parse(f).getroot()
@ -1303,7 +1314,7 @@ def get_buildhistory(prj, package, platform, arch):
return r return r
def cmd_rebuild(prj, package, repo, arch, code=None): def cmd_rebuild(apiurl, prj, package, repo, arch, code=None):
cmd = prj cmd = prj
cmd += '?cmd=rebuild' cmd += '?cmd=rebuild'
if package: if package:
@ -1315,7 +1326,7 @@ def cmd_rebuild(prj, package, repo, arch, code=None):
if code: if code:
cmd += '&code=%s' % code cmd += '&code=%s' % code
u = makeurl(['build', cmd]) u = makeurl(apiurl, ['build', cmd])
try: try:
f = http_POST(u) f = http_POST(u)
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
@ -1337,6 +1348,22 @@ def store_read_package(dir):
p = open(os.path.join(dir, store, '_package')).readlines()[0].strip() p = open(os.path.join(dir, store, '_package')).readlines()[0].strip()
return p return p
def store_read_apiurl(dir):
fname = os.path.join(dir, store, '_apiurl')
try:
apiurl = open(fname).readlines()[0].strip()
except:
apiurl = conf.config['scheme'] + '://' + conf.config['apisrv']
#store_write_apiurl(dir, apiurl)
return apiurl
def store_write_project(dir, project):
fname = os.path.join(dir, store, '_project')
open(fname, 'w').write(project + '\n')
def store_write_apiurl(dir, apiurl):
fname = os.path.join(dir, store, '_apiurl')
open(fname, 'w').write(apiurl + '\n')
def get_osc_version(): def get_osc_version():
return __version__ return __version__