## Consolidate Configuration Files
### Key Changes: - **Unified Configuration**: Consolidated all configs into single package-named file - **Removed Separate Files**: Deleted wapt_api.ini, smtp.ini, rocket.ini - **Updated Functions**: Modified all functions to read from unified config - **Version Bump**: Updated to version 2-1 ### New Configuration Structure: ``` comi-apps-to-update-on-wapt-server.ini ├── [wapt] # WAPT server credentials ├── [notifications] # Notification preferences ├── [smtp] # Email configuration └── [rocket] # Rocket.Chat configuration ``` ### Benefits: - **Simpler Deployment**: Single config file instead of 4 separate files - **Better Organization**: Related settings grouped together - **Easier Management**: One file to backup and configure - **Cleaner Package**: No scattered configuration files ### Technical Updates: - Updated install() function to copy unified config only - Modified all config reading functions to use unified file path - Enhanced debug output with step-by-step progress tracking
This commit is contained in:
45
setup.py
45
setup.py
@@ -11,18 +11,21 @@ from waptpackage import PackageVersion
|
||||
from common import get_requests_client_cert_session
|
||||
|
||||
def install():
|
||||
plugin_inifiles = glob.glob("*.ini")
|
||||
|
||||
for file in plugin_inifiles:
|
||||
if not isfile(makepath(WAPT.private_dir,file.split("\\")[-1])) :
|
||||
print(f"copie de {file} dans {WAPT.private_dir}")
|
||||
filecopyto(file, WAPT.private_dir)
|
||||
# Copy the unified configuration file
|
||||
package_config_file = "comi-apps-to-update-on-wapt-server.ini"
|
||||
if isfile(package_config_file):
|
||||
target_path = makepath(WAPT.private_dir, package_config_file)
|
||||
if not isfile(target_path):
|
||||
print(f"copie de {package_config_file} dans {WAPT.private_dir}")
|
||||
filecopyto(package_config_file, WAPT.private_dir)
|
||||
else:
|
||||
print(f"Warning: Configuration file {package_config_file} not found")
|
||||
|
||||
def _get_notification_config():
|
||||
"""Returns notification configuration from wapt_api.ini."""
|
||||
"""Returns notification configuration from unified package config file."""
|
||||
try:
|
||||
CONFWAPT = ConfigParser()
|
||||
config_path = makepath(WAPT.private_dir, "wapt_api.ini")
|
||||
config_path = makepath(WAPT.private_dir, "comi-apps-to-update-on-wapt-server.ini")
|
||||
|
||||
if not isfile(config_path):
|
||||
print(f"Warning: Configuration file not found: {config_path}, using defaults")
|
||||
@@ -75,7 +78,7 @@ def _get_wapt_session():
|
||||
"""Initializes and returns a WAPT session."""
|
||||
try:
|
||||
CONFWAPT = ConfigParser()
|
||||
config_path = makepath(WAPT.private_dir, "wapt_api.ini")
|
||||
config_path = makepath(WAPT.private_dir, "comi-apps-to-update-on-wapt-server.ini")
|
||||
|
||||
if not isfile(config_path):
|
||||
raise FileNotFoundError(f"WAPT configuration file not found: {config_path}")
|
||||
@@ -299,8 +302,10 @@ def audit():
|
||||
print("Info: Starting WAPT package audit...")
|
||||
|
||||
# Initialize WAPT session
|
||||
print("Info: Step 1 - Initializing WAPT session...")
|
||||
try:
|
||||
sessionwapt, t, client_private_key_password = _get_wapt_session()
|
||||
print("Info: ✓ WAPT session initialized successfully")
|
||||
except Exception as e:
|
||||
print(f"Error: Failed to initialize WAPT session: {e}")
|
||||
import traceback
|
||||
@@ -308,8 +313,10 @@ def audit():
|
||||
return "ERROR"
|
||||
|
||||
# Get host capabilities
|
||||
print("Info: Step 2 - Getting host capabilities...")
|
||||
try:
|
||||
dict_host_capa = _get_host_capabilities(sessionwapt)
|
||||
print(f"Info: ✓ Host capabilities retrieved: {len(dict_host_capa)} configurations")
|
||||
except Exception as e:
|
||||
print(f"Error: Failed to get host capabilities: {e}")
|
||||
import traceback
|
||||
@@ -321,9 +328,11 @@ def audit():
|
||||
return "OK"
|
||||
|
||||
# Get online packages
|
||||
print("Info: Step 3 - Getting online packages...")
|
||||
try:
|
||||
store = WaptRemoteRepo(name="main", url='https://wapt.tranquil.it/wapt', timeout=10, verify_cert=True)
|
||||
online_package_list = _get_packages_versions(store, dict_host_capa)
|
||||
print(f"Info: ✓ Online packages retrieved for {len(online_package_list)} configurations")
|
||||
except Exception as e:
|
||||
print(f"Error: Failed to fetch online packages: {e}")
|
||||
import traceback
|
||||
@@ -331,6 +340,7 @@ def audit():
|
||||
return "ERROR"
|
||||
|
||||
# Get local packages
|
||||
print("Info: Step 4 - Getting local packages...")
|
||||
try:
|
||||
localstore = WaptRemoteRepo(
|
||||
name="main",
|
||||
@@ -351,6 +361,7 @@ def audit():
|
||||
|
||||
localstore.private_key_password_callback = give_password
|
||||
local_package_list = _get_packages_versions(localstore, dict_host_capa)
|
||||
print(f"Info: ✓ Local packages retrieved for {len(local_package_list)} configurations")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: Failed to fetch local packages: {e}")
|
||||
@@ -386,14 +397,14 @@ def send_to_rocket(message_text, attachments=None):
|
||||
try:
|
||||
print("Info: Attempting to send Rocket.Chat notification...")
|
||||
|
||||
rocket_config_file = makepath(WAPT.private_dir, "rocket.ini")
|
||||
config_file = makepath(WAPT.private_dir, "comi-apps-to-update-on-wapt-server.ini")
|
||||
|
||||
if not isfile(rocket_config_file):
|
||||
print("Warning: Rocket.Chat configuration file not found, skipping notification")
|
||||
if not isfile(config_file):
|
||||
print("Warning: Configuration file not found, skipping Rocket.Chat notification")
|
||||
return False
|
||||
|
||||
conf_wapt = ConfigParser()
|
||||
conf_wapt.read(rocket_config_file)
|
||||
conf_wapt.read(config_file)
|
||||
|
||||
try:
|
||||
webhook_url = conf_wapt.get("rocket", "url")
|
||||
@@ -440,14 +451,14 @@ def send_email(body, subject):
|
||||
try:
|
||||
print("Info: Attempting to send email notification...")
|
||||
|
||||
smtp_config_file = makepath(WAPT.private_dir, "smtp.ini")
|
||||
config_file = makepath(WAPT.private_dir, "comi-apps-to-update-on-wapt-server.ini")
|
||||
|
||||
if not isfile(smtp_config_file):
|
||||
print("Warning: SMTP configuration file not found, skipping email notification")
|
||||
if not isfile(config_file):
|
||||
print("Warning: Configuration file not found, skipping email notification")
|
||||
return False
|
||||
|
||||
conf_wapt = ConfigParser()
|
||||
conf_wapt.read(smtp_config_file)
|
||||
conf_wapt.read(config_file)
|
||||
|
||||
try:
|
||||
from_addr = conf_wapt.get("smtp", "from_addr")
|
||||
|
||||
Reference in New Issue
Block a user