diff options
Diffstat (limited to 'scripts/lib/recipetool/create_go.py')
-rw-r--r-- | scripts/lib/recipetool/create_go.py | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index c560831442..a85a2f2786 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py | |||
@@ -16,7 +16,7 @@ from html.parser import HTMLParser | |||
16 | from recipetool.create import RecipeHandler, handle_license_vars | 16 | from recipetool.create import RecipeHandler, handle_license_vars |
17 | from recipetool.create import guess_license, tidy_licenses, fixup_license | 17 | from recipetool.create import guess_license, tidy_licenses, fixup_license |
18 | from recipetool.create import determine_from_url | 18 | from recipetool.create import determine_from_url |
19 | from urllib.error import URLError | 19 | from urllib.error import URLError, HTTPError |
20 | 20 | ||
21 | import bb.utils | 21 | import bb.utils |
22 | import json | 22 | import json |
@@ -225,7 +225,7 @@ class GoRecipeHandler(RecipeHandler): | |||
225 | 225 | ||
226 | def __init__(self): | 226 | def __init__(self): |
227 | super().__init__() | 227 | super().__init__() |
228 | self.__srv = [] | 228 | self.__srv = {} |
229 | 229 | ||
230 | def handle_starttag(self, tag, attrs): | 230 | def handle_starttag(self, tag, attrs): |
231 | if tag == 'meta' and list( | 231 | if tag == 'meta' and list( |
@@ -233,36 +233,34 @@ class GoRecipeHandler(RecipeHandler): | |||
233 | content = list( | 233 | content = list( |
234 | filter(lambda a: (a[0] == 'content'), attrs)) | 234 | filter(lambda a: (a[0] == 'content'), attrs)) |
235 | if content: | 235 | if content: |
236 | self.__srv = content[0][1].split() | 236 | srv = content[0][1].split() |
237 | self.__srv[srv[0]] = srv | ||
237 | 238 | ||
238 | @property | 239 | def go_import(self, modulepath): |
239 | def import_prefix(self): | 240 | if modulepath in self.__srv: |
240 | return self.__srv[0] if len(self.__srv) else None | 241 | srv = self.__srv[modulepath] |
241 | 242 | return GoImport(srv[0], srv[1], srv[2], None) | |
242 | @property | 243 | return None |
243 | def vcs(self): | ||
244 | return self.__srv[1] if len(self.__srv) else None | ||
245 | |||
246 | @property | ||
247 | def repourl(self): | ||
248 | return self.__srv[2] if len(self.__srv) else None | ||
249 | 244 | ||
250 | url = url.geturl() + "?go-get=1" | 245 | url = url.geturl() + "?go-get=1" |
251 | req = urllib.request.Request(url) | 246 | req = urllib.request.Request(url) |
252 | 247 | ||
253 | try: | 248 | try: |
254 | resp = urllib.request.urlopen(req) | 249 | body = urllib.request.urlopen(req).read() |
255 | 250 | except HTTPError as http_err: | |
251 | logger.warning( | ||
252 | "Unclean status when fetching page from [%s]: %s", url, str(http_err)) | ||
253 | body = http_err.fp.read() | ||
256 | except URLError as url_err: | 254 | except URLError as url_err: |
257 | logger.warning( | 255 | logger.warning( |
258 | "Failed to fetch page from [%s]: %s", url, str(url_err)) | 256 | "Failed to fetch page from [%s]: %s", url, str(url_err)) |
259 | return None | 257 | return None |
260 | 258 | ||
261 | parser = GoImportHTMLParser() | 259 | parser = GoImportHTMLParser() |
262 | parser.feed(resp.read().decode('utf-8')) | 260 | parser.feed(body.decode('utf-8')) |
263 | parser.close() | 261 | parser.close() |
264 | 262 | ||
265 | return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) | 263 | return parser.go_import(modulepath) |
266 | 264 | ||
267 | def __resolve_from_golang_proxy(self, modulepath, version): | 265 | def __resolve_from_golang_proxy(self, modulepath, version): |
268 | """ | 266 | """ |