autopkgtest.py: Factorize logging into helper methods

bzr-import-20160707
Martin Pitt 10 years ago
parent 65a1d73164
commit a3a523b4ed

@ -55,6 +55,13 @@ class AutoPackageTest(object):
self.read() self.read()
self.rc_path = None self.rc_path = None
def log_verbose(self, msg):
if self.britney.options.verbose:
print('I: [%s] - %s' % (time.asctime(), msg))
def log_error(self, msg):
print('E: [%s] - %s' % (time.asctime(), msg))
def _ensure_rc_file(self): def _ensure_rc_file(self):
if self.rc_path: if self.rc_path:
return return
@ -164,9 +171,8 @@ class AutoPackageTest(object):
request_file.write(line) request_file.write(line)
else: else:
if self.britney.options.verbose: if self.britney.options.verbose:
print("I: [%s] - Requested autopkgtest for %s but " self.log_verbose("Requested autopkgtest for %s but "
"run_autopkgtest set to False" % "run_autopkgtest set to False" % src)
(time.asctime(), src))
for linebits in self._parse(request_path): for linebits in self._parse(request_path):
# Make sure that there's an entry in pkgcauses for each new # Make sure that there's an entry in pkgcauses for each new
@ -176,8 +182,8 @@ class AutoPackageTest(object):
src = linebits.pop(0) src = linebits.pop(0)
ver = linebits.pop(0) ver = linebits.pop(0)
if self.britney.options.verbose: if self.britney.options.verbose:
print("I: [%s] - Requested autopkgtest for %s_%s (%s)" % self.log_verbose("Requested autopkgtest for %s_%s (%s)" %
(time.asctime(), src, ver, " ".join(linebits))) (src, ver, " ".join(linebits)))
try: try:
status = linebits.pop(0).upper() status = linebits.pop(0).upper()
while True: while True:
@ -211,10 +217,9 @@ class AutoPackageTest(object):
for trigsrc in sorted(self.pkglist[src][ver]['causes']): for trigsrc in sorted(self.pkglist[src][ver]['causes']):
for trigver, status \ for trigver, status \
in self.pkglist[src][ver]['causes'][trigsrc]: in self.pkglist[src][ver]['causes'][trigsrc]:
print("I: [%s] - Collected autopkgtest status " self.log_verbose("Collected autopkgtest status "
"for %s_%s/%s_%s: " "%s" % ( "for %s_%s/%s_%s: " "%s" %
time.asctime(), src, ver, trigsrc, (src, ver, trigsrc, trigver, status))
trigver, status))
def results(self, trigsrc, trigver): def results(self, trigsrc, trigver):
for status, src, ver in self.pkgcauses[trigsrc][trigver]: for status, src, ver in self.pkgcauses[trigsrc][trigver]:

Loading…
Cancel
Save