[PATCH mock] Enhancements of the config_opts['macros'] handling

Michael E Brown Michael_E_Brown at dell.com
Mon May 7 17:07:55 UTC 2007


On Sat, May 05, 2007 at 07:07:39PM +0200, Enrico Scholz wrote:
> 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.

This too, looks entirely sane, except for one question and one nit...

> 
> 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'

How does this affect the ability to overwrite config from a config file
higher in the heirarchy?

> +
>      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}
> +                ))

This should go into the default config section, rather than hidden here.

You need to convert the setup functions to use the new format by
default, as well as any existing config file references in the default
supplied configs.
--
Michael




More information about the Fedora-buildsys-list mailing list