diff --git a/.gitignore b/.gitignore index 4791386..2e11b42 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ my_app_gitlab/ data-backup/ .config.json nuitka-crash-report.xml +combined_config.txt +firefox_config.txt diff --git a/src/download_github.py b/src/download_github.py index d12f351..e22b646 100644 --- a/src/download_github.py +++ b/src/download_github.py @@ -2,6 +2,7 @@ import os import requests from tqdm import tqdm +# Not used def fetch_release_version(url): try: response = requests.get(url) @@ -43,10 +44,10 @@ def download_from_github(url, destination, progress_bar, version): total=total_size, unit="B", unit_scale=True, - unit_divisor=1024, + unit_divisor=8192, disable=not progress_bar, ) as bar: - for data in response.iter_content(chunk_size=1024): + for data in response.iter_content(chunk_size=8192): bar.update(len(data)) file.write(data) @@ -56,19 +57,6 @@ def download_from_github(url, destination, progress_bar, version): print("You already have the latest version.") return version -def download_from_url(url, destination, progress_bar, version): - if "github.com" in url: - return download_from_github(url, destination, progress_bar, version) - elif "sourceforge.net" in url: - return download_from_sourceforge(url, destination, progress_bar) - elif "gitlab.com" in url: - return download_from_gitlab(url, destination, progress_bar) - elif "gitea.com" in url: - return download_from_gitea(url, destination, progress_bar) - else: - print("Unsupported platform") - return None - ####################### # # Example usage: diff --git a/src/download_gitlab.py b/src/download_gitlab.py index ddd703e..1ffbffa 100644 --- a/src/download_gitlab.py +++ b/src/download_gitlab.py @@ -106,7 +106,9 @@ def download_and_update(api_url, project_id, private_token, destination_folder, source_code_folder = download_source_from_gitlab(api_url, project_id, private_token, destination_folder, progress_bar) print(f"Source code downloaded to: {source_code_folder}") else: - raise # Re-raise the exception if it's not a 404 error + print(f"Error during download_and_update: {e}") + # Log the error, but continue with the remaining code + pass # ####################################### # # Example usage: diff --git a/src/download_main.py b/src/download_main.py index 7bf1a55..f8e2458 100644 --- a/src/download_main.py +++ b/src/download_main.py @@ -1,9 +1,10 @@ import os from tqdm import tqdm # You might need to install this package using pip if not already installed +import zipfile import json import json_main -import download_gitlab +from download_gitlab import download_and_update import download_github import install_main @@ -34,6 +35,11 @@ def download_from_gitea(api_url, project_id, token, destination, progress_bar, v # Placeholder function for downloading from Gitea print("Gita not supported, yet") +def unzip_file(zip_path, extract_path): + with zipfile.ZipFile(zip_path, 'r') as zip_ref: + zip_ref.extractall(extract_path) + os.remove(zip_path) + # Function to install all packages def download_all_packages(progress_bar, progress_label, download_location, install_location): download_folder = download_location + "/" @@ -59,15 +65,40 @@ def download_all_packages(progress_bar, progress_label, download_location, insta progress_bar.set_fraction(progress_value) if source_type == "github": - download_github.download_from_github(source_info["github_url"], os.path.join(download_folder,app_name), tqdm, version) #(api_url, project_id, token, destination, progress_bar) + download_github.download_from_github( + source_info["github_url"], + os.path.join(download_folder,app_name), + tqdm, + version + ) + #api_url, project_id, token, destination, progress_bar elif source_type == "gitlab": - download_gitlab.download_and_update(source_info["gitlab_api_url"], source_info["project_id"], - source_info["private_token"], os.path.join(download_folder,app_name), tqdm, version) + download_and_update( + source_info["gitlab_api_url"], + source_info["project_id"], + source_info["private_token"], + os.path.join(download_folder,app_name), + tqdm, + version + ) + #api_url, project_id, private_token, destination_folder, progress_bar, current_version + # Add other source types as needed else: progress_label.set_text(f"Unsupported source type for {app_name}: {source_type}") print(f"Unsupported source type for {app_name}: {source_type}") + + # 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)): + for file in files: + if file.endswith(".zip"): + zip_path = os.path.join(root, file) + unzip_file(zip_path, root) + break + except Exception as e: + import traceback + traceback.print_exc() progress_label.set_text(f"Error processing {app_name}: {e}") print(f"Error processing {app_name}: {e}") install_main.install_all_packages() diff --git a/src/install_conf.py b/src/install_conf.py new file mode 100644 index 0000000..65148e0 --- /dev/null +++ b/src/install_conf.py @@ -0,0 +1,59 @@ +import os + +def create_or_update_config(file_path, conf): + if not os.path.exists(file_path): + # Create an empty config file if it doesn't exist + with open(file_path, 'w') as file: + file.write('// Empty Firefox Config File\n') + + with open(file_path, 'r') as file: + lines = file.readlines() + + updated = False + + for i, line in enumerate(lines): + if conf.split(' ')[0] in line: + # If setting already exists, update it and print a warning + lines[i] = f'// WARNING: Updated - {conf}\n' + updated = True + print(f"Warning: Duplicate setting found. Replaced {conf}") + + if not updated: + # If setting doesn't exist, add it + lines.append(f'{conf}\n') + + with open(file_path, 'w') as file: + file.writelines(lines) + +def combine_config_files(file1_path, file2_path, output_file_path): + if not os.path.exists(file1_path): + if not os.path.exists(file2_path): + # If both files are missing, print an error and create an empty file + print("Error: Both config files are missing. Creating an empty one.") + with open(output_file_path, 'w') as output_file: + output_file.write('// Empty Firefox Config File\n') + return + else: + # If the first file is missing, use the second file + with open(file2_path, 'r') as file2: + lines = file2.readlines() + elif not os.path.exists(file2_path): + # If the second file is missing, use the first file + with open(file1_path, 'r') as file1: + lines = file1.readlines() + else: + # Combine the content of both files while avoiding duplicates + with open(file1_path, 'r') as file1, open(file2_path, 'r') as file2: + lines1 = file1.readlines() + lines2 = file2.readlines() + lines = list(set(lines1) | set(lines2)) + + with open(output_file_path, 'w') as output_file: + output_file.writelines(lines) + +# Example usage: +config_file_path1 = 'firefox_config1.txt' +config_file_path2 = 'firefox_config2.txt' +combined_output_path = 'combined_config.txt' + +combine_config_files(config_file_path1, config_file_path2, combined_output_path) diff --git a/src/install_searchengine_auto.py b/src/install_searchengine_auto.py index c4a86bb..c3d36a7 100644 --- a/src/install_searchengine_auto.py +++ b/src/install_searchengine_auto.py @@ -5,7 +5,9 @@ def check_aara_websites(): websites = [ "https://search.spitfirebrowser.com/", "https://araa.extravi.dev/", - "https://tailsx.com/" + "https://tailsx.com/", + "https://search.ttj.dev/", + "https://search.wpme.pl" ] results = [] @@ -16,12 +18,15 @@ def check_aara_websites(): response = requests.get(website, timeout=1) loading_time = response.elapsed.total_seconds() + # This is supid but I guess its needed + loading_time = response.elapsed.total_seconds() + # Measure ping ping_result = ping(website.split("//")[1].split("/")[0], timeout=1) if ping_result is None: - # Set ping to 120ms if the website loads but doesn't respond to ping - ping_result = 0.12 + # Set ping to 100ms if the website loads but doesn't respond to ping + ping_result = 0.1 results.append({ 'website': website, diff --git a/src/json_main.py b/src/json_main.py index d3f1b0c..4feaf7f 100644 --- a/src/json_main.py +++ b/src/json_main.py @@ -10,7 +10,6 @@ def save_first_run(var): with open(data_location, "w") as json_file: json.dump(data, json_file, indent=4) - def get_first_run(): with open(data_location, "r") as json_file: data = json.load(json_file) @@ -25,18 +24,36 @@ def save_package(version, app, source_type, source_info, package_type): # If the file doesn't exist, create an empty dictionary data = {"packages": []} - # Create or update the category for the given app - app_data = { - "version": version, - "source": { - "source_type": source_type, - **source_info - }, - "state": "not installed", - "type": package_type - } + # Check if the app already exists in the packages + for package in data["packages"]: + if app in package: + # Package with the same name already exists, print a warning + print(f"Warning: Package '{app}' already exists. Overriding.") - data["packages"].append({app: app_data}) + # Override the existing package + package[app] = { + "version": version, + "source": { + "source_type": source_type, + **source_info + }, + "state": "not installed", + "type": package_type + } + break + else: + # Create or update the category for the given app + app_data = { + "version": version, + "source": { + "source_type": source_type, + **source_info + }, + "state": "not installed", + "type": package_type + } + + data["packages"].append({app: app_data}) with open(data_location, 'w') as file: json.dump(data, file, indent=2) @@ -54,7 +71,6 @@ def get_package(app): return {} - # ###################### # # save package test diff --git a/src/main.py b/src/main.py index 16faca9..45e5d03 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ if sys.platform == 'win32': import os import tkinter as tk from tkinter import ttk - from urllib.request import urlopen + import requests import zipfile import certifi import ssl @@ -26,14 +26,12 @@ def get_temp_folder(): def download_file(url, destination, progress_callback=None, label_callback=None): - context = ssl.create_default_context(cafile=certifi.where()) - - with urlopen(url, context=context) as response, open(destination, 'wb') as out_file: - total_size = int(response.headers.get('content-length', 0)) - block_size = 1024 - current_size = 0 - while True: - buffer = response.read(block_size) + response = requests.get(url, stream=True) + total_size = int(response.headers.get('content-length', 0)) + block_size = 8192 + current_size = 0 + with open(destination, 'wb') as out_file: + for buffer in response.iter_content(block_size): if not buffer: break out_file.write(buffer)