Skip to content
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

Add utility to download and install navvis test data #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ coverage.xml
local_settings.py
db.sqlite3

# NavVis test data.
scantools/tests/test_data/*

# Flask stuff:
instance/
.webassets-cache
Expand Down
32 changes: 32 additions & 0 deletions scantools/tests/download_navvis_test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import requests
import hashlib
import zipfile
import os

datasetUrl = "https://github.com/microsoft/lamar-benchmark/releases/download/v1.1/NavVisTestData.zip"
expectedSha1 = "0a28991004e58d9dc51167ea23f9f2ba66b26ab5"
zipFileName = "NavVisTestData.zip"

print("Downloading NavVis test data...")

if(os.path.exists(zipFileName)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would make that this script takes an output folder, and outside you create a temporal directory, something like:
navvis_test_data_path = Path(tempfile.mkdtemp())

Then you avoid check if exists, also you can remove the .gitignore. The idea is not to populate the git repo with untracked files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k will come back to this

os.remove(zipFileName)

if(os.path.exists("test_data")):
os.rmdir("test_data")

response = requests.get(datasetUrl)
if response.status_code == 200:
sha1 = hashlib.sha1(response.content).hexdigest()
if sha1 == expectedSha1:
with open(zipFileName, "wb") as file:
file.write(response.content)
with zipfile.ZipFile(zipFileName, "r") as zip_ref:
zip_ref.extractall(".")
os.remove(zipFileName)
print("NavVis test data downloaded and extracted successfully.")
else:
print("SHA1 hash mismatch. The downloaded file may be corrupted.")
else:
print("Failed to download the zip file from", datasetUrl)