353 lines
8.1 KiB
Python
353 lines
8.1 KiB
Python
# 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" # Nome del file icona in assets/
|
|
|
|
# Path to the assets directory within the package
|
|
# Path(__file__) is the path to this settings.py file
|
|
# .parent is the config/ directory
|
|
# .parent is the project_initializer/ directory
|
|
# / "assets" gives project_initializer/assets/
|
|
PACKAGE_ASSETS_PATH: Path = Path(__file__).resolve().parent.parent / "assets"
|
|
DEFAULT_ICON_PATH: Path = PACKAGE_ASSETS_PATH / DEFAULT_ICON_FILE_NAME
|
|
|
|
|
|
# --- Configuration Management ---
|
|
|
|
def get_config_file_path() -> Path:
|
|
"""
|
|
Gets the path to the configuration file.
|
|
Stores it in the user's home directory.
|
|
"""
|
|
return Path.home() / CONFIG_FILE_NAME
|
|
|
|
def load_app_configuration() -> Dict[str, Any]:
|
|
"""
|
|
Loads the application configuration (e.g., last used root directory).
|
|
Returns a dictionary with the configuration or an empty dictionary if not found/error.
|
|
"""
|
|
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:
|
|
"""
|
|
Saves the application configuration to a JSON file.
|
|
"""
|
|
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:
|
|
"""Returns the .gitignore template string."""
|
|
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
|
|
*~
|
|
|
|
_dist/
|
|
_build/
|
|
"""
|
|
|
|
def get_readme_template(project_name_original: str) -> str:
|
|
"""Returns the README.md template string, formatted with the project name."""
|
|
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:
|
|
"""Returns the __main__.py template string for the new project."""
|
|
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()
|
|
"""
|
|
|
|
def get_spec_file_template(project_name_original: str, project_name_lower: 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'], # Main script of the project being built
|
|
pathex=['.'], # Current directory, where the .spec file is, and project_name_lower is a subfolder
|
|
binaries=[],
|
|
datas=[('{DEFAULT_ICON_FILE_NAME}', '.')], # Icon file relative to project root
|
|
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, # Set to False for GUI-only applications
|
|
icon='{DEFAULT_ICON_FILE_NAME}' # Icon relative to project root
|
|
)
|
|
"""
|
|
|
|
def get_english_manual_template(project_name_original: str) -> str:
|
|
"""Returns the English manual template string."""
|
|
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 <repository_url>`
|
|
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:
|
|
"""Returns the Italian manual template string."""
|
|
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 <repository_url>`
|
|
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.
|
|
""" |