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

Enrico Scholz enrico.scholz at informatik.tu-chemnitz.de
Mon May 7 18:13:35 UTC 2007


Michael E Brown <Michael_E_Brown at dell.com> writes:

>> +    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?

You can write e.g.

| -- defaults.cfg --
| config_opts['macros'] = "%foo 1"
| 
| -- my-root.cfg ==
| config_opts['macros'] = [
|   config_opts['macros'],
|   {
|     '%bar' : 2
|   }
| ]

Overwriting is not possible/easy when we want to retain backward
compatibility.  When implemented from scratch, I would have implemented
this option completely as a dictionary (I do not think that order of
macros is for much interest).


>
>> +
>>      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.

I just rewrote this hunk of code. In a later version of my mock
modifications I removed this completely and replaced it by bind-mounting
the chrooted /var/lib/rpm directory into toplevel /var/lib/rpm.


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

See above for statement regarding backward compatibility; as long as
you do not change the default string-type, old/existing configurations
should still work.

When defaults would be dictionaries or vectors, overwriting can fail
when people append an string.




Enrico
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 480 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-buildsys-list/attachments/20070507/0f1abf6c/attachment.sig>


More information about the Fedora-buildsys-list mailing list