|
|
|
@ -19,8 +19,9 @@ import shutil |
|
|
|
|
import typing as T |
|
|
|
|
|
|
|
|
|
from glob import glob |
|
|
|
|
|
|
|
|
|
from .wrap import API_ROOT, open_wrapdburl |
|
|
|
|
from urllib.parse import urlparse |
|
|
|
|
from urllib.request import urlopen |
|
|
|
|
from .wrap import WrapException |
|
|
|
|
|
|
|
|
|
from .. import mesonlib |
|
|
|
|
|
|
|
|
@ -57,38 +58,30 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None: |
|
|
|
|
p.add_argument('project_path') |
|
|
|
|
p.set_defaults(wrap_func=promote) |
|
|
|
|
|
|
|
|
|
def get_result(urlstring: str) -> T.Dict[str, T.Any]: |
|
|
|
|
u = open_wrapdburl(urlstring) |
|
|
|
|
data = u.read().decode('utf-8') |
|
|
|
|
jd = json.loads(data) |
|
|
|
|
if jd['output'] != 'ok': |
|
|
|
|
print('Got bad output from server.', file=sys.stderr) |
|
|
|
|
raise SystemExit(data) |
|
|
|
|
assert isinstance(jd, dict) |
|
|
|
|
return jd |
|
|
|
|
|
|
|
|
|
def get_projectlist() -> T.List[str]: |
|
|
|
|
jd = get_result(API_ROOT + 'projects') |
|
|
|
|
projects = jd['projects'] |
|
|
|
|
assert isinstance(projects, list) |
|
|
|
|
return projects |
|
|
|
|
def get_releases() -> T.Dict[str, T.Any]: |
|
|
|
|
url = urlopen('https://wrapdb.mesonbuild.com/v2/releases.json') |
|
|
|
|
return T.cast(T.Dict[str, T.Any], json.loads(url.read().decode())) |
|
|
|
|
|
|
|
|
|
def list_projects(options: 'argparse.Namespace') -> None: |
|
|
|
|
projects = get_projectlist() |
|
|
|
|
for p in projects: |
|
|
|
|
releases = get_releases() |
|
|
|
|
for p in releases.keys(): |
|
|
|
|
print(p) |
|
|
|
|
|
|
|
|
|
def search(options: 'argparse.Namespace') -> None: |
|
|
|
|
name = options.name |
|
|
|
|
jd = get_result(API_ROOT + 'query/byname/' + name) |
|
|
|
|
for p in jd['projects']: |
|
|
|
|
print(p) |
|
|
|
|
releases = get_releases() |
|
|
|
|
for p in releases.keys(): |
|
|
|
|
if p.startswith(name): |
|
|
|
|
print(p) |
|
|
|
|
|
|
|
|
|
def get_latest_version(name: str) -> tuple: |
|
|
|
|
jd = get_result(API_ROOT + 'query/get_latest/' + name) |
|
|
|
|
branch = jd['branch'] |
|
|
|
|
revision = jd['revision'] |
|
|
|
|
return branch, revision |
|
|
|
|
releases = get_releases() |
|
|
|
|
info = releases.get(name) |
|
|
|
|
if not info: |
|
|
|
|
raise WrapException(f'Wrap {name} not found in wrapdb') |
|
|
|
|
latest_version = info['versions'][0] |
|
|
|
|
version, revision = latest_version.rsplit('-', 1) |
|
|
|
|
return version, revision |
|
|
|
|
|
|
|
|
|
def install(options: 'argparse.Namespace') -> None: |
|
|
|
|
name = options.name |
|
|
|
@ -99,16 +92,28 @@ def install(options: 'argparse.Namespace') -> None: |
|
|
|
|
wrapfile = os.path.join('subprojects', name + '.wrap') |
|
|
|
|
if os.path.exists(wrapfile): |
|
|
|
|
raise SystemExit('Wrap file already exists.') |
|
|
|
|
(branch, revision) = get_latest_version(name) |
|
|
|
|
u = open_wrapdburl(API_ROOT + f'projects/{name}/{branch}/{revision}/get_wrap') |
|
|
|
|
data = u.read() |
|
|
|
|
(version, revision) = get_latest_version(name) |
|
|
|
|
url = urlopen(f'https://wrapdb.mesonbuild.com/v2/{name}_{version}-{revision}/{name}.wrap') |
|
|
|
|
with open(wrapfile, 'wb') as f: |
|
|
|
|
f.write(data) |
|
|
|
|
print('Installed', name, 'branch', branch, 'revision', revision) |
|
|
|
|
f.write(url.read()) |
|
|
|
|
print(f'Installed {name} version {version} revision {revision}') |
|
|
|
|
|
|
|
|
|
def parse_patch_url(patch_url: str) -> T.Tuple[str, int]: |
|
|
|
|
arr = patch_url.split('/') |
|
|
|
|
return arr[-3], int(arr[-2]) |
|
|
|
|
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], int(arr[-2]) |
|
|
|
|
elif arr[0] == 'v2': |
|
|
|
|
# e.g. https://wrapdb.mesonbuild.com/v2/zlib_1.2.11-5/get_patch |
|
|
|
|
tag = arr[-2] |
|
|
|
|
name, version = tag.rsplit('_', 1) |
|
|
|
|
version, revision = version.rsplit('-', 1) |
|
|
|
|
return version, int(revision) |
|
|
|
|
else: |
|
|
|
|
raise WrapException(f'Invalid wrapdb URL {patch_url}') |
|
|
|
|
|
|
|
|
|
def get_current_version(wrapfile: str) -> T.Tuple[str, int, str, str, str]: |
|
|
|
|
cp = configparser.ConfigParser(interpolation=None) |
|
|
|
@ -118,11 +123,10 @@ def get_current_version(wrapfile: str) -> T.Tuple[str, int, str, str, str]: |
|
|
|
|
branch, revision = parse_patch_url(patch_url) |
|
|
|
|
return branch, revision, wrap_data['directory'], wrap_data['source_filename'], wrap_data['patch_filename'] |
|
|
|
|
|
|
|
|
|
def update_wrap_file(wrapfile: str, name: str, new_branch: str, new_revision: str) -> None: |
|
|
|
|
u = open_wrapdburl(API_ROOT + f'projects/{name}/{new_branch}/{new_revision}/get_wrap') |
|
|
|
|
data = u.read() |
|
|
|
|
def update_wrap_file(wrapfile: str, name: str, new_version: str, new_revision: str) -> None: |
|
|
|
|
url = urlopen(f'https://wrapdb.mesonbuild.com/v2/{name}_{new_version}-{new_revision}/{name}.wrap') |
|
|
|
|
with open(wrapfile, 'wb') as f: |
|
|
|
|
f.write(data) |
|
|
|
|
f.write(url.read()) |
|
|
|
|
|
|
|
|
|
def update(options: 'argparse.Namespace') -> None: |
|
|
|
|
name = options.name |
|
|
|
@ -146,17 +150,17 @@ def update(options: 'argparse.Namespace') -> None: |
|
|
|
|
os.unlink(os.path.join('subprojects/packagecache', patch_file)) |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
pass |
|
|
|
|
print('Updated', name, 'to branch', new_branch, 'revision', new_revision) |
|
|
|
|
print(f'Updated {name} version {new_branch} revision {new_revision}') |
|
|
|
|
|
|
|
|
|
def info(options: 'argparse.Namespace') -> None: |
|
|
|
|
name = options.name |
|
|
|
|
jd = get_result(API_ROOT + 'projects/' + name) |
|
|
|
|
versions = jd['versions'] |
|
|
|
|
if not versions: |
|
|
|
|
raise SystemExit('No available versions of' + name) |
|
|
|
|
releases = get_releases() |
|
|
|
|
info = releases.get(name) |
|
|
|
|
if not info: |
|
|
|
|
raise WrapException(f'Wrap {name} not found in wrapdb') |
|
|
|
|
print(f'Available versions of {name}:') |
|
|
|
|
for v in versions: |
|
|
|
|
print(' ', v['branch'], v['revision']) |
|
|
|
|
for v in info['versions']: |
|
|
|
|
print(' ', v) |
|
|
|
|
|
|
|
|
|
def do_promotion(from_path: str, spdir_name: str) -> None: |
|
|
|
|
if os.path.isfile(from_path): |
|
|
|
|