create snapshotsapi, switch fetch-from-snapshots to it
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
diff --git a/fetch-from-snapshots.py b/fetch-from-snapshots.py
index 9962b47..aaf146b 100755
--- a/fetch-from-snapshots.py
+++ b/fetch-from-snapshots.py
@@ -24,6 +24,7 @@
import os
import sys
import re
+import snapshotsapi
def download(api_urls, file_regexp):
"""Example of how to use the API to download a/all files in a directory."""
@@ -46,27 +47,6 @@
with open(os.path.basename(file_info["url"]), 'wb') as fp:
shutil.copyfileobj(req, fp)
-class ApiUrls():
- """Since we want to manipulate URLS, but urlsplit returns an immutable
- object this is a convenience object to perform the manipulations for us"""
- def __init__(self, input_url):
- self.parsed_url = [c for c in urlparse.urlsplit(input_url)]
- self.path = self.parsed_url[2]
-
- def ls(self, path=None):
- if not path:
- path = self.path
- self.parsed_url[2] = "/api/ls" + path
- return urlparse.urlunsplit(self.parsed_url)
-
- def license(self, path):
- self.parsed_url[2] = "/api/license" + path
- return urlparse.urlunsplit(self.parsed_url)
-
- def file(self, path):
- self.parsed_url[2] = path
- return urlparse.urlunsplit(self.parsed_url)
-
def check_for_latest(api_urls):
request = urllib2.urlopen(api_urls.ls())
@@ -87,5 +67,5 @@
print >> sys.stderr, "Example: fetch-from-snapshots.py http://snapshots.linaro.org/openembedded/images/minimal-armv8 linaro-image-minimal.*tar.gz"
exit(1)
- latest = check_for_latest(ApiUrls(sys.argv[1]))
- download(ApiUrls(sys.argv[1] + "/" + latest), sys.argv[2])
+ latest = check_for_latest(snapshotsapi.ApiUrls(sys.argv[1]))
+ download(snapshotsapi.ApiUrls(sys.argv[1] + "/" + latest), sys.argv[2])