Skip to content

Commit 2c46786

Browse files
committed
added support for downloading latest nightly
1 parent 5a98b75 commit 2c46786

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

setup.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import subprocess
1818
import sys
1919
import sysconfig
20+
import tarfile
2021
import urllib.request
2122
from ctypes.util import find_library
2223
from pathlib import Path
@@ -67,9 +68,16 @@ def libzim_major(self) -> str:
6768
def found_libzim(self) -> str:
6869
return find_library("zim")
6970

71+
@property
72+
def is_latest_nightly(self) -> bool:
73+
"""will use redirect to latest available nightly"""
74+
return self.libzim_dl_version == "nightly"
75+
7076
@property
7177
def is_nightly(self) -> bool:
72-
return re.match(r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version)
78+
return self.is_latest_nightly or re.match(
79+
r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version
80+
)
7381

7482
@property
7583
def platform(self) -> str:
@@ -143,8 +151,13 @@ def get_download_filename(self, arch: Optional[str] = None) -> str:
143151
if self.platform == "Linux":
144152
variant = "-musl" if self.is_musl else "-bionic"
145153

154+
if self.is_latest_nightly:
155+
version_suffix = ""
156+
else:
157+
version_suffix = f"-{self.libzim_dl_version}"
158+
146159
return pathlib.Path(
147-
f"libzim_{lzplatform}-{arch}{variant}-{self.libzim_dl_version}.tar.gz"
160+
f"libzim_{lzplatform}-{arch}{variant}{version_suffix}.tar.gz"
148161
).name
149162

150163
def download_to_dest(self):
@@ -196,7 +209,9 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
196209

197210
fpath = self.base_dir / filename
198211
source_url = "http://download.openzim.org/release/libzim"
199-
if self.is_nightly:
212+
if self.is_latest_nightly:
213+
source_url = "http://download.openzim.org/nightly"
214+
elif self.is_nightly:
200215
source_url = f"http://download.openzim.org/nightly/{self.libzim_dl_version}"
201216
url = f"{source_url}/{fpath.name}"
202217

@@ -213,7 +228,14 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
213228
print("> extracting archive")
214229
# extract into current folder (all files are inside an in-tar folder)
215230
shutil.unpack_archive(fpath, self.base_dir, "gztar")
216-
folder = fpath.with_name(fpath.name.replace(".tar.gz", ""))
231+
232+
# nightly have different download name and extracted folder name as it
233+
# uses a redirect
234+
if self.is_latest_nightly:
235+
tar = tarfile.open(fpath)
236+
folder = pathlib.Path(pathlib.Path(tar.firstmember.name).parts[0])
237+
else:
238+
folder = fpath.with_name(fpath.name.replace(".tar.gz", ""))
217239

218240
return folder
219241

0 commit comments

Comments
 (0)