2020-01-18 03:16:14 +08:00
|
|
|
#!/usr/bin/env python3
|
2023-11-16 13:22:14 +08:00
|
|
|
import os
|
|
|
|
import re
|
2020-01-24 05:05:54 +08:00
|
|
|
import subprocess
|
2023-08-26 05:01:10 +08:00
|
|
|
import sys
|
2024-02-25 08:41:23 +08:00
|
|
|
from collections.abc import Iterable
|
2023-08-26 05:01:10 +08:00
|
|
|
|
2022-10-20 05:13:06 +08:00
|
|
|
from tqdm import tqdm
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2023-08-21 11:49:55 +08:00
|
|
|
from openpilot.selfdrive.car.tests.routes import routes as test_car_models_routes
|
|
|
|
from openpilot.selfdrive.test.process_replay.test_processes import source_segments as replay_segments
|
2024-01-18 06:21:47 +08:00
|
|
|
from openpilot.tools.lib.azure_container import AzureContainer
|
|
|
|
from openpilot.tools.lib.openpilotcontainers import DataCIContainer, DataProdContainer, OpenpilotCIContainer
|
2023-08-26 05:01:10 +08:00
|
|
|
|
2024-02-25 08:41:23 +08:00
|
|
|
SOURCES: list[AzureContainer] = [
|
2024-01-18 06:21:47 +08:00
|
|
|
DataProdContainer,
|
|
|
|
DataCIContainer
|
2020-01-24 05:05:54 +08:00
|
|
|
]
|
|
|
|
|
2024-01-18 06:21:47 +08:00
|
|
|
DEST = OpenpilotCIContainer
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2024-02-26 05:29:18 +08:00
|
|
|
def upload_route(path: str, exclude_patterns: Iterable[str] = None) -> None:
|
2022-06-07 05:21:12 +08:00
|
|
|
if exclude_patterns is None:
|
2023-11-16 13:22:14 +08:00
|
|
|
exclude_patterns = [r'dcamera\.hevc']
|
2022-06-07 05:21:12 +08:00
|
|
|
|
2021-06-29 12:44:40 +08:00
|
|
|
r, n = path.rsplit("--", 1)
|
2022-06-07 05:21:12 +08:00
|
|
|
r = '/'.join(r.split('/')[-2:]) # strip out anything extra in the path
|
2021-06-29 12:44:40 +08:00
|
|
|
destpath = f"{r}/{n}"
|
2023-11-16 13:22:14 +08:00
|
|
|
for file in os.listdir(path):
|
|
|
|
if any(re.search(pattern, file) for pattern in exclude_patterns):
|
|
|
|
continue
|
2024-01-18 06:21:47 +08:00
|
|
|
DEST.upload_file(os.path.join(path, file), f"{destpath}/{file}")
|
2021-06-29 12:44:40 +08:00
|
|
|
|
2023-08-26 05:01:10 +08:00
|
|
|
|
|
|
|
def sync_to_ci_public(route: str) -> bool:
|
2024-01-18 06:21:47 +08:00
|
|
|
dest_container, dest_key = DEST.get_client_and_key()
|
2020-01-18 03:16:14 +08:00
|
|
|
key_prefix = route.replace('|', '/')
|
2020-01-31 05:21:14 +08:00
|
|
|
dongle_id = key_prefix.split('/')[0]
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2023-08-26 05:01:10 +08:00
|
|
|
if next(dest_container.list_blob_names(name_starts_with=key_prefix), None) is not None:
|
2020-01-24 05:05:54 +08:00
|
|
|
return True
|
|
|
|
|
2021-05-28 03:20:14 +08:00
|
|
|
print(f"Uploading {route}")
|
2024-01-18 06:21:47 +08:00
|
|
|
for source_container in SOURCES:
|
2023-08-26 05:01:10 +08:00
|
|
|
# assumes az login has been run
|
2024-01-18 06:21:47 +08:00
|
|
|
print(f"Trying {source_container.ACCOUNT}/{source_container.CONTAINER}")
|
|
|
|
_, source_key = source_container.get_client_and_key()
|
2020-01-24 05:05:54 +08:00
|
|
|
cmd = [
|
2020-12-19 05:28:50 +08:00
|
|
|
"azcopy",
|
2020-01-24 05:05:54 +08:00
|
|
|
"copy",
|
2024-01-18 06:21:47 +08:00
|
|
|
f"{source_container.BASE_URL}{key_prefix}?{source_key}",
|
|
|
|
f"{DEST.BASE_URL}{dongle_id}?{dest_key}",
|
2020-01-24 05:05:54 +08:00
|
|
|
"--recursive=true",
|
|
|
|
"--overwrite=false",
|
2020-12-31 13:15:39 +08:00
|
|
|
"--exclude-pattern=*/dcamera.hevc",
|
2020-01-24 05:05:54 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = subprocess.call(cmd, stdout=subprocess.DEVNULL)
|
|
|
|
if result == 0:
|
|
|
|
print("Success")
|
|
|
|
return True
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print("Failed")
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2020-01-24 05:05:54 +08:00
|
|
|
return False
|
2020-01-18 03:16:14 +08:00
|
|
|
|
|
|
|
|
2020-01-24 05:05:54 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
failed_routes = []
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2020-08-09 05:30:31 +08:00
|
|
|
to_sync = sys.argv[1:]
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2020-08-09 05:30:31 +08:00
|
|
|
if not len(to_sync):
|
2022-03-19 04:30:06 +08:00
|
|
|
# sync routes from the car tests routes and process replay
|
2021-05-28 06:29:48 +08:00
|
|
|
to_sync.extend([rt.route for rt in test_car_models_routes])
|
2020-08-09 05:30:31 +08:00
|
|
|
to_sync.extend([s[1].rsplit('--', 1)[0] for s in replay_segments])
|
|
|
|
|
2022-10-20 05:13:06 +08:00
|
|
|
for r in tqdm(to_sync):
|
2020-03-07 05:44:34 +08:00
|
|
|
if not sync_to_ci_public(r):
|
|
|
|
failed_routes.append(r)
|
2020-01-18 03:16:14 +08:00
|
|
|
|
2020-01-24 05:05:54 +08:00
|
|
|
if len(failed_routes):
|
2020-08-09 05:30:31 +08:00
|
|
|
print("failed routes:", failed_routes)
|