sourceforge download fix
This commit is contained in:
parent
7d752c068f
commit
9a65697801
4 changed files with 38 additions and 2 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -22,4 +22,6 @@ lang/
|
|||
test.py
|
||||
download/
|
||||
theme.json
|
||||
test.json
|
||||
test.json
|
||||
Spitfire
|
||||
Spitfire.zip
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue