Created
March 3, 2022 11:06
-
-
Save PVince81/0efb382d1ada8f706b5cd7bec2b29076 to your computer and use it in GitHub Desktop.
Find apps compatible with platform version in Nextcloud app store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import json | |
import sys | |
from urllib.request import urlopen | |
from packaging import version | |
if len(sys.argv) > 1: | |
expectedVersion = version.parse(sys.argv[1]) | |
else: | |
expectedVersion = version.parse('23.0.0') | |
compatibleApps = [] | |
incompatibleApps = [] | |
apiUrl = 'https://apps.nextcloud.com/api/v1/apps.json' | |
baseGithubUrl = 'https://github.com/nextcloud/' | |
#with open('apps.json', 'r') as infile: | |
with urlopen(apiUrl) as infile: | |
data = json.load(infile) | |
for appSpec in data: | |
# check if maintained by us using some tricks | |
if not appSpec['issueTracker'].startswith(baseGithubUrl): | |
continue | |
compatibleVersion = None | |
for releaseSpec in appSpec['releases']: | |
platformVersionSpec = releaseSpec['platformVersionSpec'] | |
parts = platformVersionSpec.split(' ') | |
if (parts[0][0:2] != '>='): | |
sys.stderr.write('Unknown version spec format %s\n' % platformVersionSpec) | |
continue | |
minVersion = version.parse(parts[0][2:]) | |
maxVersion = None | |
if len(parts) > 1: | |
if parts[1][0] != '<': | |
sys.stderr.write('Unknown version spec format %s\n' % platformVersionSpec) | |
continue | |
maxVersion = version.parse(parts[1][1:]) | |
if expectedVersion < minVersion: | |
continue | |
if maxVersion is None: | |
# don't trust apps with no max version! | |
continue | |
if maxVersion is not None and expectedVersion >= maxVersion: | |
continue | |
if compatibleVersion is None or compatibleVersion < version.parse(releaseSpec['version']): | |
compatibleVersion = version.parse(releaseSpec['version']) | |
if compatibleVersion is not None and not compatibleVersion.is_prerelease: | |
compatibleApps.append((appSpec, compatibleVersion)) | |
else: | |
incompatibleApps.append(appSpec) | |
compatibleApps = sorted(compatibleApps, key=lambda a: a[0]['id']) | |
incompatibleApps = sorted(incompatibleApps, key=lambda a: a['id']) | |
print('## Platform version: ', expectedVersion) | |
print('### Compatible apps:') | |
for appSpec, version in compatibleApps: | |
print('- [x] %s - %s - %s' % (appSpec['id'], version, appSpec['issueTracker'])) | |
print() | |
print('### Incompatible apps:') | |
for appSpec in incompatibleApps: | |
print('- [ ] %s - %s' % (appSpec['id'], appSpec['issueTracker'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment