diff options
author | akastornov <akastornov@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
commit | 3a2de774d91ca8d7325aaf81c200b1d2047725e6 (patch) | |
tree | 5674a780ce03a8bbd794733a19c7a70d587e4a14 /build/scripts/fetch_resource.py | |
parent | 7bd11ff35e97544d119e43447e3e865f2588ee7f (diff) | |
download | ydb-3a2de774d91ca8d7325aaf81c200b1d2047725e6.tar.gz |
Restoring authorship annotation for <akastornov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'build/scripts/fetch_resource.py')
-rw-r--r-- | build/scripts/fetch_resource.py | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/build/scripts/fetch_resource.py b/build/scripts/fetch_resource.py index d5af311e5d..ba046ad88e 100644 --- a/build/scripts/fetch_resource.py +++ b/build/scripts/fetch_resource.py @@ -1,43 +1,43 @@ -import urllib2 +import urllib2 import argparse -import xmlrpclib - - -def parse_args(): +import xmlrpclib + + +def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('-r', '--resource-id', type=int, required=True) parser.add_argument('-o', '--output', required=True) return parser.parse_args() - - -def fetch(url, retries=4, timeout=5): - for i in xrange(retries): - try: - return urllib2.urlopen(url, timeout=timeout).read() - - except Exception: - if i + 1 < retries: - continue - - else: - raise - - -def fetch_resource(id_): + + +def fetch(url, retries=4, timeout=5): + for i in xrange(retries): + try: + return urllib2.urlopen(url, timeout=timeout).read() + + except Exception: + if i + 1 < retries: + continue + + else: + raise + + +def fetch_resource(id_): urls = xmlrpclib.ServerProxy("https://sandbox.yandex-team.ru/sandbox/xmlrpc").get_resource_http_links(id_) - - for u in urls: - try: - return fetch(u) - + + for u in urls: + try: + return fetch(u) + except Exception: - continue - - raise Exception('Cannot fetch resource {}'.format(id_)) - - -if __name__ == '__main__': + continue + + raise Exception('Cannot fetch resource {}'.format(id_)) + + +if __name__ == '__main__': args = parse_args() - + with open(args.output, 'wb') as f: f.write(fetch_resource(int(args.resource_id))) |