-
Notifications
You must be signed in to change notification settings - Fork 72
Extend api to serve standard builds path list from firmware server #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shiv-tyagi
wants to merge
5
commits into
ArduPilot:main
Choose a base branch
from
shiv-tyagi:ap-metadata-server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+572
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09d006e
utils: add apache dir html parser
shiv-tyagi 2225c1f
builder: add beautifulsoup to requirements.txt
shiv-tyagi e9021a2
metadata_manager: add method to fetch build artifacts list from firmw…
shiv-tyagi 44a5be2
web: extend api to list standard build files from firmware server
shiv-tyagi 6c9211f
tests: add tests for standard artifacts api endpoint
shiv-tyagi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| jsonschema | ||
| redis | ||
| dill==0.3.8 | ||
| beautifulsoup4==4.12.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <html> | ||
| <body> | ||
| <table width=80%> | ||
| <tr bgcolor="#aaaaaa"><td width=50 align=center><b>Type</b></td><td><b>Filename</b></td><td><b>Date</b></td><td><b>Size</b></td></tr> | ||
| <tr bgcolor="#ffffff"><td align=center><img src="/icons/back.gif"></td><td><a href="/Copter/stable-4.5.0"><b>Parent Directory</B> </a></td> | ||
| <td>--</td><td>--</td> | ||
| <tr bgcolor="#cacaca"> | ||
| <td align=center><img src="/icons/text.gif"></td> | ||
| <td><a href="/Copter/stable-4.5.0/CubeOrange/arducopter.abin">arducopter.abin</a></td> | ||
| <td>Tue Apr 2 05:11:12 2024</td> | ||
| <td>1814971</td> | ||
| </tr> | ||
| <tr bgcolor="#ffffff"> | ||
| <td align=center><img src="/icons/text.gif"></td> | ||
| <td><a href="/Copter/stable-4.5.0/CubeOrange/arducopter.apj">arducopter.apj</a></td> | ||
| <td>Tue Apr 15 05:11:12 2024</td> | ||
| <td>1640045</td> | ||
| </tr> | ||
| <tr bgcolor="#cacaca"> | ||
| <td align=center><img src="/icons/text.gif"></td> | ||
| <td><a href="/Copter/stable-4.5.0/CubeOrange/features.txt">features.txt</a></td> | ||
| <td>Tue Apr 2 05:11:12 2024</td> | ||
| <td>8294</td> | ||
| </tr> | ||
| </table> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """ | ||
| Tests for Apache directory listing parser. | ||
| """ | ||
| from datetime import datetime, timezone | ||
| from pathlib import Path | ||
|
|
||
| from utils.apache_dir_listing import parse_apache_dir_listing, _parse_apache_date | ||
|
|
||
|
|
||
| FIXTURES_DIR = Path(__file__).parent / "fixtures" | ||
| SAMPLE_LISTING_HTML = (FIXTURES_DIR / "apache_dir_listing_sample.html").read_text() | ||
| BASE_URL = "https://firmware.ardupilot.org/Copter/stable-4.5.0/CubeOrange/" | ||
|
|
||
|
|
||
| class TestParseApacheDate: | ||
| def test_parses_single_digit_day(self): | ||
| result = _parse_apache_date("Tue Apr 2 05:11:12 2024") | ||
| assert result == datetime(2024, 4, 2, 5, 11, 12, tzinfo=timezone.utc) | ||
|
|
||
| def test_parses_double_digit_day(self): | ||
| result = _parse_apache_date("Tue Apr 15 05:11:12 2024") | ||
| assert result == datetime(2024, 4, 15, 5, 11, 12, tzinfo=timezone.utc) | ||
|
|
||
| def test_returns_none_for_dash(self): | ||
| assert _parse_apache_date("--") is None | ||
|
|
||
| def test_returns_none_for_invalid(self): | ||
| assert _parse_apache_date("not a date") is None | ||
|
|
||
|
|
||
| class TestParseApacheDirListing: | ||
| def test_parses_files_and_skips_parent_directory(self): | ||
| entries = parse_apache_dir_listing(SAMPLE_LISTING_HTML, BASE_URL) | ||
|
|
||
| assert len(entries) == 3 | ||
| assert entries[0]["name"] == "arducopter.abin" | ||
| assert entries[1]["name"] == "arducopter.apj" | ||
| assert entries[2]["name"] == "features.txt" | ||
|
|
||
| def test_resolves_absolute_urls(self): | ||
| entries = parse_apache_dir_listing(SAMPLE_LISTING_HTML, BASE_URL) | ||
|
|
||
| assert entries[0]["url"] == ( | ||
| "https://firmware.ardupilot.org/Copter/stable-4.5.0/" | ||
| "CubeOrange/arducopter.abin" | ||
| ) | ||
|
|
||
| def test_parses_size_and_modified(self): | ||
| entries = parse_apache_dir_listing(SAMPLE_LISTING_HTML, BASE_URL) | ||
|
|
||
| assert entries[0]["size"] == 1814971 | ||
| assert entries[0]["modified"] == datetime( | ||
| 2024, 4, 2, 5, 11, 12, tzinfo=timezone.utc | ||
| ) | ||
| assert entries[1]["modified"] == datetime( | ||
| 2024, 4, 15, 5, 11, 12, tzinfo=timezone.utc | ||
| ) | ||
|
|
||
| def test_returns_empty_list_when_no_table(self): | ||
| assert parse_apache_dir_listing("<html><body></body></html>", BASE_URL) == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. Why aren't you using the manifest file? It's there explicitly so this sort of thing is not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of reasons I avoided that this time.
We already have the path for firmware server builds (firmware.ardupilot.org//) for each version listed on the custom build server. We construct it in the version fetcher module.
To get the list of artifacts for a board, we just need to append the board name to it to get the exact path where that board's artifacts are stored.
We have been using this approach for quite some time. It is already used to retrieve the features.txt file. All we need to do to get the list of all versions is extend the same logic to also retrieve the list of files from there.
Using manifests.json is a much larger piece of work. We would need to download a file (over 60 MB today) asynchronously, parse it, group the entries by version and board, and then map them to the versions listed on custom.ardupilot.org (which come directly from GitHub tags).
I agree that this approach would be more correct overall, but in my opinion, extending what we already use for features.txt is the right approach for now.