From 417ad85be3c4c9b1660a8e00ce8a2ce0ee0f125a Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Tue, 8 Jul 2014 00:13:41 +0200 Subject: allow converting perl- BRs as well --- mgagnome | 82 +++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/mgagnome b/mgagnome index d36b613..be8efcd 100755 --- a/mgagnome +++ b/mgagnome @@ -1276,43 +1276,71 @@ def cmd_clean_spec_multi(args): # Convert -devel requires into pkgconfig requires if options.pkgconfig: br = s.buildrequires - br_old = [r for r in br.keys() if r.endswith('-devel')] no_alt = set() no_change = {} - for req in br_old: - provides = Downstream.alternative_provides(req) - provides_alt = [clean_pkgconfig_prov(prov) for prov in provides if prov.startswith('pkgconfig(')] - change_to = None - if len(provides_alt) == 1: - change_to = provides_alt[0] - elif len(provides_alt): - basereq = req[:-len('-devel')] - check_for = ['pkgconfig(%s)' % basereq] - if basereq.startswith('lib'): - check_for.append('pkgconfig(%s)' % basereq[len('lib'):]) - else: - check_for.append('pkgconfig(lib%s)' % basereq) - for check in check_for: - if check in provides_alt: - change_to = check - break - + convert_brs = { + 'pkgconfig': { + 'desc': 'convert -devel buildrequires into pkgconfig', + 'check_br': lambda req: req.endswith('-devel'), + 'check_provide': lambda prov: prov.startswith('pkgconfig('), + 'basereq': lambda req: req[:-len('-devel')], + 'extra': lambda basereq: [ + 'pkgconfig(%s)' % basereq, + 'pkgconfig(%s)' % basereq[len('lib'):] if basereq.startswith('lib') else 'pkgconfig(lib%s)' % basereq + ], + }, + 'perl': { + 'desc': 'convert perl- buildrequires into perl()', + 'check_br': lambda req: req.startswith('perl-'), + 'check_provide': lambda prov: prov.startswith('perl('), + 'basereq': lambda req: req[len('perl-'):], + 'extra': lambda basereq: ['perl(%s)' % basereq.replace('-', '::')], + } + } + + for convert_br, keys in convert_brs.iteritems(): + keys['changes'] = {} + br_old = [r for r in br.keys() if keys['check_br'](r)] + for req in br_old: + provides = Downstream.alternative_provides(req) + provides_alt = [clean_pkgconfig_prov(prov) for prov in provides if keys['check_provide'](prov)] + change_to = None + if len(provides_alt) == 1: + change_to = provides_alt[0] + elif len(provides_alt): + basereq = keys['basereq'](req) + check_for = keys['extra'](basereq) if 'extra' in keys else [] + + for check in check_for: + if check in provides_alt: + change_to = check + break - if len(provides_alt): - if change_to is None: no_change[req] = provides_alt - else: - no_alt.add(req) + if len(provides_alt): + if change_to is None: no_change[req] = provides_alt + else: + no_alt.add(req) - if change_to is not None: changes[req] = change_to + if change_to is not None: + keys['changes'][req] = change_to if not options.doit: import pprint - if changes: pprint.pprint(changes) + for keys in convert_brs.items(): + if 'changes' in keys and keys['changes']: pprint.pprint(keys['changes']) if no_alt: print "WARNING: no alternatives found for: %s" % ", ".join(sorted(no_alt)) if no_change: pprint.pprint(no_change) - if s.update_br(changes, change_description='convert -devel buildrequires into pkgconfig'): made_changes=True - if s.clean_spec(): made_changes=True + keys_with_changes = [keys for keys in convert_brs.itervalues() if 'changes' in keys and keys['changes']] + if not keys_with_changes: + keys_with_changes.append( {'changes': [], 'desc': 'unsplit BRs'}) + + for keys in keys_with_changes: + if s.update_br(keys['changes'], change_description=keys['desc']): + made_changes=True + + if s.clean_spec(): + made_changes=True # If we made it this far, checkin the changes if made_changes: -- cgit v1.2.1