aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/wrap/wrap.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-05-06 18:30:18 -0400
committerXavier Claessens <xavier.claessens@collabora.com>2022-10-10 17:09:26 -0400
commitcd82804533d2b858564d960576f126c044849cb3 (patch)
tree02f8727574de758fde21002227cd41db59815f96 /mesonbuild/wrap/wrap.py
parent312bede4967efd531614fe0dbe51f1b94d653e86 (diff)
downloadmeson-cd82804533d2b858564d960576f126c044849cb3.zip
meson-cd82804533d2b858564d960576f126c044849cb3.tar.gz
meson-cd82804533d2b858564d960576f126c044849cb3.tar.bz2
Move some code from wraptool.py to wrap.py
Diffstat (limited to 'mesonbuild/wrap/wrap.py')
-rw-r--r--mesonbuild/wrap/wrap.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index e62614f..b1c2205 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -107,6 +107,36 @@ def open_wrapdburl(urlstring: str, allow_insecure: bool = False, have_opt: bool
except urllib.error.URLError as excp:
raise WrapException(f'WrapDB connection failed to {urlstring} with error {excp}')
+def get_releases_data(allow_insecure: bool) -> bytes:
+ url = open_wrapdburl('https://wrapdb.mesonbuild.com/v2/releases.json', allow_insecure, True)
+ return url.read()
+
+def get_releases(allow_insecure: bool) -> T.Dict[str, T.Any]:
+ data = get_releases_data(allow_insecure)
+ return T.cast('T.Dict[str, T.Any]', json.loads(data.decode()))
+
+def update_wrap_file(wrapfile: str, name: str, new_version: str, new_revision: str, allow_insecure: bool) -> None:
+ url = open_wrapdburl(f'https://wrapdb.mesonbuild.com/v2/{name}_{new_version}-{new_revision}/{name}.wrap',
+ allow_insecure, True)
+ with open(wrapfile, 'wb') as f:
+ f.write(url.read())
+
+def parse_patch_url(patch_url: str) -> T.Tuple[str, str]:
+ u = urllib.parse.urlparse(patch_url)
+ if u.netloc != 'wrapdb.mesonbuild.com':
+ raise WrapException(f'URL {patch_url} does not seems to be a wrapdb patch')
+ arr = u.path.strip('/').split('/')
+ if arr[0] == 'v1':
+ # e.g. https://wrapdb.mesonbuild.com/v1/projects/zlib/1.2.11/5/get_zip
+ return arr[-3], arr[-2]
+ elif arr[0] == 'v2':
+ # e.g. https://wrapdb.mesonbuild.com/v2/zlib_1.2.11-5/get_patch
+ tag = arr[-2]
+ _, version = tag.rsplit('_', 1)
+ version, revision = version.rsplit('-', 1)
+ return version, revision
+ else:
+ raise WrapException(f'Invalid wrapdb URL {patch_url}')
class WrapException(MesonException):
pass