| #!/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:])) |