[packages/pldnotify/use-classes] wip
glen
glen at pld-linux.org
Wed Feb 24 09:16:06 CET 2021
commit 404301396c08739fb40798dc5f6ff1c22d2b5ebd
Author: Elan Ruusamäe <glen at pld-linux.org>
Date: Wed Feb 24 10:15:30 2021 +0200
wip
pldnotify.py | 89 +++++++++++++++++++++++++++++++++---------------------------
1 file changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/pldnotify.py b/pldnotify.py
index 02f0180..c080db6 100755
--- a/pldnotify.py
+++ b/pldnotify.py
@@ -52,6 +52,52 @@ class RPMSpec:
raise ValueError("%s: spec with no version" % self._specfile)
return self._version
+
+class AbstractChecker:
+ pass
+
+class CheckReleaseMonitoring(AbstractChecker):
+ """
+ Check for update from release-monitoring.org (Anitya).
+ Raise ValueError or version from anitya project.
+ """
+ def find_latest(self, distro, name):
+ url = "https://release-monitoring.org/api/project/%s/%s" % (distro, spec.name)
+ print(url)
+ response = requests.get(url)
+ data = response.json()
+ print(data)
+ if 'error' in data:
+ error = data['error']
+ if error == 'No package "%s" found in distro "%s"' % (spec.name, distro):
+ res = self.find_alternatives()
+ if res != None:
+ error = error + "\n" + res
+ raise ValueError(error)
+
+ return data['version']
+
+ """
+ Return alternatives found from Anitya
+ """
+ def find_alternatives(self, spec):
+ url = "https://release-monitoring.org/api/projects/?pattern=%s" % spec.name
+ data = requests.get(url).json()
+
+ if data['total'] == 0:
+ return None
+
+ def format_project(project):
+ url = 'https://release-monitoring.org/project/%d/' % project['id']
+
+ return '"%s" (%s): %s' % (project['name'], project['homepage'], url)
+
+ r = []
+ for project in data['projects']:
+ r.append(format_project(project))
+
+ return "Possible matches:\n- %s" % ("\n- ".join(r))
+
"""
Class containing specific remote repositories,
i.e Anitya (release-monitoring.org), NPM (nodejs), etc ...
@@ -59,7 +105,9 @@ i.e Anitya (release-monitoring.org), NPM (nodejs), etc ...
"""
class Checker:
distro = 'pld-linux'
- checkers = ['anitya']
+ checkers = [
+ CheckReleaseMonitoring,
+ ]
def __init__(self, specfile, debug):
self.debug = debug
@@ -93,45 +141,6 @@ class Checker:
return current
- """
- Check for update from release-monitoring.org (Anitya).
- Raise ValueError or version from anitya project.
- """
- def anitya(self):
- url = "https://release-monitoring.org/api/project/%s/%s" % (self.distro, self.spec.name)
- response = requests.get(url)
- data = response.json()
- if 'error' in data:
- error = data['error']
- if error == 'No package "%s" found in distro "%s"' % (self.spec.name, self.distro):
- res = self.anitya_alternatives()
- if res != None:
- error = error + "\n" + res
- raise ValueError(error)
-
- return data['version']
-
- """
- Return alternatives found from Anitya
- """
- def anitya_alternatives(self):
- url = "https://release-monitoring.org/api/projects/?pattern=%s" % self.spec.name
- data = requests.get(url).json()
-
- if data['total'] == 0:
- return None
-
- def format_project(project):
- url = 'https://release-monitoring.org/project/%d/' % project['id']
-
- return '"%s" (%s): %s' % (project['name'], project['homepage'], url)
-
- r = []
- for project in data['projects']:
- r.append(format_project(project))
-
- return "Possible matches:\n- %s" % ("\n- ".join(r))
-
def main():
parser = argparse.ArgumentParser(description='PLD-Notify: project to monitor upstream releases')
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/pldnotify.git/commitdiff/404301396c08739fb40798dc5f6ff1c22d2b5ebd
More information about the pld-cvs-commit
mailing list