From e86f6f7f45df2e33c4001f4965a4fd7e8e6c8a37 Mon Sep 17 00:00:00 2001 From: Christopher Engelhard Date: Wed, 30 Dec 2020 11:03:33 +0100 Subject: [PATCH] move helper scripts to subfolder --- .../get-bundled-versions.py | 0 utils/get-composer-requires.py | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+) rename get-bundled-versions.py => utils/get-bundled-versions.py (100%) create mode 100755 utils/get-composer-requires.py diff --git a/get-bundled-versions.py b/utils/get-bundled-versions.py similarity index 100% rename from get-bundled-versions.py rename to utils/get-bundled-versions.py diff --git a/utils/get-composer-requires.py b/utils/get-composer-requires.py new file mode 100755 index 0000000..ffd77f9 --- /dev/null +++ b/utils/get-composer-requires.py @@ -0,0 +1,80 @@ +#!/bin/env python + +import os +import json +import re +import subprocess + +defaultconstraint = 2 + +constraintmap = ('any', 'loose', 'strict', 'exact') + +def get_requires(name, version, constraint): + version = version.split('.') + + if constraint == 0: + requires = 'php-composer(' + name + ')' + elif constraint == 1: + wipe = False + for i in range(0, len(version)): + if version[i] == '0' or wipe: + version[i] = '0' + else: + version[i] = str(int(version[i]) + 1) + wipe = True + requires = '(php-composer(' + name + ') >= ' + minver + ' with php-composer(' + name + ') < ' + '.'.join(version) + ')' + elif constraint == 2: + version[-1] = '0' + version[-2] = str(int(version[-2]) + 1) + requires = '(php-composer(' + name + ') >= ' + minver + ' with php-composer(' + name + ') < ' + '.'.join(version) + ')' + else: + requires = 'php-composer(' + name + ') = ' + minver + return requires + +def repoquery(query): + stdout = subprocess.run(['dnf', 'repoquery', '-q', '--whatprovides', requires], stdout=subprocess.PIPE, universal_newlines=True, check = True).stdout + return stdout + + +with open('3rdparty/composer.json') as f: +#with open('apps/files_external/3rdparty/composer.json') as f: + depdata = json.load(f) + for name, version in depdata['require'].items(): + if name == 'php': + continue + print(name, version, ':') + version = version.replace('v', '') + if version == '*': + constraint = 0 + version = '0' + elif version.startswith('^'): + constraint = 1 + version = version.strip('^') + elif version.startswith('~'): + constraint = 2 + version = version.strip('~') + else: + constraint = defaultconstraint + + if re.search('[^.0-9]', version): + print('Unparseable version:', version) + continue + else: + minver = version + + requires = get_requires(name, version, constraint) + print(' Constraint (' + constraintmap[constraint] + '): ' + requires) + + package = repoquery(requires) + while len(package) == 0: + constraint -= 1 + if constraint < 0: + break + requires = get_requires(name, version, constraint) + print(' Constraint (' + constraintmap[constraint] + '): ' + requires) + package = repoquery(requires) + + if len(package) == 0: + print(' -> no providing package found\n') + else: + print(' -> ' + package)