From a12ca3e5dcdaea0c1a8ffa31a46d1bb72544f987 Mon Sep 17 00:00:00 2001 From: Miro HronĨok Date: Aug 01 2017 09:58:59 +0000 Subject: Preserve macros in name Fixes https://pagure.io/pyrenamer/issue/1 --- diff --git a/renamer.py b/renamer.py index ae8409e..9b186fe 100755 --- a/renamer.py +++ b/renamer.py @@ -110,6 +110,18 @@ for dirname in opts.dirname: stats['MANY-SUBPACKAGES'] += 1 continue + # find macros in name + for line in stripped: + if line.startswith('Name:'): + _, name = line.split(':') + name = name.strip() + python, _, macroname = name.partition('-') + if python == 'python' and macroname: + pass + else: + macroname = modname # better safe than sorry + break + # find description if '%description %{_description}' in stripped: i = j = stripped.index('%description %{_description}') @@ -137,9 +149,9 @@ for dirname in opts.dirname: # Detect old Provides # Assume that it appears only above %description - provides = [f'%{{?python_provide:%python_provide python2-{modname}}}'] + provides = [f'%{{?python_provide:%python_provide python2-{macroname}}}'] for k in reversed(range(i)): - match = re.match(fr'Provides:\s*python2?-({Modname}|{modname})\s*(?:=.*)', lines[k]) + match = re.match(fr'Provides:\s*python2?-({Modname}|{modname}|{re.escape(macroname)})\s*(?:=.*)', lines[k]) if match: del lines[k] tosub += 1 @@ -147,7 +159,7 @@ for dirname in opts.dirname: del lines[k] tosub += 1 provided = match.group(1) - if provided != modname: + if provided not in (modname, macroname): provides.append(f'%{{?python_provide:%python_provide python2-{provided}}}') # Move Requires down. @@ -191,11 +203,11 @@ for dirname in opts.dirname: ''] if description else [] lines[i:j] = global_desc + [ - f'%package -n python2-{modname}', + f'%package -n python2-{macroname}', 'Summary: %summary', '\n'.join(requires + provides), '', - f'%description -n python2-{modname} {desc_macro}'] \ + f'%description -n python2-{macroname} {desc_macro}'] \ + ([] if lines[j].strip() == '' else ['']) # Move unqualified %files to new subpackage @@ -203,7 +215,7 @@ for dirname in opts.dirname: for files_i in range(len(lines)): match = re.match(r'%files\s*(-f\s*[^ ]+)?\s*', lines[files_i]) if match: - lines[files_i] = f'%files -n python2-{modname}' + ( + lines[files_i] = f'%files -n python2-{macroname}' + ( f' {match.group(1)}' if match.group(1) is not None else '') # detect _bindir in files for files_j in range(files_i + 1, len(lines)):