Rev 61: Fix bug #312686 and add an 'upload_auto_quiet' config variable. in http://bazaar.launchpad.net/~bzr-upload-devs/bzr-upload/trunk
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Sep 2 18:05:30 BST 2009
At http://bazaar.launchpad.net/~bzr-upload-devs/bzr-upload/trunk
------------------------------------------------------------
revno: 61
revision-id: v.ladeuil+lp at free.fr-20090902170527-cdn8mcnhvk5gd6rl
parent: v.ladeuil+lp at free.fr-20090710124557-hf1dqba4mly7z98b
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Wed 2009-09-02 19:05:27 +0200
message:
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
* tests/test_auto_upload_hook.py:
(AutoPushHookTests): Helper class.
(AutoPushWithLocation, AutoPushWithoutLocation): New classes with
dedicated setups.
* auto_upload_hook.py:
Fix imports.
(auto_upload_hook): Delete quiet param, it was used by tests
only. Having a config variable works better and gives control to
the user as a bonus.
* __init__.py:
(get_upload_auto): Address the FIXME, there *is* a better way to
get at booleans.
(set_upload_auto): Add a FIXME :)
(get_upload_auto_quiet, set_upload_auto_quiet): New config
variable.
(install_auto_upload_hook): Define a function for that as we need
to call it for tests.
* README:
Document 'upload_auto_quiet'.
* NEWS:
Update format.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-02-10 08:41:52 +0000
+++ b/NEWS 2009-09-02 17:05:27 +0000
@@ -1,31 +1,52 @@
---------------------
+########################
bzr-upload Release Notes
---------------------
-
-.. contents::
-
-IN DEVELOPMENT
---------------
-
- COMPATIBILITY BREAKS:
-
- NEW FEATURES:
-
- * Remote branches can be used to upload from.
- (Gary van der Merwe, Vincent Ladeuil)
-
- IMPROVEMENTS:
-
- BUG FIXES:
-
- DOCUMENTATION:
-
- * Clarify 'changes' definition in online help.
- (Vincent Ladeuil, #275538)
-
- API CHANGES:
-
- TESTING:
-
- INTERNALS:
+########################
+
+.. contents:: List of Releases
+ :depth: 1
+
+In Development
+##############
+
+
+Compatibility Breaks
+********************
+
+
+New Features
+************
+
+* Remote branches can be used to upload from.
+ (Gary van der Merwe, Vincent Ladeuil)
+
+* The auto hook verbosity is now controlled by the 'upload_auto_quiet'
+ config variable. If defaults to False if not set.
+
+Bug Fixes
+*********
+
+* Fix auto hook trying to display an url without using the right encoding.
+ (Vincent Ladeuil, #312686)
+
+Improvements
+************
+
+
+Documentation
+*************
+
+* Clarify 'changes' definition in online help.
+ (Vincent Ladeuil, #275538)
+
+
+API Changes
+***********
+
+
+Internals
+*********
+
+
+Testing
+*******
=== modified file 'README'
--- a/README 2009-01-19 08:53:32 +0000
+++ b/README 2009-09-02 17:05:27 +0000
@@ -64,6 +64,11 @@
will disable the feature for that branch.
+Since the auto hook is triggered automatically, you can't use the --quiet
+option available for the upload command. Instead, you can set the
+'upload_auto_quiet' configuration variable to True or False in either
+bazaar.conf, locations.conf or branch.conf.
+
Upload from Remote Location
---------------------------
=== modified file '__init__.py'
--- a/__init__.py 2009-02-28 15:29:05 +0000
+++ b/__init__.py 2009-09-02 17:05:27 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -66,23 +66,29 @@
def _get_branch_option(branch, option):
return branch.get_config().get_user_option(option)
+
def _set_branch_option(branch, option, value):
branch.get_config().set_user_option(option, value)
+
def get_upload_location(branch):
return _get_branch_option(branch, 'upload_location')
+
def set_upload_location(branch, location):
_set_branch_option(branch, 'upload_location', location)
+
def get_upload_auto(branch):
- result = _get_branch_option(branch, 'upload_auto')
- # FIXME: is there a better way to do this with bzr's config API?
- if result is not None and result.strip() == "True":
- return True
- return False
+ auto = branch.get_config().get_user_option_as_bool('upload_auto')
+ if auto is None:
+ auto = False # Default to False if not specified
+ return auto
+
def set_upload_auto(branch, auto):
+ # FIXME: What's the point in allowing a boolean here instead of requiring
+ # the callers to use strings instead ?
if auto:
auto_str = "True"
else:
@@ -90,6 +96,17 @@
_set_branch_option(branch, 'upload_auto', auto_str)
+def get_upload_auto_quiet(branch):
+ quiet = branch.get_config().get_user_option_as_bool('upload_auto_quiet')
+ if quiet is None:
+ quiet = False # Default to False if not specified
+ return quiet
+
+
+def set_upload_auto_quiet(branch, quiet):
+ _set_branch_option(branch, 'upload_auto_quiet', quiet)
+
+
class BzrUploader(object):
def __init__(self, branch, to_transport, outf, tree, rev_id,
@@ -428,14 +445,15 @@
commands.register_command(cmd_upload)
-
-from bzrlib.plugins.upload.auto_upload_hook import auto_upload_hook
-
-
-if hasattr(branch.Branch.hooks, "install_named_hook"):
+def install_auto_upload_hook():
+ from bzrlib.plugins.upload import auto_upload_hook
branch.Branch.hooks.install_named_hook('post_change_branch_tip',
- auto_upload_hook,
+ auto_upload_hook.auto_upload_hook,
'Auto upload code from a branch when it is changed.')
+
+
+if hasattr(branch.Branch.hooks, "install_named_hook"):
+ install_auto_upload_hook()
auto_hook_available = True
else:
auto_hook_available = False
=== modified file 'auto_upload_hook.py'
--- a/auto_upload_hook.py 2008-08-01 18:58:57 +0000
+++ b/auto_upload_hook.py 2009-09-02 17:05:27 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,31 +17,32 @@
import sys
-from bzrlib import branch, transport, urlutils
-
-
-from bzrlib.plugins.upload import (
- BzrUploader,
- get_upload_location,
- get_upload_auto,
- )
-
-
-def auto_upload_hook(params, quiet=False):
+from bzrlib import (
+ branch,
+ osutils,
+ trace,
+ transport,
+ urlutils,
+ )
+
+
+def auto_upload_hook(params):
+ from bzrlib.plugins import upload
source_branch = params.branch
- destination = get_upload_location(source_branch)
+ destination = upload.get_upload_location(source_branch)
if destination is None:
return
- auto_upload = get_upload_auto(source_branch)
+ auto_upload = upload.get_upload_auto(source_branch)
if not auto_upload:
return
+ quiet = upload.get_upload_auto_quiet(source_branch)
if not quiet:
- display_url = urlutils.unescape_for_display(destination,
- sys.stdout.encoding)
- print "Automatically uploading to %s" % display_url
+ display_url = urlutils.unescape_for_display(
+ destination, osutils.get_terminal_encoding())
+ trace.note('Automatically uploading to %s', display_url)
to_transport = transport.get_transport(destination)
last_revision = source_branch.last_revision()
last_tree = source_branch.repository.revision_tree(last_revision)
- uploader = BzrUploader(source_branch, to_transport, sys.stdout,
- last_tree, last_revision, quiet=quiet)
+ uploader = upload.BzrUploader(source_branch, to_transport, sys.stdout,
+ last_tree, last_revision, quiet=quiet)
uploader.upload_tree()
=== modified file 'tests/test_auto_upload_hook.py'
--- a/tests/test_auto_upload_hook.py 2009-03-13 00:51:19 +0000
+++ b/tests/test_auto_upload_hook.py 2009-09-02 17:05:27 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,74 +16,67 @@
import os
-from bzrlib.branch import Branch
-from bzrlib.tests import TestCaseWithTransport
-
-from bzrlib.plugins.upload import set_upload_location, set_upload_auto
-from bzrlib.plugins.upload.auto_upload_hook import auto_upload_hook
-
-# Hooks are disabled during tests, so that they don't cause havoc
-# with a users system. What we will test is that the hook was
-# correctly registered, and then set up the scenarios and trigger
-# it manually
-
-class AutoPushHookTests(TestCaseWithTransport):
-
- def make_start_branch(self, location=True, auto=True):
+from bzrlib import (
+ branch,
+ tests,
+ )
+
+from bzrlib.plugins import upload
+
+
+class AutoPushHookTests(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(AutoPushHookTests, self).setUp()
+ upload.install_auto_upload_hook()
+
+ def make_start_branch(self):
self.wt = self.make_branch_and_tree('.')
self.build_tree(['a'])
self.wt.add(['a'])
self.wt.commit("one")
- if location:
- set_upload_location(self.wt.branch, self.target_location())
- if auto:
- set_upload_auto(self.wt.branch, True)
-
- def target_location(self):
- return self.get_url('target')
-
- def get_params(self):
- class FakeParams(object):
- def __init__(self, branch):
- self.branch = branch
- return FakeParams(self.wt.branch)
-
- def test_hook_is_registered(self):
- # Hooks are stored in self._preserved_hooks
- self.assertTrue(auto_upload_hook in
- self._preserved_hooks[Branch][1]['post_change_branch_tip'])
+
+
+class AutoPushWithLocation(AutoPushHookTests):
+
+ def setUp(self):
+ super(AutoPushWithLocation, self).setUp()
+ self.make_start_branch()
+ upload.set_upload_auto(self.wt.branch, True)
+ upload.set_upload_location(self.wt.branch, self.get_url('target'))
+ upload.set_upload_auto_quiet(self.wt.branch, 'True')
def test_auto_push_on_commit(self):
- self.make_start_branch()
self.failIfExists('target')
self.build_tree(['b'])
self.wt.add(['b'])
self.wt.commit("two")
- auto_upload_hook(self.get_params(), quiet=True)
self.failUnlessExists('target')
self.failUnlessExists(os.path.join('target', 'a'))
self.failUnlessExists(os.path.join('target', 'b'))
def test_disable_auto_push(self):
- self.make_start_branch()
self.failIfExists('target')
self.build_tree(['b'])
self.wt.add(['b'])
self.wt.commit("two")
- auto_upload_hook(self.get_params(), quiet=True)
- set_upload_auto(self.wt.branch, False)
+ upload.set_upload_auto(self.wt.branch, False)
self.build_tree(['c'])
self.wt.add(['c'])
self.wt.commit("three")
- auto_upload_hook(self.get_params(), quiet=True)
self.failIfExists(os.path.join('target', 'c'))
+
+class AutoPushWithoutLocation(AutoPushHookTests):
+
+ def setUp(self):
+ super(AutoPushWithoutLocation, self).setUp()
+ self.make_start_branch()
+ upload.set_upload_auto(self.wt.branch, True)
+
def test_dont_push_if_no_location(self):
- self.make_start_branch(location=False)
self.failIfExists('target')
self.build_tree(['b'])
self.wt.add(['b'])
self.wt.commit("two")
- auto_upload_hook(self.get_params(), quiet=True)
self.failIfExists('target')
-
More information about the bazaar-commits
mailing list