summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-03-25 10:56:47 +0200
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-06-05 14:20:04 +0300
commit45e9e6771288f0021eadcf87ea08f0a9c4e19063 (patch)
tree1eec90c32cf9b428ce096475dd2fb561ea983f9a /gbp
parent89f5f0f03fb52994d192ee53afb1a3ee37904b09 (diff)
downloadgit-buildpackage-45e9e6771288f0021eadcf87ea08f0a9c4e19063.tar.gz
git-buildpackage-45e9e6771288f0021eadcf87ea08f0a9c4e19063.tar.bz2
git-buildpackage-45e9e6771288f0021eadcf87ea08f0a9c4e19063.zip
config: support for per-tree config files
Add support for reading the local config file(s) from a given git tree-ish. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp')
-rw-r--r--gbp/config.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/gbp/config.py b/gbp/config.py
index 166f5537..43d37a18 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -20,6 +20,8 @@ from optparse import OptionParser, OptionGroup, Option, OptionValueError
from ConfigParser import SafeConfigParser, NoSectionError
from copy import copy
import os.path
+import tempfile
+
try:
from gbp.version import gbp_version
except ImportError:
@@ -335,13 +337,26 @@ class GbpOptionParser(OptionParser):
files = [fname for fname in files if fname.startswith('/')]
return files
- def _read_config_file(self, parser, repo, filename):
+ def _read_config_file(self, parser, repo, filename, git_treeish):
"""Read config file"""
str_fields = {}
if repo:
str_fields['git_dir'] = repo.git_dir
if not repo.bare:
str_fields['top_dir'] = repo.path
+
+ # Read per-tree config file
+ if repo and git_treeish and filename.startswith('%(top_dir)s/'):
+ with tempfile.TemporaryFile() as tmp:
+ relpath = filename.replace('%(top_dir)s/', '')
+ try:
+ config = repo.show('%s:%s' % (git_treeish, relpath))
+ tmp.writelines(config)
+ except GitRepositoryError:
+ pass
+ tmp.seek(0)
+ parser.readfp(tmp)
+ return
try:
filename = filename % str_fields
except KeyError:
@@ -349,7 +364,7 @@ class GbpOptionParser(OptionParser):
return
parser.read(filename)
- def parse_config_files(self):
+ def parse_config_files(self, git_treeish=None):
"""
Parse the possible config files and set appropriate values
default values
@@ -366,7 +381,7 @@ class GbpOptionParser(OptionParser):
repo = None
# Read all config files
for filename in config_files:
- self._read_config_file(parser, repo, filename)
+ self._read_config_file(parser, repo, filename, git_treeish)
self.config.update(dict(parser.defaults()))
# Make sure we read any legacy sections prior to the real subcommands
@@ -406,7 +421,8 @@ class GbpOptionParser(OptionParser):
else:
self.config['filter'] = []
- def __init__(self, command, prefix='', usage=None, sections=[]):
+ def __init__(self, command, prefix='', usage=None, sections=[],
+ git_treeish=None):
"""
@param command: the command to build the config parser for
@type command: C{str}
@@ -422,7 +438,7 @@ class GbpOptionParser(OptionParser):
self.sections = sections
self.prefix = prefix
self.config = {}
- self.parse_config_files()
+ self.parse_config_files(git_treeish)
self.valid_options = []
if self.command.startswith('git-') or self.command.startswith('gbp-'):