From: Chen Qi <[email protected]>
We want to be able to do stable version upgrade for recipes. For
example, 1.0.0 -> 1.0.1 instead of 1.0.0 -> 1.1.0.
To to this, we need an extra paramter to latest_versionstring
so that we are able to filter out the versions we need. Using regex
has the advantage of adapting to different version schemes.
Signed-off-by: Chen Qi <[email protected]>
---
lib/bb/fetch2/crate.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/lib/bb/fetch2/crate.py b/lib/bb/fetch2/crate.py
index b89817ab9..6f0e656f7 100644
--- a/lib/bb/fetch2/crate.py
+++ b/lib/bb/fetch2/crate.py
@@ -14,6 +14,7 @@ import hashlib
import json
import os
import subprocess
+import re
import bb
from bb.fetch2 import logger, subprocess_setup, UnpackError
from bb.fetch2.wget import Wget
@@ -155,18 +156,22 @@ class Crate(Wget):
with open(mdpath, "w") as f:
json.dump(metadata, f)
- def latest_versionstring(self, ud, d):
+ def latest_versionstring(self, ud, d, filter_regex=None):
"""
Return the latest version available when versionsurl is the [name]/versions URL.
"""
from functools import cmp_to_key
json_data = json.loads(self._fetch_index(ud.versionsurl, ud, d))
versions = [(0, i["num"], "") for i in json_data["versions"]]
+ if filter_regex:
+ versions = [v for v in versions if re.match(filter_regex, v[1])]
versions = sorted(versions, key=cmp_to_key(bb.utils.vercmp))
+ if versions:
+ return (versions[-1][1], "")
+ else:
+ return ('', '')
- return (versions[-1][1], "")
-
- def latest_versionstring_from_index(self, ud, d):
+ def latest_versionstring_from_index(self, ud, d, filter_regex=None):
"""
Return the latest version available when versionsurl is a Cargo index
file.
@@ -180,5 +185,11 @@ class Crate(Wget):
data = json.loads(line)
versions.append((0, data["vers"], ""))
+ if filter_regex:
+ versions = [v for v in versions if re.match(filter_regex, v[1])]
+
versions = sorted(versions, key=cmp_to_key(bb.utils.vercmp))
- return (versions[-1][1], "")
+ if versions:
+ return (versions[-1][1], "")
+ else:
+ return ('', '')
--
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.