[packages/pldnotify] anitya: print alternatives if mapping not found

glen glen at pld-linux.org
Tue Dec 15 21:01:06 CET 2015


commit 02ba5bf56e1eff89b692596ce7e9755625e69bb7
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Tue Dec 15 22:01:01 2015 +0200

    anitya: print alternatives if mapping not found

 pldnotify.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/pldnotify.py b/pldnotify.py
index a7ceb36..edc4de8 100755
--- a/pldnotify.py
+++ b/pldnotify.py
@@ -103,10 +103,34 @@ class Checker:
         response = requests.get(url)
         data = response.json()
         if 'error' in data:
-            raise ValueError, data['error']
+            error = data['error']
+            if error == 'No package "%s" found in distro "%s"' % (self.name, self.distro):
+                res = self.anitya_alternatives()
+                if res != None:
+                    error = error + ", " + 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.name
+        data = requests.get(url).json()
+
+        if data['total'] == 0:
+            return None
+
+        def format_project(project):
+            return '"%s" (%s)' % (project['name'], project['homepage'])
+
+        r = []
+        for project in data['projects']:
+            r.append(format_project(project))
+
+        return "Do you need to map %s?" % (", ".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/02ba5bf56e1eff89b692596ce7e9755625e69bb7



More information about the pld-cvs-commit mailing list