Options that expect a path in gbp.conf can now be given as
'~/path/to/dir' or '$HOME/path/to/dir' (or any other environment
variable for that matter).
---

This patch creates a new options type called "path". Options of this type are
expanded by replacing environment variables with their value, and expanding '~'
or '~user' to their respective paths.

This new option type is used for 'tarball-dir' and 'export-dir' in
git-buildpackage. Are there other options that should use it?

-- 
Benoît Knecht
---

diff --git a/gbp/config.py b/gbp/config.py
index 9a6a3c5..314f48a 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -3,14 +3,24 @@
 # (C) 2006,2007,2010 Guido Guenther <a...@sigxcpu.org>
 """handles command line and config file option parsing for the gbp commands"""
 
-from optparse import OptionParser, OptionGroup
+from optparse import OptionParser, OptionGroup, Option
 from ConfigParser import SafeConfigParser
+from copy import copy
 import os.path
 try:
     from gbp.gbp_version import gbp_version
 except ImportError:
     gbp_version = "[Unknown version]"
 
+def expand_path(option, opt, value):
+    value = os.path.expandvars(value)
+    return os.path.expanduser(value)
+
+class GbpOption(Option):
+    TYPES = Option.TYPES + ('path',)
+    TYPE_CHECKER = copy(Option.TYPE_CHECKER)
+    TYPE_CHECKER['path'] = expand_path
+
 class GbpOptionParser(OptionParser):
     """
     Handles commandline options and parsing of config files
@@ -139,7 +149,7 @@ class GbpOptionParser(OptionParser):
         self.prefix = prefix
         self.config = {}
         self.__parse_config_files()
-        OptionParser.__init__(self, usage=usage, version='%s %s' % 
(self.command, gbp_version))
+        OptionParser.__init__(self, option_class=GbpOption, usage=usage, 
version='%s %s' % (self.command, gbp_version))
 
     def _is_boolean(self, option_name, *args, **kwargs):
         """is option_name a boolean option"""
diff --git a/git-buildpackage b/git-buildpackage
index cbc310a..3b83d7b 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -260,7 +260,7 @@ def main(argv):
                       help="force creation of orig.tar.gz", 
action="store_true")
     orig_group.add_config_file_option(option_name="no-create-orig", 
dest="no_create_orig",
                       help="don't create orig.tar.gz", action="store_true")
-    orig_group.add_config_file_option(option_name="tarball-dir", 
dest="tarball_dir",
+    orig_group.add_config_file_option(option_name="tarball-dir", 
dest="tarball_dir", type="path",
                       help="location to look for external tarballs")
     orig_group.add_config_file_option(option_name="compression", 
dest="comp_type",
                       help="Compression type, default is '%(compression)s'")
@@ -282,7 +282,7 @@ def main(argv):
     cmd_group.add_boolean_config_file_option(option_name="pbuilder", 
dest="use_pbuilder")
     cmd_group.add_config_file_option(option_name="dist", dest="pbuilder_dist")
     cmd_group.add_config_file_option(option_name="arch", dest="pbuilder_arch")
-    export_group.add_config_file_option(option_name="export-dir", 
dest="export_dir",
+    export_group.add_config_file_option(option_name="export-dir", 
dest="export_dir", type="path",
                       help="before building the package export the source into 
EXPORT_DIR, default is '%(export-dir)s'")
     export_group.add_config_file_option("export", dest="export",
                       help="export treeish object TREEISH, default is 
'%(export)s'", metavar="TREEISH")
-- 
1.7.2.3




--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to