Rev 6034: Try refactoring the code a bit per vila's suggestions. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-verbosity-knob-812928
John Arbash Meinel
john at arbash-meinel.com
Fri Jul 22 10:59:49 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-verbosity-knob-812928
------------------------------------------------------------
revno: 6034
revision-id: john at arbash-meinel.com-20110722105928-ucxdvw8vcidnh4iu
parent: john at arbash-meinel.com-20110720151704-xch56jmjr6243nrl
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-verbosity-knob-812928
timestamp: Fri 2011-07-22 12:59:28 +0200
message:
Try refactoring the code a bit per vila's suggestions.
The problem is that late-binding of values like 'best_tag' mean you
have to pass around a fair amount of state between the helper functions.
I really don't want to always compute most-recent tag in the case that
things are up-to-date, but maybe I can do a little bit better.
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2011-07-20 15:05:29 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2011-07-22 10:59:28 +0000
@@ -500,7 +500,7 @@
if info is None:
return
c = the_branch.get_config()
- verbosity = c.get_user_option('bzr.plugins.launchpad.packaging_verbosity')
+ verbosity = c.get_user_option('launchpad.packaging_verbosity')
if verbosity is not None:
verbosity = verbosity.lower()
if verbosity == 'off':
=== modified file 'bzrlib/plugins/launchpad/lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-20 15:05:29 +0000
+++ b/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-22 10:59:28 +0000
@@ -205,39 +205,36 @@
the_branch.unlock()
-def report_freshness(the_branch, verbosity, latest_pub):
- """Report to the user how up-to-date the packaging branch is.
+def _check_freshness(the_branch, latest_pub):
+ """Get information about how 'fresh' this 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
+ :param the_branch: The Branch to check
+ :param latest_pub: The LatestPublication used to check most recent
+ published version.
+ :return: (tags, latest_ver)
"""
- 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.place()
+ if latest_ver is None:
+ return None, {}
+ 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,))
+ return latest_ver, tags
+
+
+def _report_freshness(the_branch, tags, latest_ver, place, verbosity):
+ """Report if the branch is up-to-date."""
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
@@ -259,3 +256,25 @@
'Packaging branch version: %s\n'
'Packaging branch status: OUT-OF-DATE'
% (place, latest_ver, best_tag))
+
+
+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'
+ latest_ver, tags = _check_freshness(the_branch, latest_pub)
+ place = latest_pub.place()
+ _report_freshness(the_branch, tags, latest_ver, place, verbosity)
=== modified file 'bzrlib/plugins/launchpad/test_lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-20 15:05:29 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-22 10:59:28 +0000
@@ -382,24 +382,22 @@
class TestReportFreshness(tests.TestCaseWithMemoryTransport):
- def make_trivial_branch(self):
+ def setUp(self):
+ super(TestReportFreshness, self).setUp()
builder = self.make_branch_builder('tip')
builder.build_snapshot('A', [], [
('add', ('', 'root-id', 'directory', None))])
- b = builder.get_branch()
- return b
+ self.branch = builder.get_branch()
- def assertFreshnessReports(self, the_branch, verbosity, latest_version,
- content):
+ def assertFreshnessReports(self, 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,
+ lp_api_lite.report_freshness(self.branch, verbosity,
StubLatestPublication(latest_version))
new_content = self.get_log()[orig_log_len:]
# Strip out lines that have LatestPublication.get_* because those are
@@ -416,101 +414,87 @@
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')
+ c = self.branch.get_config()
+ c.set_user_option('launchpad.packaging_verbosity', 'off')
orig_log_len = len(self.get_log())
- launchpad._check_is_up_to_date(b)
+ launchpad._check_is_up_to_date(self.branch)
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)
+ lp_api_lite.report_freshness(self.branch, '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',
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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,
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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,
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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',
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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,
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports('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',
+ self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
+ self.assertFreshnessReports(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