Rev 64: Fix compatibility with bzr. in http://bazaar.launchpad.net/~bzr-upload-devs/bzr-upload/trunk

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Sep 5 13:33:05 BST 2009


At http://bazaar.launchpad.net/~bzr-upload-devs/bzr-upload/trunk

------------------------------------------------------------
revno: 64
revision-id: v.ladeuil+lp at free.fr-20090905123303-8xyyxdcxtdfeu7nh
parent: v.ladeuil+lp at free.fr-20090905113521-901et7depwu6osh3
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Sat 2009-09-05 14:33:03 +0200
message:
  	Fix compatibility with bzr.
  
  	* __init__.py:
  	(_get_branch_bool_option): Ensure compatibility with earlier bzr
  	versions, at least for now.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-09-05 11:35:21 +0000
+++ b/NEWS	2009-09-05 12:33:03 +0000
@@ -35,6 +35,10 @@
 * Fix auto hook trying to display an url without using the right encoding.
   (Vincent Ladeuil, #312686)
 
+* Fix compatibility with bzr versions that don't provide
+  get_user_option_as_bool().
+  (Vincent Ladeuil, #423791)
+
 Improvements
 ************
 

=== modified file '__init__.py'
--- a/__init__.py	2009-09-05 11:35:21 +0000
+++ b/__init__.py	2009-09-05 12:33:03 +0000
@@ -163,6 +163,20 @@
 def _get_branch_option(branch, option):
     return branch.get_config().get_user_option(option)
 
+# FIXME: Get rid of that as soon as we depend on a bzr API that includes
+# get_user_option_as_bool
+def _get_branch_bool_option(branch, option):
+    conf = branch.get_config()
+    if hasattr(conf, 'get_user_option_as_bool'):
+        value = conf.get_user_option_as_bool(option)
+    else:
+        value = conf.get_user_option(option)
+        if value is not None:
+            if value.lower().strip() == 'true':
+                value = True
+            else:
+                value = False
+    return value
 
 def _set_branch_option(branch, option, value):
     branch.get_config().set_user_option(option, value)
@@ -190,7 +204,7 @@
 
 
 def get_upload_auto(branch):
-    auto = branch.get_config().get_user_option_as_bool('upload_auto')
+    auto = _get_branch_bool_option(branch, 'upload_auto')
     if auto is None:
         auto = False # Default to False if not specified
     return auto
@@ -207,7 +221,7 @@
 
 
 def get_upload_auto_quiet(branch):
-    quiet = branch.get_config().get_user_option_as_bool('upload_auto_quiet')
+    quiet = _get_branch_bool_option(branch, 'upload_auto_quiet')
     if quiet is None:
         quiet = False # Default to False if not specified
     return quiet



More information about the bazaar-commits mailing list