aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorBenoît Knecht <benoit.knecht@fsfe.org>2010-10-26 16:11:36 +0200
committerGuido Günther <agx@sigxcpu.org>2010-11-02 11:57:56 +0100
commitdfe910406faf1fbfffe5aed258b95c76610392ae (patch)
tree6fc7e649e607a5100054a66b6b8aafa8cb803645 /gbp
parentea9a6560eb537cb29ee2c56da49756571c25ddde (diff)
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
Diffstat (limited to 'gbp')
-rw-r--r--gbp/config.py14
1 files changed, 12 insertions, 2 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"""