bitbake: 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.

(Bitbake rev: aa4cee1bb7415c498e4dc6af4dbb3d0c841faf2e)

Signed-off-by: Gunjan Gupta <viraniac@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Gunjan Gupta
2022-05-19 18:34:03 +00:00
committed by Richard Purdie
parent 23103d45c0
commit b0d39aa3d2

View File

@@ -9,6 +9,7 @@ Based on the svn "Fetch" implementation.
import logging import logging
import os import os
import re
import bb import bb
from bb.fetch2 import FetchMethod from bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError from bb.fetch2 import FetchError
@@ -60,26 +61,49 @@ class Osc(FetchMethod):
basecmd = d.getVar("FETCHCMD_osc") or "/usr/bin/env osc" basecmd = d.getVar("FETCHCMD_osc") or "/usr/bin/env osc"
proto = ud.parm.get('protocol', 'ocs') proto = ud.parm.get('protocol', 'https')
options = [] options = []
config = "-c %s" % self.generate_config(ud, d) config = "-c %s" % self.generate_config(ud, d)
if ud.revision: if getattr(ud, 'revision', ''):
options.append("-r %s" % ud.revision) options.append("-r %s" % ud.revision)
coroot = self._strip_leading_slashes(ud.path) coroot = self._strip_leading_slashes(ud.path)
if command == "fetch": 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": 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: else:
raise FetchError("Invalid osc command %s" % command, ud.url) raise FetchError("Invalid osc command %s" % command, ud.url)
return osccmd 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): def download(self, ud, d):
""" """
Fetch url Fetch url
@@ -123,7 +147,7 @@ class Osc(FetchMethod):
os.remove(config_path) os.remove(config_path)
f = open(config_path, 'w') f = open(config_path, 'w')
proto = ud.parm.get('proto', 'https') proto = ud.parm.get('protocol', 'https')
f.write("[general]\n") f.write("[general]\n")
f.write("apiurl = %s://%s\n" % (proto, ud.host)) f.write("apiurl = %s://%s\n" % (proto, ud.host))
f.write("su-wrapper = su -c\n") f.write("su-wrapper = su -c\n")