diff options
author | Benoît Knecht <benoit.knecht@fsfe.org> | 2010-10-26 16:11:36 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2010-11-02 11:57:56 +0100 |
commit | dfe910406faf1fbfffe5aed258b95c76610392ae (patch) | |
tree | 6fc7e649e607a5100054a66b6b8aafa8cb803645 | |
parent | ea9a6560eb537cb29ee2c56da49756571c25ddde (diff) | |
download | git-buildpackage-dfe910406faf1fbfffe5aed258b95c76610392ae.tar.gz git-buildpackage-dfe910406faf1fbfffe5aed258b95c76610392ae.tar.bz2 git-buildpackage-dfe910406faf1fbfffe5aed258b95c76610392ae.zip |
Expand environment variables and '~' in gbp.conf paths
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).
Closes: #545692
-rw-r--r-- | gbp/config.py | 14 | ||||
-rwxr-xr-x | git-buildpackage | 4 |
2 files changed, 14 insertions, 4 deletions
diff --git a/gbp/config.py b/gbp/config.py index 9d443d13..e9c108c6 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -3,14 +3,24 @@ # (C) 2006,2007,2010 Guido Guenther <agx@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 @@ -142,7 +152,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 f58aa35f..f6fb4c1d 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") |