From 9a65697801541e70c544aaf1366916586d66b700 Mon Sep 17 00:00:00 2001 From: dez Date: Thu, 8 Feb 2024 08:49:14 +0100 Subject: [PATCH] sourceforge download fix --- .gitignore | 4 +++- src/donwload_sourceforge.py | 6 +++++- src/download_main.py | 6 ++++++ src/json_main.py | 24 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bc21b37..cab2398 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ lang/ test.py download/ theme.json -test.json \ No newline at end of file +test.json +Spitfire +Spitfire.zip \ No newline at end of file diff --git a/src/donwload_sourceforge.py b/src/donwload_sourceforge.py index d30abec..8b4c217 100644 --- a/src/donwload_sourceforge.py +++ b/src/donwload_sourceforge.py @@ -1,5 +1,6 @@ import requests from tqdm import tqdm +from urllib.parse import urlparse # not exactly ideal solution @@ -11,7 +12,10 @@ def download_from_sourceforge(api_url, file_path): block_size = 1024 # 1 KB progress_bar = tqdm(total=total_size, unit='B', unit_scale=True) - with open(file_path, 'wb') as file: + # Extract the filename from the URL + filename = urlparse(api_url).path.split("/")[-1] + + with open(file_path + filename, 'wb') as file: for data in response.iter_content(block_size): progress_bar.update(len(data)) file.write(data) diff --git a/src/download_main.py b/src/download_main.py index 8500b56..f16b5eb 100644 --- a/src/download_main.py +++ b/src/download_main.py @@ -74,6 +74,7 @@ def download_all_packages(progress_bar, progress_label, download_location, insta tqdm, version ) + json_main.change_package_state(app_name, "downloaded") elif source_type == "gitlab": download_and_update( source_info["gitlab_api_url"], @@ -83,15 +84,19 @@ def download_all_packages(progress_bar, progress_label, download_location, insta tqdm, version ) + json_main.change_package_state(app_name, "downloaded") elif source_type == "sourceforge" or source_type == "raw": donwload_sourceforge.download_from_sourceforge( source_info["url"], os.path.join(download_folder,app_name) ) + json_main.change_package_state(app_name, "downloaded") # Add other source types as needed else: progress_label = f"Unsupported source type for {app_name}: {source_type}" print(f"Unsupported source type for {app_name}: {source_type}") + json_main.change_package_state(app_name, "unsupported source") + break # Check if there are any zip files inside the package folder and unzip them for root, dirs, files in os.walk(os.path.join(download_folder,app_name)): @@ -106,6 +111,7 @@ def download_all_packages(progress_bar, progress_label, download_location, insta traceback.print_exc() progress_label = f"Error processing {app_name}: {e}" print(f"Error processing {app_name}: {e}") + json_main.change_package_state(app_name, "processing error") install_main.install_all_packages(data) diff --git a/src/json_main.py b/src/json_main.py index 15a1f22..cec97f1 100644 --- a/src/json_main.py +++ b/src/json_main.py @@ -58,6 +58,30 @@ def save_package(version, app, source_type, source_info, package_type): with open(data_location, 'w') as file: json.dump(data, file, indent=2) +def change_package_state(package_name, package_state): + try: + with open(data_location, 'r') as file: + data = json.load(file) + except FileNotFoundError: + print("Error: Configuration file not found.") + return + + for package in data.get("packages", []): + if package_name in package: + # Update the state of the specified package + package[package_name]["state"] = package_state + print(f"Package '{package_name}' state changed to '{package_state}'.") + break + else: + print(f"Error: Package '{package_name}' not found.") + + with open(data_location, 'w') as file: + json.dump(data, file, indent=2) + +# # Example usage: +# # Change the state of the package "my_app_github" to "installed" +# change_package_state("my_app_github", "installed") + def check_package_consistency(data): browser_count = 0 style_count = 0