summaryrefslogtreecommitdiff
diff options
authorRobert C Jennings <robert.jennings@canonical.com>2017-06-26 13:03:19 -0500
committerRobert C Jennings <robert.jennings@canonical.com>2017-06-26 13:03:19 -0500
commit507eab3f66bcc4a4ea557a0c5a68bf51f73a8f5b (patch)
tree8488b9e2dce6a9a1c087ba54177d0986e4d607bc
parentefabe30f7686ce358eb5371612e84f45dd2f9f06 (diff)
Break out changelog processing from main
bzr-revno: 18.2.18
-rwxr-xr-xmfdiff181
1 files changed, 101 insertions, 80 deletions
diff --git a/mfdiff b/mfdiff
index e974d79..eb81cdb 100755
--- a/mfdiff
+++ b/mfdiff
@@ -398,6 +398,105 @@ def filter_changelog(changelog_path, version_start, version_end):
return change_blocks, error_msg
+def print_changelogs(cache_d, manifest_from, manifest_to, changed):
+ """
+ Print changelog entries for each changed package limited to
+ changes in the package between the versions in the two manifests.
+
+ :param str cache_d: Path to the apt cache directory
+ :param dict manifest_from: Packages and their versions in the
+ first manifest file
+ :param dict manifest_to: Packages and their versions in the
+ second manifest file
+ :param list changed: Packages which changed between the two manifests
+ """
+
+ srcs = {}
+ exceptions = []
+ cache = get_cache(cache_d)
+ src2bins = map_source_to_binary(cache, changed)
+
+ # Generate changelog data per unique source package
+ srcs = {}
+ exceptions = []
+ cache = get_cache(cache_d)
+
+ src2bins = map_source_to_binary(cache, changed)
+
+ # Generate changelog data per unique source package
+ for src in src2bins:
+ srcs[src] = {"changelog_file": "", "changeblocks": []}
+
+ # Use the first binary listed for a source package
+ binary = src2bins[src][0]
+
+ # Find the source version data for the binary in manifest #2
+ binver_to = manifest_to[binary]
+ try:
+ srcver_to = source_version_for_binary(
+ cache, binary, binver_to)
+ except UnknownSourceVersionError as excp:
+ logging.error(excp.message)
+ exceptions.append(excp)
+ continue
+
+ # Find the source version data for the binary in manifest #1
+ binver_from = manifest_from[binary]
+ try:
+ srcver_from = source_version_for_binary(
+ cache, binary, binver_from)
+ except UnknownSourceVersionError as excp:
+ if binver_to == srcver_to:
+ logging.info('Could not find source version data in apt '
+ 'cache. Assuming source %s version %s from '
+ 'binary %s', src, binver_from, binary)
+ srcver_from = binver_from
+ else:
+ logging.error(excp.message)
+ exceptions.append(excp)
+ continue
+
+ try:
+ if version_compare(srcver_from, srcver_to) > 0:
+ msg = "Package version regression {} -> {}".format(
+ srcver_from, srcver_to)
+ raise UnknownSourceVersionError(msg)
+ except UnknownSourceVersionError as excp:
+ exceptions.append(excp)
+ continue
+
+ try:
+ changelog_path = getchangelog(src, srcver_to, cache_d)
+ except MissingChangelogError as excp:
+ exceptions.append(excp)
+ continue
+
+ srcs[src]["changelog_file"] = changelog_path
+
+ try:
+ srcs[src]["changeblocks"], incomplete = filter_changelog(
+ changelog_path, srcver_from, srcver_to)
+ if incomplete:
+ raise ChangelogMissingVersion(incomplete)
+ except ChangelogMissingVersion as exp:
+ exceptions.append(exp)
+ continue
+
+ # Print changelog ranges for changed packages
+ for src in sorted(src2bins):
+ binlist = sorted(src2bins[src])
+ binary = binlist[0]
+ print("==== %s: %s => %s ====" %
+ (src, manifest_from[binary], manifest_to[binary]))
+ print("==== %s" % ' '.join(binlist))
+ print_blocks(srcs[src]["changeblocks"])
+
+ if exceptions:
+ print("**** Errors ****")
+ for error in exceptions:
+ print(error)
+
+
def parse_args():
"""
Parse command line arguments
@@ -468,88 +567,10 @@ def main():
print("removed: %s" % removed)
print("changed: %s" % changed)
- cache_d = prep_cacheroot(arch, release, options.cache_d)
-
# if modified packages, download all changelogs from changelogs.
if changed:
- srcs = {}
- exceptions = []
- cache = get_cache(cache_d)
-
- src2bins = map_source_to_binary(cache, changed)
-
- # Generate changelog data per unique source package
- for src in src2bins:
- srcs[src] = {"changelog_file": "", "changeblocks": []}
-
- # Use the first binary listed for a source package
- binary = src2bins[src][0]
-
- # Find the source version data for the binary in manifest #2
- binver_to = manifest_to[binary]
- try:
- srcver_to = source_version_for_binary(
- cache, binary, binver_to)
- except UnknownSourceVersionError as excp:
- logging.error(excp.message)
- exceptions.append(excp)
- continue
-
- # Find the source version data for the binary in manifest #1
- binver_from = manifest_from[binary]
- try:
- srcver_from = source_version_for_binary(
- cache, binary, binver_from)
- except UnknownSourceVersionError as excp:
- if binver_to == srcver_to:
- logging.info('Could not find source version data in apt '
- 'cache. Assuming source %s version %s from '
- 'binary %s', src, binver_from, binary)
- srcver_from = binver_from
- else:
- logging.error(excp.message)
- exceptions.append(excp)
- continue
-
- try:
- if version_compare(srcver_from, srcver_to) > 0:
- msg = "Package version regression {} -> {}".format(
- srcver_from, srcver_to)
- raise UnknownSourceVersionError(msg)
- except UnknownSourceVersionError as excp:
- exceptions.append(excp)
- continue
-
- try:
- changelog_path = getchangelog(src, srcver_to, cache_d)
- except MissingChangelogError as excp:
- exceptions.append(excp)
- continue
-
- srcs[src]["changelog_file"] = changelog_path
-
- try:
- srcs[src]["changeblocks"], incomplete = filter_changelog(
- changelog_path, srcver_from, srcver_to)
- if incomplete:
- raise ChangelogMissingVersion(incomplete)
- except ChangelogMissingVersion as exp:
- exceptions.append(exp)
- continue
-
- # Print changelog ranges for changed packages
- for src in sorted(src2bins):
- binlist = sorted(src2bins[src])
- binary = binlist[0]
- print("==== %s: %s => %s ====" %
- (src, manifest_from[binary], manifest_to[binary]))
- print("==== %s" % ' '.join(binlist))
- print_blocks(srcs[src]["changeblocks"])
-
- if exceptions:
- print("**** Errors ****")
- for error in exceptions:
- print(error)
+ cache_d = prep_cacheroot(arch, release, options.cache_d)
+ print_changelogs(cache_d, manifest_from, manifest_to, changed)
if __name__ == "__main__":