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>
This commit is contained in:
Matt Story 2021-10-26 10:56:13 -04:00
parent 198838599c
commit 11b30b91df

View File

@ -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 @@ def fetch_file(url, verbose=False):
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()