diff --git a/app/downloader.py b/app/downloader.py index d5683d6..4ade60c 100644 --- a/app/downloader.py +++ b/app/downloader.py @@ -27,6 +27,7 @@ def main(): firmware_versions_to_keep = config.get("FIRMWARE_VERSIONS_TO_KEEP", 2) auto_extract = config.get("AUTO_EXTRACT", False) extract_patterns = config.get("EXTRACT_PATTERNS", []) + exclude_patterns = config.get("EXCLUDE_PATTERNS", []) wifi_only = config.get("WIFI_ONLY", True) selected_apk_patterns = config.get('SELECTED_APK_ASSETS', []) @@ -118,13 +119,16 @@ def is_connected_to_wifi(): return False # Function to extract files from zip archives - def extract_files(zip_path, extract_dir, patterns): + def extract_files(zip_path, extract_dir, patterns, exclude_patterns): try: with zipfile.ZipFile(zip_path, 'r') as zip_ref: matched_files = [] for file_info in zip_ref.infolist(): file_name = file_info.filename base_name = os.path.basename(file_name) + # Check if file matches exclude patterns + if any(exclude in base_name for exclude in exclude_patterns): + continue for pattern in patterns: if pattern in base_name: # Extract and flatten directory structure @@ -201,7 +205,7 @@ def check_and_download(releases, latest_release_file, release_type, download_dir download_path = os.path.join(release_dir, file_name) download_file(asset['browser_download_url'], download_path) if auto_extract and file_name.endswith('.zip') and release_type == "Firmware": - extract_files(download_path, release_dir, extract_patterns) + extract_files(download_path, release_dir, extract_patterns, exclude_patterns) downloaded_versions.append(release_tag) # Only update latest_release_file if downloads occurred diff --git a/app/setup_config.py b/app/setup_config.py index 2ee65aa..f34786e 100644 --- a/app/setup_config.py +++ b/app/setup_config.py @@ -136,8 +136,12 @@ def run_setup(): if config.get('EXTRACT_PATTERNS'): current_patterns = ' '.join(config.get('EXTRACT_PATTERNS', [])) print(f"Current patterns: {current_patterns}") - extract_patterns = input("Extraction patterns (leave blank to keep current): ").strip() - if extract_patterns: + extract_patterns = input("Extraction patterns (leave blank to keep current, enter '!' to clear): ").strip() + if extract_patterns == '!': + config['AUTO_EXTRACT'] = False + config['EXTRACT_PATTERNS'] = [] + print("Extraction patterns cleared. No files will be extracted.") + elif extract_patterns: config['AUTO_EXTRACT'] = True config['EXTRACT_PATTERNS'] = extract_patterns.split() else: @@ -150,10 +154,43 @@ def run_setup(): config['EXTRACT_PATTERNS'] = extract_patterns.split() else: config['AUTO_EXTRACT'] = False - print("No extraction patterns provided. Extraction will be skipped.") - print("You can run 'fetchtastic setup' again to set extraction patterns.") + print("No patterns selected, no files will be extracted. Run setup again if you wish to change this.") + # Skip exclude patterns prompt + config['EXCLUDE_PATTERNS'] = [] + # Prompt for exclude patterns if extraction is enabled + if config.get('AUTO_EXTRACT', False) and config.get('EXTRACT_PATTERNS'): + exclude_prompt = "Would you like to exclude any patterns from extraction? [y/n] (default: no): " + exclude_choice = input(exclude_prompt).strip().lower() or 'n' + if exclude_choice == 'y': + print("Enter the keywords to exclude from extraction, separated by spaces.") + print("Example: .hex tcxo") + if config.get('EXCLUDE_PATTERNS'): + current_excludes = ' '.join(config.get('EXCLUDE_PATTERNS', [])) + print(f"Current exclude patterns: {current_excludes}") + exclude_patterns = input("Exclude patterns (leave blank to keep current, enter '!' to clear): ").strip() + if exclude_patterns == '!': + config['EXCLUDE_PATTERNS'] = [] + print("Exclude patterns cleared. No files will be excluded.") + elif exclude_patterns: + config['EXCLUDE_PATTERNS'] = exclude_patterns.split() + else: + # Keep existing patterns + pass + else: + exclude_patterns = input("Exclude patterns: ").strip() + if exclude_patterns: + config['EXCLUDE_PATTERNS'] = exclude_patterns.split() + else: + config['EXCLUDE_PATTERNS'] = [] + else: + # User chose not to exclude patterns + config['EXCLUDE_PATTERNS'] = [] + else: + config['EXCLUDE_PATTERNS'] = [] else: config['AUTO_EXTRACT'] = False + config['EXTRACT_PATTERNS'] = [] + config['EXCLUDE_PATTERNS'] = [] # Ask if the user wants to only download when connected to Wi-Fi wifi_only_default = 'yes' if config.get('WIFI_ONLY', True) else 'no' @@ -316,26 +353,17 @@ def remove_cron_job(): except Exception as e: print(f"An error occurred while removing the cron job: {e}") -def is_cron_job_set(): - try: - result = subprocess.run(['crontab', '-l'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - if result.returncode == 0 and 'fetchtastic download' in result.stdout: - return True - else: - return False - except Exception: - return False - def setup_boot_script(): boot_dir = os.path.expanduser("~/.termux/boot") boot_script = os.path.join(boot_dir, "fetchtastic.sh") if not os.path.exists(boot_dir): os.makedirs(boot_dir) print("Created the Termux:Boot directory.") - print("It seems that Termux:Boot is not installed or hasn't been run yet.") print("Please install Termux:Boot from F-Droid and run it once to enable boot scripts.") + # Write the boot script with open(boot_script, 'w') as f: f.write("#!/data/data/com.termux/files/usr/bin/sh\n") + f.write("sleep 30\n") f.write("fetchtastic download\n") os.chmod(boot_script, 0o700) print("Boot script created to run Fetchtastic on device boot.") diff --git a/setup.cfg b/setup.cfg index f5d7f8b..c32746e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = fetchtastic -version = 0.1.9 +version = 0.1.10 author = Jeremiah K author_email = jeremiahk@gmx.com description = Meshtastic Firmware and APK Downloader