Compare commits
5 Commits
95753d279c
...
23a3985ca2
Author | SHA1 | Date |
---|---|---|
CreateSource | 23a3985ca2 | |
CreateSource | 4a48b0ab21 | |
CreateSource | 9a4fb87d44 | |
CreateSource | b26b99e9e3 | |
CreateSource | c1ce90d1ce |
|
@ -91,6 +91,21 @@ TOOLS: Dict[str, Callable[[str], str]] = {
|
||||||
"wibo": wibo_url,
|
"wibo": wibo_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def download(url, response, output) -> None:
|
||||||
|
if url.endswith(".zip"):
|
||||||
|
data = io.BytesIO(response.read())
|
||||||
|
with zipfile.ZipFile(data) as f:
|
||||||
|
f.extractall(output)
|
||||||
|
# Make all files executable
|
||||||
|
for root, _, files in os.walk(output):
|
||||||
|
for name in files:
|
||||||
|
os.chmod(os.path.join(root, name), 0o755)
|
||||||
|
output.touch(mode=0o755) # Update dir modtime
|
||||||
|
else:
|
||||||
|
with open(output, "wb") as f:
|
||||||
|
shutil.copyfileobj(response, f)
|
||||||
|
st = os.stat(output)
|
||||||
|
os.chmod(output, st.st_mode | stat.S_IEXEC)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -104,22 +119,21 @@ def main() -> None:
|
||||||
|
|
||||||
print(f"Downloading {url} to {output}")
|
print(f"Downloading {url} to {output}")
|
||||||
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||||
with urllib.request.urlopen(req) as response:
|
try:
|
||||||
if url.endswith(".zip"):
|
with urllib.request.urlopen(req) as response:
|
||||||
data = io.BytesIO(response.read())
|
download(url, response, output)
|
||||||
with zipfile.ZipFile(data) as f:
|
except urllib.error.URLError as e:
|
||||||
f.extractall(output)
|
if str(e).find("CERTIFICATE_VERIFY_FAILED") == -1:
|
||||||
# Make all files executable
|
raise e
|
||||||
for root, _, files in os.walk(output):
|
try:
|
||||||
for name in files:
|
import certifi
|
||||||
os.chmod(os.path.join(root, name), 0o755)
|
import ssl
|
||||||
output.touch(mode=0o755) # Update dir modtime
|
except:
|
||||||
else:
|
print("\"certifi\" module not found. Please install it using \"python -m pip install certifi\".")
|
||||||
with open(output, "wb") as f:
|
return
|
||||||
shutil.copyfileobj(response, f)
|
|
||||||
st = os.stat(output)
|
|
||||||
os.chmod(output, st.st_mode | stat.S_IEXEC)
|
|
||||||
|
|
||||||
|
with urllib.request.urlopen(req, context=ssl.create_default_context(cafile=certifi.where())) as response:
|
||||||
|
download(url, response, output)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue