britney: Replace all calls to "log" with logger

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 7 years ago
parent 8bf73610ee
commit b23777c852

@ -300,7 +300,7 @@ class Britney(object):
self.read_hints(os.path.join(self.suite_info['unstable'].path, 'Hints'))
if self.options.nuninst_cache:
self.log("Not building the list of non-installable packages, as requested", type="I")
self.logger.info("Not building the list of non-installable packages, as requested")
if self.options.print_uninst:
nuninst = self.get_nuninst(build=False)
print('* summary')
@ -340,34 +340,34 @@ class Britney(object):
constraints_file = os.path.join(self.options.static_input_dir, 'constraints')
faux_packages = os.path.join(self.options.static_input_dir, 'faux-packages')
except AttributeError:
self.log("The static_input_dir option is not set", type='I')
self.logger.info("The static_input_dir option is not set")
constraints_file = None
faux_packages = None
if faux_packages is not None and os.path.exists(faux_packages):
self.log("Loading faux packages from %s" % faux_packages, type='I')
self.logger.info("Loading faux packages from %s" % faux_packages)
self._load_faux_packages(faux_packages)
elif faux_packages is not None:
self.log("No Faux packages as %s does not exist" % faux_packages, type='I')
self.logger.info("No Faux packages as %s does not exist" % faux_packages)
if constraints_file is not None and os.path.exists(constraints_file):
self.log("Loading constraints from %s" % constraints_file, type='I')
self.logger.info("Loading constraints from %s" % constraints_file)
self.constraints = self._load_constraints(constraints_file)
else:
if constraints_file is not None:
self.log("No constraints as %s does not exist" % constraints_file, type='I')
self.logger.info("No constraints as %s does not exist" % constraints_file)
self.constraints = {
'keep-installable': [],
}
self.log("Compiling Installability tester", type="I")
self.logger.info("Compiling Installability tester")
self._inst_tester = build_installability_tester(self.binaries, self.options.architectures)
if not self.options.nuninst_cache:
self.log("Building the list of non-installable packages for the full archive", type="I")
self.logger.info("Building the list of non-installable packages for the full archive")
self._inst_tester.compute_testing_installability()
nuninst = self.get_nuninst(build=True)
for arch in self.options.architectures:
self.log("> Found %d non-installable packages" % len(nuninst[arch]), type="I")
self.logger.info("> Found %d non-installable packages" % len(nuninst[arch]))
if self.options.print_uninst:
self.nuninst_arch_report(nuninst, arch)
@ -379,12 +379,12 @@ class Britney(object):
write_nuninst(self.options.noninst_status, nuninst)
stats = self._inst_tester.compute_stats()
self.log("> Installability tester statistics (per architecture)", type="I")
self.logger.info("> Installability tester statistics (per architecture)")
for arch in self.options.architectures:
arch_stat = stats[arch]
self.log("> %s" % arch, type="I")
self.logger.info("> %s" % arch)
for stat in arch_stat.stat_summary():
self.log("> - %s" % stat, type="I")
self.logger.info("> - %s" % stat)
for policy in self.policies:
policy.hints = self.hints
@ -398,10 +398,10 @@ class Britney(object):
bad.append((f, pkg_entry1[f], pkg_entry2[f]))
if bad: # pragma: no cover
self.log("Mismatch found %s %s %s differs" % (
package, pkg_entry1.version, parch), type="E")
self.logger.error("Mismatch found %s %s %s differs" % (
package, pkg_entry1.version, parch))
for f, v1, v2 in bad:
self.log(" ... %s %s != %s" % (check_field_name[f], v1, v2))
self.logger.info(" ... %s %s != %s" % (check_field_name[f], v1, v2))
raise ValueError("Invalid data set")
# Merge ESSENTIAL if necessary
@ -450,11 +450,11 @@ class Britney(object):
# integrity checks
if self.options.nuninst_cache and self.options.print_uninst: # pragma: no cover
self.log("nuninst_cache and print_uninst are mutually exclusive!", type="E")
self.logger.error("nuninst_cache and print_uninst are mutually exclusive!")
sys.exit(1)
# if the configuration file exists, then read it and set the additional options
elif not os.path.isfile(self.options.config): # pragma: no cover
self.log("Unable to read the configuration file (%s), exiting!" % self.options.config, type="E")
self.logger.error("Unable to read the configuration file (%s), exiting!" % self.options.config)
sys.exit(1)
# minimum days for unstable-testing transition and the list of hints
@ -484,29 +484,29 @@ class Britney(object):
self.suite_info[suite] = SuiteInfo(name=suite, path=suite_path, excuses_suffix=suffix)
else:
if suite in {'testing', 'unstable'}: # pragma: no cover
self.log("Mandatory configuration %s is not set in the config" % suite.upper(), type='E')
self.logger.error("Mandatory configuration %s is not set in the config" % suite.upper())
sys.exit(1)
self.log("Optional suite %s is not defined (config option: %s) " % (suite, suite.upper()))
self.logger.info("Optional suite %s is not defined (config option: %s) " % (suite, suite.upper()))
try:
release_file = read_release_file(self.suite_info['testing'].path)
self.log("Found a Release file in testing - using that for defaults")
self.logger.info("Found a Release file in testing - using that for defaults")
except FileNotFoundError:
self.log("Testing does not have a Release file.")
self.logger.info("Testing does not have a Release file.")
release_file = None
if getattr(self.options, "components", None):
self.options.components = [s.strip() for s in self.options.components.split(",")]
elif release_file and not self.options.control_files:
self.options.components = release_file['Components'].split()
self.log("Using components listed in Release file: %s" % ' '.join(self.options.components))
self.logger.info("Using components listed in Release file: %s" % ' '.join(self.options.components))
else:
self.options.components = None
if self.options.control_files and self.options.components: # pragma: no cover
# We cannot regenerate the control files correctly when reading from an
# actual mirror (we don't which package goes in what component etc.).
self.log("Cannot use --control-files with mirror-layout (components)!", type="E")
self.logger.error("Cannot use --control-files with mirror-layout (components)!")
sys.exit(1)
if not hasattr(self.options, "heidi_delta_output"):
@ -522,12 +522,12 @@ class Britney(object):
allarches = sorted(self.options.architectures.split())
else:
if not release_file: # pragma: no cover
self.log("No configured architectures and there is no release file for testing", type="E")
self.log("Please check if there is a \"Release\" file in %s" % self.suite_info['testing'].path, type="E")
self.log("or if the config file contains a non-empty \"ARCHITECTURES\" field", type="E")
self.logger.error("No configured architectures and there is no release file for testing")
self.logger.error("Please check if there is a \"Release\" file in %s" % self.suite_info['testing'].path)
self.logger.error("or if the config file contains a non-empty \"ARCHITECTURES\" field")
sys.exit(1)
allarches = sorted(release_file['Architectures'].split())
self.log("Using architectures listed in Release file: %s" % ' '.join(allarches))
self.logger.info("Using architectures listed in Release file: %s" % ' '.join(allarches))
arches = [x for x in allarches if x in self.options.nobreakall_arches]
arches += [x for x in allarches if x not in arches and x not in self.options.outofsync_arches]
arches += [x for x in allarches if x not in arches and x not in self.options.break_arches]
@ -552,22 +552,6 @@ class Britney(object):
def hints(self):
return self._hint_parser.hints
def log(self, msg, type="I"):
"""Print info messages according to verbosity level
An easy-and-simple log method which prints messages to the standard
output. The type parameter controls the urgency of the message, and
can be equal to `I' for `Information', `W' for `Warning' and `E' for
`Error'. Warnings and errors are always printed, and information is
printed only if verbose logging is enabled.
"""
level = {
'I': logging.INFO,
'W': logging.WARNING,
'E': logging.ERROR,
}.get(type, logging.INFO)
self.logger.log(level, msg)
def _load_faux_packages(self, faux_packages_file):
"""Loads fake packages
@ -672,7 +656,7 @@ class Britney(object):
if constraint not in {'present-and-installable'}: # pragma: no cover
raise ValueError("Unsupported constraint %s for %s (file %s)" % (constraint, pkg_name, constraints_file))
self.log(" - constraint %s" % pkg_name, type='I')
self.logger.info(" - constraint %s" % pkg_name)
pkg_list = [x.strip() for x in mandatory_field('Package-List').split("\n") if x.strip() != '' and not x.strip().startswith("#")]
src_data = SourcePackage(faux_version,
@ -746,11 +730,11 @@ class Britney(object):
for component in self.options.components:
filename = os.path.join(basedir, component, "source", "Sources")
filename = possibly_compressed(filename)
self.log("Loading source packages from %s" % filename)
self.logger.info("Loading source packages from %s" % filename)
read_sources_file(filename, sources)
else:
filename = os.path.join(basedir, "Sources")
self.log("Loading source packages from %s" % filename)
self.logger.info("Loading source packages from %s" % filename)
sources = read_sources_file(filename)
return sources
@ -761,13 +745,13 @@ class Britney(object):
for or_clause in parts:
if len(or_clause) != 1: # pragma: no cover
msg = "Ignoring invalid provides in %s: Alternatives [%s]" % (str(pkg_id), str(or_clause))
self.log(msg, type='W')
self.logger.warning(msg)
continue
for part in or_clause:
provided, provided_version, op = part
if op != '' and op != '=': # pragma: no cover
msg = "Ignoring invalid provides in %s: %s (%s %s)" % (str(pkg_id), provided, op, provided_version)
self.log(msg, type='W')
self.logger.warning(msg)
continue
provided = sys.intern(provided)
provided_version = sys.intern(provided_version)
@ -776,7 +760,7 @@ class Britney(object):
return nprov
def _read_packages_file(self, filename, arch, srcdist, packages=None, intern=sys.intern):
self.log("Loading binary packages from %s" % filename)
self.logger.info("Loading binary packages from %s" % filename)
if packages is None:
packages = {}
@ -929,7 +913,8 @@ class Britney(object):
for arch in architectures:
packages = {}
if arch not in listed_archs:
self.log("Skipping arch %s for %s: It is not listed in the Release file" % (arch, distribution))
self.logger.info("Skipping arch %s for %s: It is not listed in the Release file" % (
arch, distribution))
arch2packages[arch] = ({}, {})
continue
for component in self.options.components:
@ -993,9 +978,9 @@ class Britney(object):
else:
filename = os.path.join(hintsdir, who)
if not os.path.isfile(filename):
self.log("Cannot read hints list from %s, no such file!" % filename, type="E")
self.logger.error("Cannot read hints list from %s, no such file!" % filename)
continue
self.log("Loading hints list from %s" % filename)
self.logger.info("Loading hints list from %s" % filename)
with open(filename, encoding='utf-8') as f:
self._hint_parser.parse_hints(who, self.HINTS[who], filename, f)
@ -1011,25 +996,24 @@ class Britney(object):
if x in ['unblock', 'unblock-udeb']:
if apt_pkg.version_compare(hint2.version, hint.version) < 0:
# This hint is for a newer version, so discard the old one
self.log("Overriding %s[%s] = ('%s', '%s') with ('%s', '%s')" %
(x, package, hint2.version, hint2.user, hint.version, hint.user), type="W")
self.logger.warning("Overriding %s[%s] = ('%s', '%s') with ('%s', '%s')" %
(x, package, hint2.version, hint2.user, hint.version, hint.user))
hint2.set_active(False)
else:
# This hint is for an older version, so ignore it in favour of the new one
self.log("Ignoring %s[%s] = ('%s', '%s'), ('%s', '%s') is higher or equal" %
(x, package, hint.version, hint.user, hint2.version, hint2.user), type="W")
self.logger.warning("Ignoring %s[%s] = ('%s', '%s'), ('%s', '%s') is higher or equal" %
(x, package, hint.version, hint.user, hint2.version, hint2.user))
hint.set_active(False)
else:
self.log("Overriding %s[%s] = ('%s', '%s') with ('%s', '%s')" %
(x, package, hint2.user, hint2, hint.user, hint),
type="W")
self.logger.warning("Overriding %s[%s] = ('%s', '%s') with ('%s', '%s')" %
(x, package, hint2.user, hint2, hint.user, hint))
hint2.set_active(False)
z[package] = key
# Sanity check the hints hash
if len(hints["block"]) == 0 and len(hints["block-udeb"]) == 0:
self.log("WARNING: No block hints at all, not even udeb ones!", type="W")
self.logger.warning("WARNING: No block hints at all, not even udeb ones!")
# Utility methods for package analysis
# ------------------------------------
@ -1567,7 +1551,7 @@ class Britney(object):
of this procedure, please refer to the module docstring.
"""
self.log("Update Excuses generation started", type="I")
self.logger.info("Update Excuses generation started")
# list of local methods and variables (for better performance)
sources = self.sources
@ -1687,16 +1671,16 @@ class Britney(object):
# write excuses to the output file
if not self.options.dry_run:
self.log("> Writing Excuses to %s" % self.options.excuses_output, type="I")
self.logger.info("> Writing Excuses to %s" % self.options.excuses_output)
sorted_excuses = sorted(excuses.values(), key=lambda x: x.sortkey())
write_excuses(sorted_excuses, self.options.excuses_output,
output_format="legacy-html")
if hasattr(self.options, 'excuses_yaml_output'):
self.log("> Writing YAML Excuses to %s" % self.options.excuses_yaml_output, type="I")
self.logger.info("> Writing YAML Excuses to %s" % self.options.excuses_yaml_output)
write_excuses(sorted_excuses, self.options.excuses_yaml_output,
output_format="yaml")
self.log("Update Excuses generation completed", type="I")
self.logger.info("Update Excuses generation completed")
# Upgrade run
# -----------
@ -2392,14 +2376,14 @@ class Britney(object):
self.output_write("\n")
def assert_nuninst_is_correct(self):
self.log("> Update complete - Verifying non-installability counters", type="I")
self.logger.info("> Update complete - Verifying non-installability counters")
cached_nuninst = self.nuninst_orig
self._inst_tester.compute_testing_installability()
computed_nuninst = self.get_nuninst(build=True)
if cached_nuninst != computed_nuninst: # pragma: no cover
only_on_break_archs = True
self.log("==================== NUNINST OUT OF SYNC =========================", type="E")
self.logger.error("==================== NUNINST OUT OF SYNC =========================")
for arch in self.options.architectures:
expected_nuninst = set(cached_nuninst[arch])
actual_nuninst = set(computed_nuninst[arch])
@ -2410,18 +2394,17 @@ class Britney(object):
if (false_negatives or false_positives) and arch not in self.options.break_arches:
only_on_break_archs = False
if false_negatives:
self.log(" %s - unnoticed nuninst: %s" % (arch, str(false_negatives)), type="E")
self.logger.error(" %s - unnoticed nuninst: %s" % (arch, str(false_negatives)))
if false_positives:
self.log(" %s - invalid nuninst: %s" % (arch, str(false_positives)), type="E")
self.log(" %s - actual nuninst: %s" % (arch, str(actual_nuninst)), type="I")
self.log("==================== NUNINST OUT OF SYNC =========================", type="E")
self.logger.error(" %s - invalid nuninst: %s" % (arch, str(false_positives)))
self.logger.info(" %s - actual nuninst: %s" % (arch, str(actual_nuninst)))
self.logger.error("==================== NUNINST OUT OF SYNC =========================")
if not only_on_break_archs:
raise AssertionError("NUNINST OUT OF SYNC")
else:
self.log("Nuninst is out of sync on some break arches",
type="W")
self.logger.warning("Nuninst is out of sync on some break arches")
self.log("> All non-installability counters are ok", type="I")
self.logger.info("> All non-installability counters are ok")
def upgrade_testing(self):
@ -2432,11 +2415,11 @@ class Britney(object):
commands.
"""
self.log("Starting the upgrade test", type="I")
self.logger.info("Starting the upgrade test")
self.output_write("Generated on: %s\n" % (time.strftime("%Y.%m.%d %H:%M:%S %z", time.gmtime(time.time()))))
self.output_write("Arch order is: %s\n" % ", ".join(self.options.architectures))
self.log("> Calculating current uninstallability counters", type="I")
self.logger.info("> Calculating current uninstallability counters")
self.nuninst_orig = self.get_nuninst()
# nuninst_orig may get updated during the upgrade process
self.nuninst_orig_save = self.get_nuninst()
@ -2492,7 +2475,7 @@ class Britney(object):
# obsolete source packages
# a package is obsolete if none of the binary packages in testing
# are built by it
self.log("> Removing obsolete source packages from testing", type="I")
self.logger.info("> Removing obsolete source packages from testing")
# local copies for performance
sources = self.sources['testing']
binaries = self.binaries['testing']
@ -2510,15 +2493,15 @@ class Britney(object):
# smooth updates
removals = old_libraries(self.sources, self.binaries, self.options.outofsync_arches)
if self.options.smooth_updates:
self.log("> Removing old packages left in testing from smooth updates", type="I")
self.logger.info("> Removing old packages left in testing from smooth updates")
if removals:
self.output_write("Removing packages left in testing for smooth updates (%d):\n%s" % \
(len(removals), old_libraries_format(removals)))
self.do_all(actions=removals)
removals = old_libraries(self.sources, self.binaries, self.options.outofsync_arches)
else:
self.log("> Not removing old packages left in testing from smooth updates (smooth-updates disabled)",
type="I")
self.logger.info("> Not removing old packages left in testing from smooth updates"
" (smooth-updates disabled)")
self.output_write("List of old libraries in testing (%d):\n%s" % \
(len(removals), old_libraries_format(removals)))
@ -2529,7 +2512,7 @@ class Britney(object):
if not self.options.dry_run:
# re-write control files
if self.options.control_files:
self.log("Writing new testing control files to %s" %
self.logger.info("Writing new testing control files to %s" %
self.suite_info['testing'].path)
write_controlfiles(self.sources, self.binaries,
'testing', self.suite_info['testing'].path)
@ -2538,21 +2521,21 @@ class Britney(object):
policy.save_state(self)
# write HeidiResult
self.log("Writing Heidi results to %s" % self.options.heidi_output)
self.logger.info("Writing Heidi results to %s" % self.options.heidi_output)
write_heidi(self.options.heidi_output, self.sources["testing"],
self.binaries["testing"],
outofsync_arches=self.options.outofsync_arches)
self.log("Writing delta to %s" % self.options.heidi_delta_output)
self.logger.info("Writing delta to %s" % self.options.heidi_delta_output)
write_heidi_delta(self.options.heidi_delta_output,
self.all_selected)
self.printuninstchange()
self.log("Test completed!", type="I")
self.logger.info("Test completed!")
def printuninstchange(self):
self.log("Checking for newly uninstallable packages", type="I")
self.logger.info("Checking for newly uninstallable packages")
text = eval_uninst(self.options.architectures, newly_uninst(
self.nuninst_orig_save, self.nuninst_orig))
@ -2566,7 +2549,7 @@ class Britney(object):
This method provides a command line interface for the release team to
try hints and evaluate the results.
"""
self.log("> Calculating current uninstallability counters", type="I")
self.logger.info("> Calculating current uninstallability counters")
self.nuninst_orig = self.get_nuninst()
self.nuninst_orig_save = self.get_nuninst()
@ -2613,7 +2596,7 @@ class Britney(object):
try:
readline.write_history_file(histfile)
except IOError as e:
self.log("Could not write %s: %s" % (histfile, e), type="W")
self.logger.warning("Could not write %s: %s" % (histfile, e))
def do_hint(self, hinttype, who, pkgvers):
"""Process hints
@ -2627,7 +2610,7 @@ class Britney(object):
else:
_pkgvers = pkgvers
self.log("> Processing '%s' hint from %s" % (hinttype, who), type="I")
self.logger.info("> Processing '%s' hint from %s" % (hinttype, who))
self.output_write("Trying %s from %s: %s\n" % (hinttype, who, " ".join("%s/%s" % (x.uvname, x.version) for x in _pkgvers)))
ok = True
@ -2683,7 +2666,7 @@ class Britney(object):
excuses relationships. If they build a circular dependency, which we already
know as not-working with the standard do_all algorithm, try to `easy` them.
"""
self.log("> Processing hints from the auto hinter", type="I")
self.logger.info("> Processing hints from the auto hinter")
sources_t = self.sources['testing']
excuses = self.excuses
@ -2802,11 +2785,11 @@ class Britney(object):
else:
self.upgrade_testing()
self.log('> Stats from the installability tester', type="I")
self.logger.info('> Stats from the installability tester')
for stat in self._inst_tester.stats.stats():
self.log('> %s' % stat, type="I")
self.logger.info('> %s' % stat)
else:
self.log('Migration computation skipped as requested.', type='I')
self.logger.info('Migration computation skipped as requested.')
logging.shutdown()

Loading…
Cancel
Save