Compare commits
5 Commits
95753d279c
...
23a3985ca2
Author | SHA1 | Date |
---|---|---|
CreateSource | 23a3985ca2 | |
CreateSource | 4a48b0ab21 | |
CreateSource | 9a4fb87d44 | |
CreateSource | b26b99e9e3 | |
CreateSource | c1ce90d1ce |
|
@ -91,20 +91,7 @@ TOOLS: Dict[str, Callable[[str], str]] = {
|
||||||
"wibo": wibo_url,
|
"wibo": wibo_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def download(url, response, output) -> None:
|
||||||
def main() -> None:
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument("tool", help="Tool name")
|
|
||||||
parser.add_argument("output", type=Path, help="output file path")
|
|
||||||
parser.add_argument("--tag", help="GitHub tag", required=True)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
url = TOOLS[args.tool](args.tag)
|
|
||||||
output = Path(args.output)
|
|
||||||
|
|
||||||
print(f"Downloading {url} to {output}")
|
|
||||||
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
|
||||||
with urllib.request.urlopen(req) as response:
|
|
||||||
if url.endswith(".zip"):
|
if url.endswith(".zip"):
|
||||||
data = io.BytesIO(response.read())
|
data = io.BytesIO(response.read())
|
||||||
with zipfile.ZipFile(data) as f:
|
with zipfile.ZipFile(data) as f:
|
||||||
|
@ -120,6 +107,33 @@ def main() -> None:
|
||||||
st = os.stat(output)
|
st = os.stat(output)
|
||||||
os.chmod(output, st.st_mode | stat.S_IEXEC)
|
os.chmod(output, st.st_mode | stat.S_IEXEC)
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("tool", help="Tool name")
|
||||||
|
parser.add_argument("output", type=Path, help="output file path")
|
||||||
|
parser.add_argument("--tag", help="GitHub tag", required=True)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
url = TOOLS[args.tool](args.tag)
|
||||||
|
output = Path(args.output)
|
||||||
|
|
||||||
|
print(f"Downloading {url} to {output}")
|
||||||
|
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req) as response:
|
||||||
|
download(url, response, output)
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
if str(e).find("CERTIFICATE_VERIFY_FAILED") == -1:
|
||||||
|
raise e
|
||||||
|
try:
|
||||||
|
import certifi
|
||||||
|
import ssl
|
||||||
|
except:
|
||||||
|
print("\"certifi\" module not found. Please install it using \"python -m pip install certifi\".")
|
||||||
|
return
|
||||||
|
|
||||||
|
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