aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/fetch_resource.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
committeralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /build/scripts/fetch_resource.py
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
downloadydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz
add ymake export to ydb
Diffstat (limited to 'build/scripts/fetch_resource.py')
-rw-r--r--build/scripts/fetch_resource.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/build/scripts/fetch_resource.py b/build/scripts/fetch_resource.py
new file mode 100644
index 0000000000..d5af311e5d
--- /dev/null
+++ b/build/scripts/fetch_resource.py
@@ -0,0 +1,43 @@
+import urllib2
+import argparse
+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_):
+ urls = xmlrpclib.ServerProxy("https://sandbox.yandex-team.ru/sandbox/xmlrpc").get_resource_http_links(id_)
+
+ for u in urls:
+ try:
+ return fetch(u)
+
+ except Exception:
+ 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)))