# ProjectInitializerTool/project_initializer/config/settings.py import json from pathlib import Path from typing import Dict, Any # --- Constants --- CONFIG_FILE_NAME: str = ".project_initializer_config.json" DEFAULT_ICON_FILE_NAME: str = "default_icon.ico" PACKAGE_ASSETS_PATH: Path = Path(__file__).resolve().parent.parent / "assets" DEFAULT_ICON_PATH: Path = PACKAGE_ASSETS_PATH / DEFAULT_ICON_FILE_NAME # --- Configuration Management (invariato) --- def get_config_file_path() -> Path: return Path.home() / CONFIG_FILE_NAME def load_app_configuration() -> Dict[str, Any]: config_path = get_config_file_path() if config_path.exists(): try: with open(config_path, "r", encoding="utf-8") as f: return json.load(f) except json.JSONDecodeError: print(f"Warning: Configuration file {config_path} is corrupted. Using defaults.") return {} except IOError: print(f"Warning: Could not read configuration file {config_path}. Using defaults.") return {} return {} def save_app_configuration(config_data: Dict[str, Any]) -> None: config_path = get_config_file_path() try: with open(config_path, "w", encoding="utf-8") as f: json.dump(config_data, f, indent=4) except IOError: print(f"Error: Could not write configuration file {config_path}.") # --- File Templates --- def get_gitignore_template() -> str: # ... (contenuto invariato, omesso per brevità) ... return """# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a CI server in a temp folder. # Then everything is copied to shipping folder during release. *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # PEP 582; __pypackages__ __pypackages__/ # PEP 621; pyproject.toml sections .pdm.toml .pdm.lock # .venv # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # static analysis tool .flake8 # VS Code .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json .history/ # sublime *.sublime-workspace *.sublime-project # Kate .kateproject .kateproject.lock .katenewfile. Neuen Filenamensvorschlag merken. # Temporary files *.swp *~ """ def get_readme_template(project_name_original: str) -> str: # ... (contenuto invariato, omesso per brevità) ... return f"""# {project_name_original} A brief description of {project_name_original}. ## Features - Feature 1 - Feature 2 ## Getting Started ... ## Contributing ... ## License ... """ def get_main_py_template(project_name_original: str, project_name_lower: str) -> str: # ... (contenuto invariato, omesso per brevità) ... return f"""# {project_name_lower}/__main__.py # Example import assuming your main logic is in a 'main' function # within a 'app' module in your '{project_name_lower}.core' package. # from {project_name_lower}.core.app import main as start_application # # Or, if you have a function in {project_name_lower}.core.core: # from {project_name_lower}.core.core import main_function def main(): print(f"Running {project_name_original}...") # Placeholder: Replace with your application's entry point # Example: start_application() print("To customize, edit '{project_name_lower}/__main__.py' and your core modules.") if __name__ == "__main__": main() """ # --- MODIFICA QUI per accettare project_icon_filename --- def get_spec_file_template(project_name_original: str, project_name_lower: str, project_icon_filename: str) -> str: """Returns the .spec file template string for PyInstaller.""" return f"""# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['{project_name_lower}/__main__.py'], pathex=['.'], binaries=[], # Usa project_icon_filename nella sezione datas datas=[('{project_icon_filename}', '.')], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='{project_name_original}', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True, # Usa project_icon_filename per l'opzione icon icon='{project_icon_filename}' ) """ # --- FINE MODIFICA --- def get_english_manual_template(project_name_original: str) -> str: # ... (contenuto invariato, omesso per brevità) ... return f"""# {project_name_original} - English Manual ## Introduction Welcome to {project_name_original}. This document provides an overview of how to install, use, and understand the project. ## Installation Describe the installation steps here. For example: 1. Clone the repository: `git clone ` 2. Navigate to the project directory: `cd {project_name_original}` 3. Install dependencies: `pip install -r requirements.txt` (if applicable) ## Usage Explain how to run and use the application. - To run the application: `python -m {project_name_original.lower().replace(" ", "_").replace("-", "_")}` - Command-line arguments (if any). - GUI interaction (if any). ## Development Information for developers contributing to the project. - Code structure. - How to run tests. ## Troubleshooting Common issues and their solutions. """ def get_italian_manual_template(project_name_original: str) -> str: # ... (contenuto invariato, omesso per brevità) ... return f"""# {project_name_original} - Manuale Italiano ## Introduzione Benvenuto in {project_name_original}. Questo documento fornisce una panoramica su come installare, utilizzare e comprendere il progetto. ## Installazione Descrivi i passaggi di installazione qui. Ad esempio: 1. Clona il repository: `git clone ` 2. Naviga nella directory del progetto: `cd {project_name_original}` 3. Installa le dipendenze: `pip install -r requirements.txt` (se applicabile) ## Utilizzo Spiega come eseguire e utilizzare l'applicazione. - Per eseguire l'applicazione: `python -m {project_name_original.lower().replace(" ", "_").replace("-", "_")}` - Argomenti da riga di comando (se presenti). - Interazione con la GUI (se presente). ## Sviluppo Informazioni per gli sviluppatori che contribuiscono al progetto. - Struttura del codice. - Come eseguire i test. ## Risoluzione dei problemi Problemi comuni e relative soluzioni. """