| |
@@ -1,6 +1,7 @@
|
| |
#!/usr/bin/python3
|
| |
|
| |
import argparse
|
| |
+ import json
|
| |
import os
|
| |
import pathlib
|
| |
import subprocess
|
| |
@@ -16,6 +17,7 @@
|
| |
parser.add_argument('-c', '--commit', action='store_true')
|
| |
parser.add_argument('-u', '--user')
|
| |
parser.add_argument('-w', '--write', action='store_true')
|
| |
+ parser.add_argument('-r', '--results', action='store')
|
| |
parser.add_argument('--keep-py3dir', action='store_true')
|
| |
parser.add_argument('dirname', type=pathlib.Path, nargs='+')
|
| |
opts = parser.parse_args()
|
| |
@@ -33,6 +35,13 @@
|
| |
def is_requires(type, pattern, line):
|
| |
return re.match(rf'{type}:\s*({pattern})', line) is not None
|
| |
|
| |
+ def produced_packages(dirname, specfile):
|
| |
+ command = ['rpm', '--define', f'_sourcedir {dirname}',
|
| |
+ '--define', 'dist .fc30', '-q', '--qf', '%{NAME}\n',
|
| |
+ '--specfile', f'{specfile}']
|
| |
+ output = subprocess.check_output(command, universal_newlines=True)
|
| |
+ return set(output.splitlines())
|
| |
+
|
| |
def dprint(*args, **kwargs):
|
| |
if opts.debug:
|
| |
print(*args, **kwargs)
|
| |
@@ -44,6 +53,12 @@
|
| |
specfile, = dirname.glob('*.spec')
|
| |
|
| |
print(f'==== {specfile}')
|
| |
+ try:
|
| |
+ old_packages = produced_packages(dirname, specfile)
|
| |
+ except subprocess.CalledProcessError:
|
| |
+ print('CANNOT PARSE SPEC')
|
| |
+ continue
|
| |
+
|
| |
new = pathlib.Path(f'{specfile}.tmp')
|
| |
try:
|
| |
# remove .tmp file to not leave obsolete stuff in case we bail out
|
| |
@@ -157,6 +172,25 @@
|
| |
cmd += ['-u', opts.user]
|
| |
subprocess.check_call(cmd)
|
| |
|
| |
+ try:
|
| |
+ new_packages = produced_packages(dirname, new)
|
| |
+ except subprocess.CalledProcessError:
|
| |
+ print('CANNOT PARSE SPEC')
|
| |
+ continue
|
| |
+ removed_packages = old_packages - new_packages
|
| |
+ print('Removed packages:', ', '.join(sorted(removed_packages)))
|
| |
+ if opts.results:
|
| |
+ ok = True
|
| |
+ with open(opts.results) as f:
|
| |
+ results = json.load(f)
|
| |
+ for pkg in removed_packages:
|
| |
+ if pkg not in results or results[pkg]['verdict'] != 'drop_now':
|
| |
+ print(f'CANNOT REMOVE {pkg}')
|
| |
+ ok = False
|
| |
+ continue
|
| |
+ if not ok:
|
| |
+ continue
|
| |
+
|
| |
if opts.diff:
|
| |
subprocess.call(['git', 'diff', f'-U{opts.U}', '--no-index', specfile, new])
|
| |
|
| |