aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdlpcvp.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/dlpcvp.py b/dlpcvp.py
index cedcad6..a8e26ea 100755
--- a/dlpcvp.py
+++ b/dlpcvp.py
@@ -1,6 +1,7 @@
#!/usr/bin/python3.6
# Requires: python3-rpm
+import argparse
import configparser
import json
import logging
@@ -21,6 +22,7 @@ import rpm
PyPI_base = "https://pypi.org/pypi/{}/json"
OBS_base = "https://api.opensuse.org"
ConfigRC = os.path.expanduser('~/.config/osc/oscrc')
+CUTCHARS = len('python-')
config = configparser.ConfigParser()
config.read(ConfigRC)
@@ -29,6 +31,7 @@ logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.DEBUG)
log = logging.getLogger()
+# or HTTPPasswordMgrWithPriorAuth ?
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
user = config[OBS_base]['user']
passw = config[OBS_base]['pass']
@@ -36,6 +39,7 @@ password_mgr.add_password(None, OBS_base, user, passw)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
+urllib.request.install_opener(opener)
def get_version_from_pypi(name: str, etag: str = None) -> Tuple[str, str, str]:
@@ -63,8 +67,8 @@ def suse_packages(proj:str) -> Iterable[str]:
"""
Iterator returning names of all packages in the given proj
- ETag management won't work here, because I don't like any way how to
- return it in iterator.
+ ETag management won't work here, because I don't know about any way
+ how to return it in iterator.
"""
req = Request(url=OBS_base + f'/source/{proj}')
@@ -161,15 +165,28 @@ def package_version(proj:str, pkg_name:str,
else:
raise
-
-if __name__=='__main__':
- cutchars = len('python-')
- project = 'devel:languages:python:singlespec-staging'
- for pkg in suse_packages(project):
- if pkg:
- assert pkg.startswith('python-')
- pypi_name = pkg[cutchars:]
+def main(prj):
+ for pkg in suse_packages(prj):
+ log.debug(f'pkg = {pkg}')
+ if pkg.startswith('python-'):
+ pypi_name = pkg[CUTCHARS:]
pypi_ver = get_version_from_pypi(pypi_name)
- suse_ver = package_version(project, pkg)
+ suse_ver = package_version(prj, pkg)
+ # FIXME We should somehow react to the situation, not just
+ # ignore it.
if suse_ver is not None:
print(f"{pkg} {suse_ver} {pypi_ver}")
+ else:
+ print(f'Is {pkg} on PyPI?')
+
+
+if __name__=='__main__':
+ parser = argparse.ArgumentParser(description='Check available versions '
+ 'of the upstream packages on PyPI')
+ parser.add_argument('--opensuse-project',
+ default='devel:languages:python:numeric',
+ help='The OpenBuildService project. Defaults '
+ 'to %(default)s')
+
+ args = parser.parse_args()
+ sys.exit(main(args.opensuse_project))