Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 823832c

Browse files
committed
build_parameters.py: tidy parsing of list html
the existing code is parsing the stringification of a structure, which is just bad form. Extract the href directly from the HTML attributes and use it for further parsing
1 parent 031d70a commit 823832c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

build_parameters.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ def __init__(self):
268268
def handle_starttag(self, tag, attrs):
269269
if tag == 'a':
270270
attr = dict(attrs)
271-
self.links.append(attr)
271+
href = attr.get('href')
272+
self.links.append(href)
272273

273274
html_parser = ParseText()
274275
try:
@@ -287,7 +288,7 @@ def handle_starttag(self, tag, attrs):
287288

288289
for folder in page_links: # Non clever way to filter the strings insert by makehtml.py, unwanted folders, and so.
289290
version_folder = str(folder)
290-
firmware_version_url = f"{firmware_url[:-1]}{version_folder[10:-2]}"
291+
firmware_version_url = f"{firmware_url[:-1]}{version_folder}"
291292
if "stable" in version_folder and not version_folder.endswith("stable"): # If finish with
292293
stableFirmwares.append(firmware_version_url)
293294
elif "latest" in version_folder:
@@ -317,7 +318,8 @@ def __init__(self):
317318
def handle_starttag(self, tag, attrs):
318319
if tag == 'a':
319320
attr = dict(attrs)
320-
self.links.append(attr)
321+
href = attr.get('href')
322+
self.links.append(href)
321323

322324
html_parser = ParseText()
323325
try:
@@ -326,10 +328,10 @@ def handle_starttag(self, tag, attrs):
326328
except Exception as e:
327329
error(f"Board folders list download error: {e}")
328330
finally:
329-
last_item = html_parser.links.pop()
330-
last_folder = last_item['href']
331-
debug(f"Returning link of the last board folder ({last_folder[last_folder.rindex('/')+1:]})")
332-
return last_folder[last_folder.rindex('/')+1:] # clean the partial link
331+
last_folder = html_parser.links.pop()
332+
board_name = os.path.basename(last_folder)
333+
debug(f"Returning link of the last board folder ({board_name})")
334+
return board_name
333335
####################################################################################################
334336

335337
def fetch_commit_hash(version_link, board, file):

0 commit comments

Comments
 (0)