Skip to content

Commit

Permalink
- added support to strip the build time from the buildlog when runnin…
Browse files Browse the repository at this point in the history
…g "bl", "rbl", "lbl"

Also added a config option "buildlog_strip_time" to permanently enable/disable the
stripping of the build time.
  • Loading branch information
marcus-h committed Dec 15, 2012
1 parent bfa1088 commit 737bac5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
16 changes: 12 additions & 4 deletions osc/commandline.py
Expand Up @@ -4439,6 +4439,8 @@ def do_rprjresults(self, subcmd, opts, *args):
@cmdln.alias('buildlogtail')
@cmdln.option('-o', '--offset', metavar='OFFSET',
help='get log start or end from the offset')
@cmdln.option('-s', '--strip-time', action='store_true',
help='strip leading build time from the log')
def do_buildlog(self, subcmd, opts, *args):
"""${cmd_name}: Shows the build log of a package
Expand Down Expand Up @@ -4489,8 +4491,8 @@ def do_buildlog(self, subcmd, opts, *args):
offset=0
elif opts.offset:
offset = int(opts.offset)

print_buildlog(apiurl, project, package, repository, arch, offset)
strip_time = opts.strip_time or conf.config['buildlog_strip_time']
print_buildlog(apiurl, project, package, repository, arch, offset, strip_time)


def print_repos(self, repos_only=False, exc_class=oscerr.WrongArgs, exc_msg='Missing arguments'):
Expand Down Expand Up @@ -4519,6 +4521,8 @@ def print_repos(self, repos_only=False, exc_class=oscerr.WrongArgs, exc_msg='Mis
@cmdln.alias('remotebuildlogtail')
@cmdln.option('-o', '--offset', metavar='OFFSET',
help='get log starting or ending from the offset')
@cmdln.option('-s', '--strip-time', action='store_true',
help='strip leading build time from the log')
def do_remotebuildlog(self, subcmd, opts, *args):
"""${cmd_name}: Shows the build log of a package
Expand Down Expand Up @@ -4562,12 +4566,14 @@ def do_remotebuildlog(self, subcmd, opts, *args):
offset=0
elif opts.offset:
offset = int(opts.offset)

print_buildlog(apiurl, project, package, repository, arch, offset)
strip_time = opts.strip_time or conf.config['buildlog_strip_time']
print_buildlog(apiurl, project, package, repository, arch, offset, strip_time)

@cmdln.alias('lbl')
@cmdln.option('-o', '--offset', metavar='OFFSET',
help='get log starting from offset')
@cmdln.option('-s', '--strip-time', action='store_true',
help='strip leading build time from the log')
def do_localbuildlog(self, subcmd, opts, *args):
"""${cmd_name}: Shows the build log of a local buildchroot
Expand Down Expand Up @@ -4620,6 +4626,8 @@ def do_localbuildlog(self, subcmd, opts, *args):
f.seek(offset)
data = f.read(BUFSIZE)
while len(data):
if opts.strip_time or conf.config['buildlog_strip_time']:
data = buildlog_strip_time(data)
sys.stdout.write(data)
data = f.read(BUFSIZE)
f.close()
Expand Down
7 changes: 6 additions & 1 deletion osc/conf.py
Expand Up @@ -103,6 +103,8 @@ def _get_processors():
'builtin_signature_check': '1', # by default use builtin check for verify pkgs
'icecream': '0',

'buildlog_strip_time': '0', # strips the build time from the build log

'debug': '0',
'http_debug': '0',
'http_full_debug': '0',
Expand Down Expand Up @@ -165,7 +167,7 @@ def _get_processors():
boolean_opts = ['debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', 'plaintext_passwd',
'checkout_no_colon', 'checkout_rooted', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive',
'review_inherit_group', 'use_keyring', 'gnome_keyring', 'no_verify', 'builtin_signature_check', 'http_full_debug',
'include_request_from_project', 'local_service_run']
'include_request_from_project', 'local_service_run', 'buildlog_strip_time']

api_host_options = ['user', 'pass', 'passx', 'aliases', 'http_headers', 'email', 'sslcertck', 'cafile', 'capath', 'trusted_prj']

Expand Down Expand Up @@ -232,6 +234,9 @@ def _get_processors():
# This should not be 0
# build-uid =
# strip leading build time information from the build log
# buildlog_strip_time = 1
# extra packages to install when building packages locally (osc build)
# this corresponds to osc build's -x option and can be overridden with that
# -x '' can also be given on the command line to override this setting, or
Expand Down
10 changes: 9 additions & 1 deletion osc/core.py
Expand Up @@ -5092,7 +5092,13 @@ def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=
raise oscerr.OscIOError(None, 'Content-Length is not matching file size for %s: %i vs %i file size' % (url, cl, read))


def print_buildlog(apiurl, prj, package, repository, arch, offset = 0):
def buildlog_strip_time(data):
"""Strips the leading build time from the log"""
time_regex = re.compile('^\[\s{0,5}\d+s\]\s', re.M)
return time_regex.sub('', data)


def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=False):
"""prints out the buildlog on stdout"""

# to protect us against control characters
Expand All @@ -5107,6 +5113,8 @@ def print_buildlog(apiurl, prj, package, repository, arch, offset = 0):
u = makeurl(apiurl, ['build', prj, repository, arch, package, '_log'], query=query)
for data in streamfile(u):
offset += len(data)
if strip_time:
data = buildlog_strip_time(data)
sys.stdout.write(data.translate(all_bytes, remove_bytes))
if start_offset == offset:
break
Expand Down

0 comments on commit 737bac5

Please sign in to comment.