Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import zipfile
- from pathlib import Path
- from tkinter import filedialog
- CONFIG_FILE_NAME = 'qt-config.ini'
- def resolve_path(path: str | Path) -> Path:
- if getattr(sys, "frozen", False):
- # If the script is running as a bundled app (.exe)
- script_dir = Path(sys.executable).resolve().parent
- else:
- # If the script is running in development mode
- script_dir = Path(__file__).resolve().parent
- return script_dir / path
- def open_qt_config() -> None:
- # Locate "qt-config.ini" file in the "config" folder
- config_dir = resolve_path('config')
- for file in config_dir.rglob(CONFIG_FILE_NAME):
- if file.is_file():
- qt_config_file = file
- break
- else:
- print(f"No '{CONFIG_FILE_NAME}' file found in the 'config' folder.")
- return
- with open(qt_config_file) as file:
- for line in file:
- if line.startswith('nand_directory='):
- input_folder = Path(line.replace('nand_directory=', '').strip(), 'user', 'save')
- break
- else:
- print(f"No 'nand_directory' entry found in '{CONFIG_FILE_NAME}'.")
- return
- # Select output file
- output_file = filedialog.asksaveasfilename(
- title="Select output file",
- defaultextension=".zip",
- filetypes=(("Zip Files", "*.zip"),)
- )
- if not output_file:
- print("No output file location or name selected.")
- return
- # Create a .zip file in write mode
- with zipfile.ZipFile(output_file, "w", compression=zipfile.ZIP_DEFLATED) as zipf:
- # Traverse files and folders in the input folder
- for file in input_folder.rglob('*'):
- if file.is_dir() or 'cache' in str(file.parent):
- continue
- relative_path = file.relative_to(input_folder)
- zipf.write(file, arcname=relative_path)
- print(f"Compressed file copy created at: {output_file}")
- if __name__ == "__main__":
- open_qt_config()
- input("Press Enter to exit.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement