diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/gcp.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/gcp.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/bitbake/lib/bb/fetch2/gcp.py b/bitbake/lib/bb/fetch2/gcp.py index eb3e0c6a6b..86546d40bf 100644 --- a/bitbake/lib/bb/fetch2/gcp.py +++ b/bitbake/lib/bb/fetch2/gcp.py | |||
@@ -23,7 +23,6 @@ import urllib.parse, urllib.error | |||
23 | from bb.fetch2 import FetchMethod | 23 | from bb.fetch2 import FetchMethod |
24 | from bb.fetch2 import FetchError | 24 | from bb.fetch2 import FetchError |
25 | from bb.fetch2 import logger | 25 | from bb.fetch2 import logger |
26 | from bb.fetch2 import runfetchcmd | ||
27 | 26 | ||
28 | class GCP(FetchMethod): | 27 | class GCP(FetchMethod): |
29 | """ | 28 | """ |
@@ -47,8 +46,7 @@ class GCP(FetchMethod): | |||
47 | else: | 46 | else: |
48 | ud.basename = os.path.basename(ud.path) | 47 | ud.basename = os.path.basename(ud.path) |
49 | 48 | ||
50 | ud.localfile = d.expand(urllib.parse.unquote(ud.basename)) | 49 | ud.localfile = ud.basename |
51 | ud.basecmd = "gsutil stat" | ||
52 | 50 | ||
53 | def get_gcp_client(self): | 51 | def get_gcp_client(self): |
54 | from google.cloud import storage | 52 | from google.cloud import storage |
@@ -59,17 +57,20 @@ class GCP(FetchMethod): | |||
59 | Fetch urls using the GCP API. | 57 | Fetch urls using the GCP API. |
60 | Assumes localpath was called first. | 58 | Assumes localpath was called first. |
61 | """ | 59 | """ |
60 | from google.api_core.exceptions import NotFound | ||
62 | logger.debug2(f"Trying to download gs://{ud.host}{ud.path} to {ud.localpath}") | 61 | logger.debug2(f"Trying to download gs://{ud.host}{ud.path} to {ud.localpath}") |
63 | if self.gcp_client is None: | 62 | if self.gcp_client is None: |
64 | self.get_gcp_client() | 63 | self.get_gcp_client() |
65 | 64 | ||
66 | bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}") | 65 | bb.fetch2.check_network_access(d, "blob.download_to_filename", f"gs://{ud.host}{ud.path}") |
67 | runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d) | ||
68 | 66 | ||
69 | # Path sometimes has leading slash, so strip it | 67 | # Path sometimes has leading slash, so strip it |
70 | path = ud.path.lstrip("/") | 68 | path = ud.path.lstrip("/") |
71 | blob = self.gcp_client.bucket(ud.host).blob(path) | 69 | blob = self.gcp_client.bucket(ud.host).blob(path) |
72 | blob.download_to_filename(ud.localpath) | 70 | try: |
71 | blob.download_to_filename(ud.localpath) | ||
72 | except NotFound: | ||
73 | raise FetchError("The GCP API threw a NotFound exception") | ||
73 | 74 | ||
74 | # Additional sanity checks copied from the wget class (although there | 75 | # Additional sanity checks copied from the wget class (although there |
75 | # are no known issues which mean these are required, treat the GCP API | 76 | # are no known issues which mean these are required, treat the GCP API |
@@ -91,8 +92,7 @@ class GCP(FetchMethod): | |||
91 | if self.gcp_client is None: | 92 | if self.gcp_client is None: |
92 | self.get_gcp_client() | 93 | self.get_gcp_client() |
93 | 94 | ||
94 | bb.fetch2.check_network_access(d, ud.basecmd, f"gs://{ud.host}{ud.path}") | 95 | bb.fetch2.check_network_access(d, "gcp_client.bucket(ud.host).blob(path).exists()", f"gs://{ud.host}{ud.path}") |
95 | runfetchcmd("%s %s" % (ud.basecmd, f"gs://{ud.host}{ud.path}"), d) | ||
96 | 96 | ||
97 | # Path sometimes has leading slash, so strip it | 97 | # Path sometimes has leading slash, so strip it |
98 | path = ud.path.lstrip("/") | 98 | path = ud.path.lstrip("/") |