Ais
commited on
Update app/download_adapter.py
Browse files- app/download_adapter.py +14 -6
app/download_adapter.py
CHANGED
|
@@ -1,30 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
import gdown
|
| 3 |
import re
|
|
|
|
| 4 |
|
| 5 |
DRIVE_FOLDER_URL = "https://drive.google.com/drive/folders/1S9xT92Zm9rZ4RSCxAe_DLld8vu78mqW4"
|
| 6 |
LOCAL_DEST = "adapter"
|
|
|
|
| 7 |
|
| 8 |
def download_latest_adapter():
|
| 9 |
print("🔽 Downloading adapter folder from Google Drive...")
|
| 10 |
-
gdown.download_folder(url=DRIVE_FOLDER_URL, output=
|
| 11 |
|
| 12 |
all_versions = sorted(
|
| 13 |
-
[d for d in os.listdir(
|
| 14 |
key=lambda x: int(x.split()[-1])
|
| 15 |
)
|
| 16 |
if not all_versions:
|
| 17 |
raise ValueError("❌ No version folders found in Google Drive folder.")
|
| 18 |
|
| 19 |
latest = all_versions[-1]
|
| 20 |
-
src = os.path.join(
|
| 21 |
print(f"✅ Latest adapter found: {latest}")
|
| 22 |
|
| 23 |
os.makedirs(LOCAL_DEST, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
for file in os.listdir(src):
|
| 25 |
-
|
| 26 |
-
dest_file = os.path.join(LOCAL_DEST, file)
|
| 27 |
-
os.system(f"cp '{src_file}' '{dest_file}'")
|
| 28 |
|
| 29 |
print(f"✅ Adapter copied to: {LOCAL_DEST}")
|
| 30 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gdown
|
| 3 |
import re
|
| 4 |
+
import shutil
|
| 5 |
|
| 6 |
DRIVE_FOLDER_URL = "https://drive.google.com/drive/folders/1S9xT92Zm9rZ4RSCxAe_DLld8vu78mqW4"
|
| 7 |
LOCAL_DEST = "adapter"
|
| 8 |
+
TEMP_DIR = "gdrive_tmp"
|
| 9 |
|
| 10 |
def download_latest_adapter():
|
| 11 |
print("🔽 Downloading adapter folder from Google Drive...")
|
| 12 |
+
gdown.download_folder(url=DRIVE_FOLDER_URL, output=TEMP_DIR, quiet=False, use_cookies=False)
|
| 13 |
|
| 14 |
all_versions = sorted(
|
| 15 |
+
[d for d in os.listdir(TEMP_DIR) if re.match(r"version \d+", d)],
|
| 16 |
key=lambda x: int(x.split()[-1])
|
| 17 |
)
|
| 18 |
if not all_versions:
|
| 19 |
raise ValueError("❌ No version folders found in Google Drive folder.")
|
| 20 |
|
| 21 |
latest = all_versions[-1]
|
| 22 |
+
src = os.path.join(TEMP_DIR, latest)
|
| 23 |
print(f"✅ Latest adapter found: {latest}")
|
| 24 |
|
| 25 |
os.makedirs(LOCAL_DEST, exist_ok=True)
|
| 26 |
+
|
| 27 |
+
# Clear any existing files in the adapter folder
|
| 28 |
+
for f in os.listdir(LOCAL_DEST):
|
| 29 |
+
file_path = os.path.join(LOCAL_DEST, f)
|
| 30 |
+
if os.path.isfile(file_path):
|
| 31 |
+
os.remove(file_path)
|
| 32 |
+
|
| 33 |
+
# Copy all files from latest adapter version to local adapter/
|
| 34 |
for file in os.listdir(src):
|
| 35 |
+
shutil.copy(os.path.join(src, file), os.path.join(LOCAL_DEST, file))
|
|
|
|
|
|
|
| 36 |
|
| 37 |
print(f"✅ Adapter copied to: {LOCAL_DEST}")
|
| 38 |
|