Skip to contentSkip to conversation

fetch2/osc: Add support to query latest revision

PATCH In review Gunjan Gupta 2 participants 2 messages May 19, 2022 – May 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/osc: Add support to query latest revision

Add support to query latest revision. This makes it possble to use osc fetcher without specifying the rev parameter.

---
 lib/bb/fetch2/osc.py | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
lib/bb/fetch2/osc.py +29 -5
index eb0f82c8..dd02f037 100644
@@ -9,6 +9,7 @@ Based on the svn "Fetch" implementation.
 
 import logging
 import os
+import re
 import  bb
 from    bb.fetch2 import FetchMethod
 from    bb.fetch2 import FetchError
@@ -60,26 +61,49 @@ class Osc(FetchMethod):
 
         basecmd = d.getVar("FETCHCMD_osc") or "/usr/bin/env osc"
 
-        proto = ud.parm.get('protocol', 'ocs')
+        proto = ud.parm.get('protocol', 'https')
 
         options = []
 
         config = "-c %s" % self.generate_config(ud, d)
 
-        if ud.revision:
+        if getattr(ud, 'revision', ''):
             options.append("-r %s" % ud.revision)
 
         coroot = self._strip_leading_slashes(ud.path)
 
         if command == "fetch":
-            osccmd = "%s %s co %s/%s %s" % (basecmd, config, coroot, ud.module, " ".join(options))
+            osccmd = "%s %s -A %s://%s co %s/%s %s" % (basecmd, config, proto, ud.host, coroot, ud.module, " ".join(options))
         elif command == "update":
-            osccmd = "%s %s up %s" % (basecmd, config, " ".join(options))
+            osccmd = "%s %s -A %s://%s up %s" % (basecmd, config, proto, ud.host, " ".join(options))
+        elif command == "api_source":
+            osccmd = "%s %s -A %s://%s api source/%s/%s" % (basecmd, config, proto, ud.host, coroot, ud.module)
         else:
             raise FetchError("Invalid osc command %s" % command, ud.url)
 
         return osccmd
 
+    def _latest_revision(self, ud, d, name):
+        """
+        Fetch latest revision for the given package
+        """
+        api_source_cmd = self._buildosccommand(ud, d, "api_source")
+
+        output = runfetchcmd(api_source_cmd, d)
+        match = re.match('<directory ?.* rev="(\d+)".*>', output)
+        if match is None:
+            raise FetchError("Unable to parse osc response", ud.url)
+        return match.groups()[0]
+
+    def _revision_key(self, ud, d, name):
+        """
+        Return a unique key for the url
+        """
+        # Collapse adjacent slashes
+        slash_re = re.compile(r"/+")
+        rev = getattr(ud, 'revision', "latest")
+        return "osc:%s%s.%s.%s" % (ud.host, slash_re.sub(".", ud.path), name, rev)
+
     def download(self, ud, d):
         """
         Fetch url
@@ -123,7 +147,7 @@ class Osc(FetchMethod):
             os.remove(config_path)
 
         f = open(config_path, 'w')
-        proto = ud.parm.get('proto', 'https')
+        proto = ud.parm.get('protocol', 'https')
         f.write("[general]\n")
         f.write("apiurl = %s://%s\n" % (proto, ud.host))
         f.write("su-wrapper = su -c\n")
Signature · 1 line
2.32.0
#1 lore raw

lib/bb/fetch2/osc.py

Quoted 13 lines · Gunjan Gupta

Add support to query latest revision. This makes it possble to use osc fetcher without specifying the rev parameter.

---
 lib/bb/fetch2/osc.py | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
lib/bb/fetch2/osc.py +0 -0
index eb0f82c8..dd02f037 100644
....

+ def _latest_revision(self, ud, d, name):

lib/bb/fetch2/osc.py class Osc(FetchMethod): · line 96

Quoted 11 lines
lib/bb/fetch2/osc.py +10 -0
+        """
+        Fetch latest revision for the given package
+        """
+        api_source_cmd = self._buildosccommand(ud, d, "api_source")
+
+        output = runfetchcmd(api_source_cmd, d)
+        match = re.match('<directory ?.* rev="(\d+)".*>', output)
+        if match is None:
+            raise FetchError("Unable to parse osc response", ud.url)
+        return match.groups()[0]

...

This causes new warning with new python:
bitbake/lib/bb/fetch2/osc.py:93: DeprecationWarning: invalid escape sequence '\d'
match = re.match('<directory ?.* rev="(\d+)".*>', output)

Will send a fix.