Support more url schemes for getting standalone manifest
urllib.requests.urlopen also supports file, so call it unless the
scheme is 'gs'. This adds http, https, and ftp support.
Change-Id: I3f215c3ebd8e6dee29ba14c7e79ed99d37287109
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/322095
Reviewed-by: Michael Kelly <mkelly@arista.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Matt Story <mstory@arista.com>
diff --git a/fetch.py b/fetch.py
index d79f947..c954a9c 100644
--- a/fetch.py
+++ b/fetch.py
@@ -17,6 +17,8 @@
import subprocess
import sys
from urllib.parse import urlparse
+from urllib.request import urlopen
+
def fetch_file(url, verbose=False):
"""Fetch a file from the specified source using the appropriate protocol.
@@ -39,7 +41,5 @@
print('fatal: error running "gsutil": %s' % e.stderr,
file=sys.stderr)
sys.exit(1)
- if scheme == 'file':
- with open(url[len('file://'):], 'rb') as f:
- return f.read()
- raise ValueError('unsupported url %s' % url)
+ with urlopen(url) as f:
+ return f.read()