Coverage for src / ezpl / config / defaults.py: 75.51%
43 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-13 19:35 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-13 19:35 +0000
1# ///////////////////////////////////////////////////////////////
2# EZPL - Default Configuration
3# Project: ezpl
4# ///////////////////////////////////////////////////////////////
6"""
7Default configuration values for Ezpl logging framework.
9This module defines all default configuration values used throughout the application.
10"""
12from __future__ import annotations
14# ///////////////////////////////////////////////////////////////
15# IMPORTS
16# ///////////////////////////////////////////////////////////////
17# Standard library imports
18import os
19import sys
20from pathlib import Path
21from typing import Any
23# ///////////////////////////////////////////////////////////////
24# FUNCTIONS
25# ///////////////////////////////////////////////////////////////
28def _get_app_data_dir() -> Path:
29 """
30 Get the application data directory (cross-platform).
32 Returns:
33 - Windows: %APPDATA% (Roaming)
34 - Linux: ~/.local/share
35 - macOS: ~/Library/Application Support
36 """
37 if sys.platform == "win32": 37 ↛ 39line 37 didn't jump to line 39 because the condition on line 37 was never true
38 # Windows: Use APPDATA (Roaming)
39 appdata = os.getenv("APPDATA")
40 if appdata:
41 return Path(appdata) / "ezpl"
42 # Fallback to user home
43 return Path.home() / "AppData" / "Local" / "ezpl"
44 elif sys.platform == "darwin": 44 ↛ 46line 44 didn't jump to line 46 because the condition on line 44 was never true
45 # macOS: ~/Library/Application Support
46 return Path.home() / "Library" / "Application Support" / "ezpl"
47 else:
48 # Linux: ~/.local/share
49 return Path.home() / ".local" / "share" / "ezpl"
52# ///////////////////////////////////////////////////////////////
53# CLASSES
54# ///////////////////////////////////////////////////////////////
57class DefaultConfiguration:
58 """
59 Default configuration values for Ezpl.
61 This class provides centralized access to all default configuration values.
62 """
64 # ///////////////////////////////////////////////////////////////
65 # LOGGING DEFAULTS
66 # ///////////////////////////////////////////////////////////////
68 LOG_LEVEL = "INFO"
69 LOG_FILE = "ezpl.log"
70 # Use cross-platform app data directory for logs if no path specified
71 LOG_DIR = _get_app_data_dir() / "logs"
73 # ///////////////////////////////////////////////////////////////
74 # PRINTER DEFAULTS
75 # ///////////////////////////////////////////////////////////////
77 PRINTER_LEVEL = "INFO"
78 INDENT_STEP = 3
79 INDENT_SYMBOL = ">"
80 BASE_INDENT_SYMBOL = "~"
82 # ///////////////////////////////////////////////////////////////
83 # FILE LOGGER DEFAULTS
84 # ///////////////////////////////////////////////////////////////
86 FILE_LOGGER_LEVEL = "INFO"
87 LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} | {level:<10} | {module}:{function}:{line} - {message}"
89 # Rotation settings (optional - None means no rotation)
90 LOG_ROTATION = None # e.g., "10 MB", "1 day", "500 KB", "12:00", "1 week"
91 LOG_RETENTION = None # e.g., "7 days", "1 month", "10 files"
92 LOG_COMPRESSION = None # e.g., "zip", "gz", "tar.gz"
94 # ///////////////////////////////////////////////////////////////
95 # CONFIGURATION DEFAULTS
96 # ///////////////////////////////////////////////////////////////
98 CONFIG_DIR = Path.home() / ".ezpl"
99 CONFIG_FILE = CONFIG_DIR / "config.json"
101 # ///////////////////////////////////////////////////////////////
102 # EXPORT DEFAULTS
103 # ///////////////////////////////////////////////////////////////
105 EXPORT_BATCH_FILE = "export_env.bat" # Windows
106 EXPORT_SHELL_FILE = "export_env.sh" # Unix/Linux/macOS
108 # ///////////////////////////////////////////////////////////////
109 # CLASS METHODS
110 # ///////////////////////////////////////////////////////////////
112 @classmethod
113 def get_all_defaults(cls) -> dict[str, Any]:
114 """
115 Get all default configuration values as a dictionary.
117 Returns:
118 Dictionary containing all default configuration values
119 """
120 return {
121 "log-level": cls.LOG_LEVEL,
122 "log-file": cls.LOG_FILE,
123 "log-dir": str(
124 cls.LOG_DIR
125 ), # Convert Path to string for JSON serialization
126 "printer-level": cls.PRINTER_LEVEL,
127 "indent-step": cls.INDENT_STEP,
128 "indent-symbol": cls.INDENT_SYMBOL,
129 "base-indent-symbol": cls.BASE_INDENT_SYMBOL,
130 "file-logger-level": cls.FILE_LOGGER_LEVEL,
131 "log-format": cls.LOG_FORMAT,
132 "log-rotation": cls.LOG_ROTATION,
133 "log-retention": cls.LOG_RETENTION,
134 "log-compression": cls.LOG_COMPRESSION,
135 }
137 @classmethod
138 def get_logging_defaults(cls) -> dict[str, Any]:
139 """
140 Get logging-specific default values.
142 Returns:
143 Dictionary containing logging default values
144 """
145 return {
146 "log-level": cls.LOG_LEVEL,
147 "log-file": cls.LOG_FILE,
148 "log-dir": cls.LOG_DIR,
149 }
151 @classmethod
152 def get_printer_defaults(cls) -> dict[str, Any]:
153 """
154 Get printer-specific default values.
156 Returns:
157 Dictionary containing printer default values
158 """
159 return {
160 "printer-level": cls.PRINTER_LEVEL,
161 "indent-step": cls.INDENT_STEP,
162 "indent-symbol": cls.INDENT_SYMBOL,
163 "base-indent-symbol": cls.BASE_INDENT_SYMBOL,
164 }
166 @classmethod
167 def get_file_logger_defaults(cls) -> dict[str, Any]:
168 """
169 Get file logger-specific default values.
171 Returns:
172 Dictionary containing file logger default values
173 """
174 return {
175 "file-logger-level": cls.FILE_LOGGER_LEVEL,
176 "log-format": cls.LOG_FORMAT,
177 "log-rotation": cls.LOG_ROTATION,
178 "log-retention": cls.LOG_RETENTION,
179 "log-compression": cls.LOG_COMPRESSION,
180 }