Rev 6032: Implement the verbosity knob. This lets you: in http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 20 14:59:27 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
------------------------------------------------------------
revno: 6032
revision-id: john at arbash-meinel.com-20110720145917-kd5zn115fm34jl8l
parent: john at arbash-meinel.com-20110718165156-f519epfjwqnq1juw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-up-to-date-609187
timestamp: Wed 2011-07-20 16:59:17 +0200
message:
Implement the verbosity knob. This lets you:
off: disable checking and all messages
minimal: only report one-line summaries when out-of-date
short: only report one-line summaries
all: report multi-line summaries of branch freshness.
all is the default when nothing is set.
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2011-07-18 16:51:56 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2011-07-20 14:59:17 +0000
@@ -40,10 +40,6 @@
# see http://wiki.bazaar.canonical.com/Specs/BranchRegistrationTool
-import time
-
-# Since we are a built-in plugin we share the bzrlib version
-
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
from bzrlib import (
@@ -56,6 +52,7 @@
branch as _mod_branch,
bzrdir,
lazy_regex,
+ # Since we are a built-in plugin we share the bzrlib version
version_info,
)
from bzrlib.commands import (
@@ -502,39 +499,19 @@
info = _get_package_branch_info(the_branch.base)
if info is None:
return
+ c = the_branch.get_config()
+ verbosity = c.get_user_option('bzr.plugins.launchpad.packaging_verbosity')
+ if verbosity is not None:
+ verbosity = verbosity.lower()
+ if verbosity == 'off':
+ trace.mutter('not checking %s because verbosity is turned off'
+ % (the_branch.base,))
+ return
archive, series, project = info
from bzrlib.plugins.launchpad import lp_api_lite
- t = time.time()
latest_pub = lp_api_lite.LatestPublication(archive, series, project)
- latest_ver = latest_pub.get_latest_version()
- t_latest_ver = time.time() - t
- trace.mutter('LatestPublication.get_latest_version took %.3fs'
- % (t_latest_ver,))
- if latest_ver is None:
- trace.note('Could not find a published version for packaging branch:\n'
- ' %s' % (the_branch.base,))
- return
- t = time.time()
- tags = the_branch.tags.get_tag_dict()
- t_tag_dict = time.time() - t
- trace.mutter('LatestPublication get_tag_dict took: %.3fs' % (t_tag_dict,))
- if latest_ver in tags:
- trace.note('Found most recent published version: %s'
- ' in packaging branch:\n %s'
- % (latest_ver, the_branch.base))
- else:
- place = archive.title()
- if series is not None:
- place = '%s/%s' % (place, series.title())
- best_tag = lp_api_lite.get_most_recent_tag(tags, the_branch)
- if best_tag is None:
- best_message = ''
- else:
- best_message = '\nThe most recent tag found is %s' % (best_tag,)
- trace.warning(
- 'Packaging branch is not up-to-date. The most recent published\n'
- 'version in %s is %s, but it is not in the branch tags for:\n %s%s'
- % (place, latest_ver, the_branch.base, best_message))
+ lp_api_lite.report_freshness(the_branch, verbosity, latest_pub)
+
def _register_hooks():
_mod_branch.Branch.hooks.install_named_hook('open',
=== modified file 'bzrlib/plugins/launchpad/lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-18 16:51:56 +0000
+++ b/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-20 14:59:17 +0000
@@ -33,6 +33,7 @@
except ImportError:
json = None
+import time
import urllib
import urllib2
@@ -187,3 +188,61 @@
return reverse_dict[rev_id]
finally:
the_branch.unlock()
+
+
+def report_freshness(the_branch, verbosity, latest_pub):
+ """Report to the user how up-to-date the packaging branch is.
+
+ :param the_branch: A Branch object
+ :param verbosity: Can be one of:
+ off: Do not print anything, and skip all checks.
+ all: Print all information that we have in a verbose manner, this
+ includes misses, etc.
+ short: Print information, but only one-line summaries
+ minimal: Only print a one-line summary when the package branch is
+ out-of-date
+ :param latest_pub: A LatestPublication instance
+ """
+ if verbosity == 'off':
+ return
+ if verbosity is None:
+ verbosity = 'all'
+ t = time.time()
+ latest_ver = latest_pub.get_latest_version()
+ t_latest_ver = time.time() - t
+ trace.mutter('LatestPublication.get_latest_version took: %.3fs'
+ % (t_latest_ver,))
+ place = latest_pub._archive.title()
+ if latest_pub._series is not None:
+ place = '%s %s' % (place, latest_pub._series.title())
+ if latest_ver is None:
+ if verbosity == 'all':
+ trace.note('Most recent %s version: MISSING' % (place,))
+ elif verbosity == 'short':
+ trace.note('%s is MISSING a version' % (place,))
+ return
+ t = time.time()
+ tags = the_branch.tags.get_tag_dict()
+ t_tag_dict = time.time() - t
+ trace.mutter('LatestPublication.get_tag_dict took: %.3fs' % (t_tag_dict,))
+ if latest_ver in tags:
+ if verbosity == 'minimal':
+ return
+ elif verbosity == 'short':
+ trace.note('%s is CURRENT in %s' % (latest_ver, place))
+ else:
+ trace.note('Most recent %s version: %s\n'
+ 'Packaging branch status: CURRENT'
+ % (place, latest_ver))
+ else:
+ best_tag = get_most_recent_tag(tags, the_branch)
+ if verbosity in ('minimal', 'short'):
+ if best_tag is None:
+ best_tag = 'Branch'
+ trace.warning('%s is OUT-OF-DATE, %s has %s'
+ % (best_tag, place, latest_ver))
+ else:
+ trace.warning('Most recent %s version: %s\n'
+ 'Packaging branch version: %s\n'
+ 'Packaging branch status: OUT-OF-DATE'
+ % (place, latest_ver, best_tag))
=== modified file 'bzrlib/plugins/launchpad/test_lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-18 16:51:56 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-20 14:59:17 +0000
@@ -17,12 +17,16 @@
"""Tools for dealing with the Launchpad API without using launchpadlib.
"""
+import doctest
import socket
from bzrlib import tests
from bzrlib.plugins import launchpad
from bzrlib.plugins.launchpad import lp_api_lite
+from testtools.matchers import DocTestMatches
+
+
class _JSONParserFeature(tests.Feature):
def _probe(self):
@@ -348,3 +352,152 @@
self.assertEqual('B', b.last_revision())
self.assertEqual('tip-1.0',
lp_api_lite.get_most_recent_tag(tag_dict, b))
+
+
+class StubLatestPublication(object):
+
+ def __init__(self, latest):
+ self.called = False
+ self.latest = latest
+ self._archive = 'ubuntu'
+ self._series = 'natty'
+
+ def get_latest_version(self):
+ self.called = True
+ return self.latest
+
+
+class TestReportFreshness(tests.TestCaseWithMemoryTransport):
+
+ def make_trivial_branch(self):
+ builder = self.make_branch_builder('tip')
+ builder.build_snapshot('A', [], [
+ ('add', ('', 'root-id', 'directory', None))])
+ b = builder.get_branch()
+ return b
+
+ def assertFreshnessReports(self, the_branch, verbosity, latest_version,
+ content):
+ """Assert that lp_api_lite.report_freshness reports the given content.
+
+ :param the_branch: The branch we are inspecting
+ :param verbosity: The reporting level
+ :param latest_version: The version reported by StubLatestPublication
+ :param content: The expected content. This should be in DocTest form.
+ """
+ orig_log_len = len(self.get_log())
+ lp_api_lite.report_freshness(the_branch, verbosity,
+ StubLatestPublication(latest_version))
+ new_content = self.get_log()[orig_log_len:]
+ # Strip out lines that have LatestPublication.get_* because those are
+ # timing related lines. While interesting to log for now, they aren't
+ # something we want to be testing
+ new_content = new_content.split('\n')
+ for i in range(2):
+ if (len(new_content) > 0
+ and 'LatestPublication.get_' in new_content[0]):
+ new_content = new_content[1:]
+ new_content = '\n'.join(new_content)
+ self.assertThat(new_content,
+ DocTestMatches(content,
+ doctest.ELLIPSIS | doctest.REPORT_UDIFF))
+
+ def test_verbosity_off_skips_check(self):
+ b = self.make_trivial_branch()
+ # We force _get_package_branch_info so that we know it would otherwise
+ # try to connect to launcphad
+ self.overrideAttr(launchpad, '_get_package_branch_info',
+ lambda x: ('ubuntu', 'natty', 'bzr'))
+ self.overrideAttr(lp_api_lite, 'LatestPublication',
+ lambda *args: self.fail('Tried to query launchpad'))
+ c = b.get_config()
+ c.set_user_option('bzr.plugins.launchpad.packaging_verbosity', 'off')
+ orig_log_len = len(self.get_log())
+ launchpad._check_is_up_to_date(b)
+ new_content = self.get_log()[orig_log_len:]
+ self.assertContainsRe(new_content,
+ 'not checking memory.*/tip/ because verbosity is turned off')
+
+ def test_verbosity_off(self):
+ b = self.make_trivial_branch()
+ latest_pub = StubLatestPublication('1.0-1ubuntu2')
+ lp_api_lite.report_freshness(b, 'off', latest_pub)
+ self.assertFalse(latest_pub.called)
+
+ def test_verbosity_minimal_no_tags(self):
+ b = self.make_trivial_branch()
+ self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
+ ' WARNING Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
+
+ def test_verbosity_minimal_out_of_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
+ ' WARNING 1.0-1ubuntu1 is OUT-OF-DATE,'
+ ' Ubuntu Natty has 1.0-1ubuntu2\n')
+
+ def test_verbosity_minimal_up_to_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
+ '')
+
+ def test_verbosity_minimal_missing(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'minimal', None,
+ '')
+
+ def test_verbosity_short_out_of_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
+ ' WARNING 1.0-1ubuntu1 is OUT-OF-DATE,'
+ ' Ubuntu Natty has 1.0-1ubuntu2\n')
+
+ def test_verbosity_short_up_to_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
+ ' INFO 1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
+
+ def test_verbosity_short_missing(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'short', None,
+ ' INFO Ubuntu Natty is MISSING a version')
+
+ def test_verbosity_all_no_tags(self):
+ b = self.make_trivial_branch()
+ self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
+ ' WARNING Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
+ 'Packaging branch version: None\n'
+ 'Packaging branch status: OUT-OF-DATE\n')
+
+ def test_verbosity_all_out_of_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
+ ' WARNING Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
+ 'Packaging branch version: 1.0-1ubuntu1\n'
+ 'Packaging branch status: OUT-OF-DATE\n')
+
+ def test_verbosity_all_up_to_date(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
+ ' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
+ 'Packaging branch status: CURRENT\n')
+
+ def test_verbosity_all_missing(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, 'all', None,
+ ' INFO Most recent Ubuntu Natty version: MISSING\n')
+
+ def test_verbosity_None_is_all(self):
+ b = self.make_trivial_branch()
+ b.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(b, None, '1.0-1ubuntu2',
+ ' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
+ 'Packaging branch status: CURRENT\n')
More information about the bazaar-commits
mailing list