-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathfetch
executable file
·40 lines (30 loc) · 1016 Bytes
/
fetch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# Copyright 2019 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Simpler helper to download files."""
from pathlib import Path
import sys
import libdot
def get_parser():
"""Get a command line parser."""
parser = libdot.ArgumentParser(description=__doc__)
parser.add_argument(
"--base64", action="store_true", help="Decode file using base64."
)
parser.add_argument(
"-o", "--output", type=Path, help="Alternative path to save to."
)
parser.add_argument("args", nargs="+", help="URIs or files to download.")
return parser
def main(argv):
"""The main func!"""
parser = get_parser()
opts = parser.parse_args(argv)
for uri in opts.args:
output = opts.output
if not output:
output = uri.rsplit("/", 1)[-1]
libdot.fetch(uri, output, b64=opts.base64)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))