aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/wrap
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
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')
-rw-r--r--mesonbuild/wrap/wrap.py30
-rw-r--r--mesonbuild/wrap/wraptool.py36
2 files changed, 32 insertions, 34 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
diff --git a/mesonbuild/wrap/wraptool.py b/mesonbuild/wrap/wraptool.py
index 80a58ab..be6ceb7 100644
--- a/mesonbuild/wrap/wraptool.py
+++ b/mesonbuild/wrap/wraptool.py
@@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import json
import sys, os
import configparser
import shutil
import typing as T
from glob import glob
-from urllib.parse import urlparse
-from .wrap import open_wrapdburl, WrapException
+from .wrap import (open_wrapdburl, WrapException, get_releases, get_releases_data,
+ update_wrap_file, parse_patch_url)
from pathlib import Path
from .. import mesonlib
@@ -75,14 +74,6 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
help='Allow insecure server connections.')
p.set_defaults(wrap_func=update_db)
-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 list_projects(options: 'argparse.Namespace') -> None:
releases = get_releases(options.allow_insecure)
for p in releases.keys():
@@ -123,23 +114,6 @@ def install(options: 'argparse.Namespace') -> None:
f.write(url.read())
print(f'Installed {name} version {version} revision {revision}')
-def parse_patch_url(patch_url: str) -> T.Tuple[str, str]:
- u = 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}')
-
def get_current_version(wrapfile: str) -> T.Tuple[str, str, str, str, T.Optional[str]]:
cp = configparser.ConfigParser(interpolation=None)
cp.read(wrapfile)
@@ -160,12 +134,6 @@ def get_current_version(wrapfile: str) -> T.Tuple[str, str, str, str, T.Optional
patch_filename = wrap_data['patch_filename']
return branch, revision, wrap_data['directory'], wrap_data['source_filename'], patch_filename
-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 update(options: 'argparse.Namespace') -> None:
name = options.name
if not os.path.isdir('subprojects'):