build_parameters.py: fix htmlparser#7597
Conversation
1c890b9 to
fc6adca
Compare
4cfca13 to
cf6be4b
Compare
|
rebased on #7650 |
b17a6c9 to
4e90730
Compare
|
rebased after #7659 |
| if tag == 'a': | ||
| attr = dict(attrs) | ||
| self.links.append(attr) | ||
| href = attr.get('href') |
There was a problem hiding this comment.
we just need the link so no need to capture the whole section
There was a problem hiding this comment.
attr : {'href': '/Copter/stable-4.4.2'}
href : /Copter/stable-4.4.2
| for folder in page_links: # Non clever way to filter the strings insert by makehtml.py, unwanted folders, and so. | ||
| version_folder = str(folder) | ||
| firmware_link = f"{firmware_url[:-1]}{version_folder[10:-2]}" | ||
| firmware_version_url = f"{firmware_url[:-1]}{version_folder}" |
There was a problem hiding this comment.
as we got on the href, we don't need to discard the marking
There was a problem hiding this comment.
master:
version folder: {'href': '/Copter/stable-4.6.2'}
firmware version url: https://firmware.ardupilot.org/Copter/stable-4.6.2
PR:
version folder: /Copter/stable-4.6.3
firmware version url: https://firmware.ardupilot.org/Copter/stable-4.6.3
| last_folder = last_item['href'] | ||
| debug(f"Returning link of the last board folder ({last_folder[last_folder.rindex('/')+1:]})") | ||
| return last_folder[last_folder.rindex('/')+1:] # clean the partial link | ||
| if len(html_parser.links) == 0: |
There was a problem hiding this comment.
fix the case of empty list (that shouldn't happens but ...)
There was a problem hiding this comment.
Won't this happen any time the server returns HTTP 500 Still dividing by zero?
There was a problem hiding this comment.
yes but that would need to be handled on the Exception level. This just handle the fact the sever respond by with empty or not well formatted page and prevent raising an exception.
Unless you prefer to raise on such case ? But if that happens how do we get notification as this happens on the server ? (no CI for parameter versionning yet)
| error(f"No board folders found in {url}, skipping this release.") | ||
| return "" | ||
| last_folder = html_parser.links.pop() | ||
| board_name = os.path.basename(last_folder) |
There was a problem hiding this comment.
this is simpler to get the last part of the url
| fetch_link = f"{version_link}/{board}/{file}" | ||
|
|
||
| progress(f"Processing link...\t{fetch_link}") | ||
| if board == "": |
There was a problem hiding this comment.
handle the empty list error
02479e3 to
4d4df74
Compare
fix class fix error handling fix parsing element simplify elements parsed and return
fix class (python use capitalize name, links was missing from class but use in exception handling)
fix error handling
fix parsing element
simplify elements parsed and return: get the href directly as that is what interest us and simplify the parsing, pre-filter links to keep only the necessary, do better return to avoid broad exception on missing directory