Skip to content

Commit

Permalink
- add "osc results --watch" command to wait for build results in effi…
Browse files Browse the repository at this point in the history
…cient way
  • Loading branch information
adrianschroeter committed Jan 23, 2012
1 parent cb78230 commit 49d91c3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.134
- patchinfo call can work without checked out copy now
- use qemu as fallback for building not directly supported architectures
- "results --watch" option to watch build results until they finished building
#
# Features which requires OBS 2.3
#
Expand Down
6 changes: 5 additions & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4191,6 +4191,8 @@ def do_rremove(self, subcmd, opts, project, package, *files):
help='Show results only for specified architecture(s)')
@cmdln.option('-v', '--verbose', action='store_true', default=False,
help='more verbose output')
@cmdln.option('-w', '--watch', action='store_true', default=False,
help='permanently watch the result')
@cmdln.option('', '--xml', action='store_true', default=False,
help='generate output in XML (former results_meta)')
@cmdln.option('', '--csv', action='store_true', default=False,
Expand Down Expand Up @@ -4245,7 +4247,9 @@ def do_results(self, subcmd, opts, *args):
print '\n'.join(format_results(get_package_results(*args), opts.format))
else:
args.append(opts.verbose)
print '\n'.join(get_results(*args))
args.append(opts.watch)
args.append("\n")
get_results(*args)

# WARNING: this function is also called by do_results. You need to set a default there
# as well when adding a new option!
Expand Down
60 changes: 40 additions & 20 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4634,10 +4634,12 @@ def get_binarylist_published(apiurl, prj, repo, arch):
return r


def show_results_meta(apiurl, prj, package=None, lastbuild=None, repository=[], arch=[]):
def show_results_meta(apiurl, prj, package=None, lastbuild=None, repository=[], arch=[], oldstate=None):
query = {}
if package:
query['package'] = package
if oldstate:
query['oldstate'] = oldstate
if lastbuild:
query['lastbuild'] = 1
u = makeurl(apiurl, ['build', prj, '_result'], query=query)
Expand All @@ -4655,13 +4657,15 @@ def show_prj_results_meta(apiurl, prj):
return f.readlines()


def get_package_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]):
def get_package_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], oldstate=None):
""" return a package results as a list of dicts """
r = []

f = show_results_meta(apiurl, prj, package, lastbuild, repository, arch)
f = show_results_meta(apiurl, prj, package, lastbuild, repository, arch, oldstate)
root = ET.fromstring(''.join(f))

r.append( {'_oldstate': root.get('state')} )

for node in root.findall('result'):
rmap = {}
rmap['project'] = rmap['prj'] = prj
Expand Down Expand Up @@ -4692,26 +4696,42 @@ def format_results(results, format):
"""apply selected format on each dict in results and return it as a list of strings"""
return [format % r for r in results]

def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], verbose=False):
def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], verbose=False, wait=False, printJoin=None):
r = []
result_line_templ = '%(rep)-20s %(arch)-10s %(status)s'
oldstate = None

for res in get_package_results(apiurl, prj, package, lastbuild, repository, arch):
res['status'] = res['code']
if verbose and res['details'] != '':
if res['status'] in ('unresolvable', 'expansion error'):
lines = res['details'].split(',')
res['status'] += ': ' + '\n '.join(lines)

else:
res['status'] += ': %s' % (res['details'], )
if res['dirty']:
if verbose:
res['status'] = 'outdated (was: %s)' % res['status']
else:
res['status'] += '*'

r.append(result_line_templ % res)
while True:
waiting = False
r = []
for res in get_package_results(apiurl, prj, package, lastbuild, repository, arch, oldstate):
if res.has_key('_oldstate'):
oldstate = res['_oldstate']
continue
res['status'] = res['code']
if verbose and res['details'] != '':
if res['status'] in ('unresolvable', 'expansion error'):
lines = res['details'].split(',')
res['status'] += ': ' + '\n '.join(lines)

else:
res['status'] += ': %s' % (res['details'], )
if res['dirty']:
waiting=True
if verbose:
res['status'] = 'outdated (was: %s)' % res['status']
else:
res['status'] += '*'
if res['status'] in ('scheduled', 'finished', 'building', 'signing', 'dispatching'):
waiting=True

r.append(result_line_templ % res)

if printJoin:
print printJoin.join(r)

if wait==False or waiting==False:
break

return r

Expand Down

0 comments on commit 49d91c3

Please sign in to comment.