diff options
author | Martin Langhoff <martin@laptop.org> | 2011-01-06 22:15:14 (GMT) |
---|---|---|
committer | Daniel Drake <dsd@laptop.org> | 2011-01-06 22:17:41 (GMT) |
commit | 5b0949640f963f2456e2f3520692237e2c526e2e (patch) | |
tree | 66d1559c102bd15730dac9114fff0ba15adadc4b /osbuilder.py | |
parent | f320782896b2fe8aa73282087e2f9b2bfe0da459 (diff) |
Define oob_config_dir env var and interpolation
Path references in the config file can now refer to %(oob_config_dir)s
which resolves to the directory where the config file resides.
Additionally, scripts will find $oob_config_dir defined in the environment.
For example this will find a custom script in the same dir as the config
file:
[custom_scripts]
custom_script_1=%(oob_config_dir)s/myscript.sh
In a custom script, this will apply a patch in the same directory as the
config file:
patch $INSTALL_DIR/etc/foo < $oob_config_dir/foo.patch
[dsd: minor tweak, add documentation]
Diffstat (limited to 'osbuilder.py')
-rwxr-xr-x | osbuilder.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/osbuilder.py b/osbuilder.py index 11b480b..1e5597a 100755 --- a/osbuilder.py +++ b/osbuilder.py @@ -69,6 +69,8 @@ class Stage(object): env['OOB__statedir'] = self.osb.statedir env['OOB__fsmount'] = self.osb.fsmount + env['oob_config_dir'] = os.path.dirname(self.osb.build_config) + for section in self.osb.cfg.sections(): for option in self.osb.cfg.options(section): val = self.osb.cfg.get(section, option) @@ -247,7 +249,7 @@ class OsBuilderException(Exception): class OsBuilder(object): def __init__(self, build_config, additional_defaults): - self.build_config = build_config + self.build_config = os.path.abspath(build_config) self.additional_defaults = additional_defaults print " * OLPC OS builder v%s" % VERSION @@ -270,7 +272,9 @@ class OsBuilder(object): self.fsmount = os.path.join(self.builddir, 'mnt-fs') # load config to find module list - self.cfg = ConfigParser() + # and set interpolation default for oob_config_dir + self.cfg = ConfigParser({'oob_config_dir': + os.path.dirname(self.build_config)}) self.cfg.read(self.build_config) # read in defaults specified on the command line @@ -313,7 +317,8 @@ class OsBuilder(object): def read_config(self): """Read and validate config (including module defaults)""" # reset config since we want to load the module defaults first - self.cfg = ConfigParser() + self.cfg = ConfigParser({'oob_config_dir': + os.path.dirname(self.build_config)}) for mod in self.modules: m = re.match(r"[A-Za-z_][A-Za-z0-9_]*$", mod) |