[PATCH mock] Enhancements of the config_opts['macros'] handling
Enrico Scholz
enrico.scholz at informatik.tu-chemnitz.de
Sat May 5 17:07:39 UTC 2007
This patch allows filling of ~/.rpmmacros by using dictionaries or
lists instead of a single strings. You can write e.g.
| config_opts['macros'] = [
| config_opts['macros'],
| {
| '%dist' : 'foo',
| '%packager' : 'bar'
| }]
This adds old/predefined macros first and then new '%dist' and
'%packager' ones.
For backward compatibility strings are still supported; to retain a
certain order of macros, they can be specified as tuples or lists too.
Signed-off-by: Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
---
mock.py | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/mock.py b/mock.py
index e20dbf0..573bb6e 100644
--- a/mock.py
+++ b/mock.py
@@ -767,6 +767,19 @@ class Root:
self.homedir, self.config['chrootuser'])
self.do_chroot(cmd, fatal = True)
+ def _expand_macro_string(self, macros):
+ res = []
+ if isinstance(macros, dict):
+ for (key,v) in macros.items():
+ res.append('%s\t%s' % (key,v))
+ elif isinstance(macros, basestring):
+ res = [macros]
+ else:
+ for v in macros:
+ res.append(self._expand_macro_string(v))
+
+ return '\n'.join(res) + '\n'
+
def _build_dir_setup(self):
# purge the builddir, if it exists
bd_out = '%s%s' % (self.rootdir, self.builddir)
@@ -788,8 +801,12 @@ class Root:
macrofile_out = '%s%s/.rpmmacros' % (self.rootdir, self.homedir)
if not os.path.exists(macrofile_out):
rpmmacros = open(macrofile_out, 'w')
- self.config['macros'] = self.config['macros'] + "\n%%_rpmlock_path %s/var/lib/rpm/__db.000" % self.basedir
- rpmmacros.write(self.config['macros'])
+
+ rpmmacros.write(self._expand_macro_string(self.config['macros']))
+ rpmmacros.write(self._expand_macro_string(
+ {"%_rpmlock_path" : "%s/var/lib/rpm/__db.000" % self.basedir}
+ ))
+
rpmmacros.close()
More information about the Fedora-buildsys-list
mailing list