config-cli-gui 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ """CLI interface for config-cli-gui using the generic config framework.
2
+
3
+ This file uses the CliGenerator from the generic config framework.
4
+ """
5
+
6
+ from pathlib import Path
7
+
8
+ from config_cli_gui.cli_generator import CliGenerator
9
+ from config_cli_gui.config.config import ConfigParameterManager
10
+ from config_cli_gui.core.base import BaseGPXProcessor
11
+ from config_cli_gui.core.logging import initialize_logging
12
+
13
+
14
+ def validate_config(config: ConfigParameterManager, logger) -> bool:
15
+ """Validate the configuration parameters.
16
+
17
+ Args:
18
+ config: Configuration manager instance
19
+ logger: Logger instance for error reporting
20
+
21
+ Returns:
22
+ True if configuration is valid, False otherwise
23
+ """
24
+ # Get CLI category and check required parameters
25
+ cli_category = config.get_cli_category()
26
+ if not cli_category:
27
+ logger.error("No CLI configuration found")
28
+ return False
29
+
30
+ # Check if input parameter exists and has a value
31
+ input_param = getattr(cli_category, "input", None)
32
+ if not input_param or not input_param.default:
33
+ logger.error("Input is required")
34
+ return False
35
+
36
+ # Check if input file exists
37
+ input_path = Path(input_param.default)
38
+ if not input_path.exists():
39
+ logger.error(f"File not found: {input_path}")
40
+ return False
41
+
42
+ logger.debug(f"Input file validation passed: {input_path}")
43
+ return True
44
+
45
+
46
+ def run_main_processing(config: ConfigParameterManager) -> int:
47
+ """Main processing function that gets called by the CLI generator.
48
+
49
+ Args:
50
+ config: Configuration manager with all settings
51
+
52
+ Returns:
53
+ Exit code (0 for success, non-zero for error)
54
+ """
55
+ # Initialize logging system
56
+ logger_manager = initialize_logging(config)
57
+ logger = logger_manager.get_logger("config_cli_gui.cli")
58
+
59
+ try:
60
+ # Log startup information
61
+ logger.info("Starting config_cli_gui CLI")
62
+ logger_manager.log_config_summary()
63
+
64
+ # Validate configuration
65
+ if not validate_config(config, logger):
66
+ logger.error("Configuration validation failed")
67
+ return 1
68
+
69
+ # Get CLI parameters
70
+ cli_category = config.get_cli_category()
71
+ input_file = cli_category.input.default
72
+ output_file = cli_category.output.default
73
+ min_dist = cli_category.min_dist.default
74
+ extract_waypoints = cli_category.extract_waypoints.default
75
+
76
+ # Get app parameters
77
+ app_category = config.get_category("app")
78
+ date_format = app_category.date_format.default if app_category else "%Y-%m-%d"
79
+
80
+ logger.info(f"Processing input: {input_file}")
81
+
82
+ # Create and run BaseGPXProcessor
83
+ processor = BaseGPXProcessor(
84
+ input_=input_file,
85
+ output=output_file,
86
+ min_dist=min_dist,
87
+ date_format=date_format,
88
+ elevation=extract_waypoints,
89
+ logger=logger,
90
+ )
91
+
92
+ logger.info("Starting conversion process")
93
+
94
+ # Run the processing (adjust method name based on your actual implementation)
95
+ result_files = processor.compress_files()
96
+
97
+ logger.info(f"Successfully processed: {input_file}")
98
+ if output_file:
99
+ logger.info(f"Output written to: {output_file}")
100
+ if result_files:
101
+ logger.info(f"Generated files: {', '.join(result_files)}")
102
+
103
+ logger.info("CLI processing completed successfully")
104
+ return 0
105
+
106
+ except Exception as e:
107
+ logger.error(f"Processing failed: {e}")
108
+ logger.debug("Full traceback:", exc_info=True)
109
+ return 1
110
+
111
+
112
+ def main():
113
+ """Main entry point for the CLI application."""
114
+ # Create the base configuration manager
115
+ config_manager = ConfigParameterManager()
116
+
117
+ # Create CLI generator
118
+ cli_generator = CliGenerator(config_manager=config_manager, app_name="config_cli_gui")
119
+
120
+ # Run the CLI with our main processing function
121
+ return cli_generator.run_cli(
122
+ main_function=run_main_processing,
123
+ description="Process GPX files with various operations like compression, "
124
+ "merging, and POI extraction",
125
+ validator=validate_config,
126
+ )
127
+
128
+
129
+ if __name__ == "__main__":
130
+ import sys
131
+
132
+ sys.exit(main())
File without changes
@@ -0,0 +1,209 @@
1
+ """Central configuration management for config-cli-gui project.
2
+
3
+ This module provides a single source of truth for all configuration parameters
4
+ organized in categories (CLI, App, GUI). It can generate config files, CLI modules,
5
+ and documentation from the parameter definitions.
6
+ """
7
+
8
+ from config_cli_gui.config_framework import (
9
+ BaseConfigCategory,
10
+ CliConfigCategory,
11
+ ConfigManager,
12
+ ConfigParameter,
13
+ DocumentationGenerator,
14
+ )
15
+
16
+
17
+ class CliConfig(CliConfigCategory):
18
+ """CLI-specific configuration parameters."""
19
+
20
+ def get_category_name(self) -> str:
21
+ return "cli"
22
+
23
+ # Positional argument
24
+ input: ConfigParameter = ConfigParameter(
25
+ name="input",
26
+ default="",
27
+ type_=str,
28
+ help="Path to input (file or folder)",
29
+ required=True,
30
+ cli_arg=None, # Positional argument
31
+ )
32
+
33
+ # Optional CLI arguments
34
+ output: ConfigParameter = ConfigParameter(
35
+ name="output",
36
+ default="",
37
+ type_=str,
38
+ help="Path to output destination",
39
+ )
40
+
41
+ min_dist: ConfigParameter = ConfigParameter(
42
+ name="min_dist",
43
+ default=20,
44
+ type_=int,
45
+ help="Maximum distance between two waypoints",
46
+ )
47
+
48
+ extract_waypoints: ConfigParameter = ConfigParameter(
49
+ name="extract_waypoints",
50
+ default=True,
51
+ type_=bool,
52
+ help="Extract starting points of each track as waypoint",
53
+ )
54
+
55
+ elevation: ConfigParameter = ConfigParameter(
56
+ name="elevation",
57
+ default=True,
58
+ type_=bool,
59
+ help="Include elevation data in waypoints",
60
+ )
61
+
62
+
63
+ class AppConfig(BaseConfigCategory):
64
+ """Application-specific configuration parameters."""
65
+
66
+ def get_category_name(self) -> str:
67
+ return "app"
68
+
69
+ date_format: ConfigParameter = ConfigParameter(
70
+ name="date_format",
71
+ default="%Y-%m-%d",
72
+ type_=str,
73
+ help="Date format to use",
74
+ )
75
+
76
+ log_level: ConfigParameter = ConfigParameter(
77
+ name="log_level",
78
+ default="INFO",
79
+ type_=str,
80
+ choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
81
+ help="Logging level for the application",
82
+ )
83
+
84
+ log_file_max_size: ConfigParameter = ConfigParameter(
85
+ name="log_file_max_size",
86
+ default=10,
87
+ type_=int,
88
+ help="Maximum log file size in MB before rotation",
89
+ )
90
+
91
+ log_backup_count: ConfigParameter = ConfigParameter(
92
+ name="log_backup_count",
93
+ default=5,
94
+ type_=int,
95
+ help="Number of backup log files to keep",
96
+ )
97
+
98
+ log_format: ConfigParameter = ConfigParameter(
99
+ name="log_format",
100
+ default="detailed",
101
+ type_=str,
102
+ choices=["simple", "detailed", "json"],
103
+ help="Log message format style",
104
+ )
105
+
106
+ max_workers: ConfigParameter = ConfigParameter(
107
+ name="max_workers",
108
+ default=4,
109
+ type_=int,
110
+ help="Maximum number of worker threads",
111
+ )
112
+
113
+ enable_file_logging: ConfigParameter = ConfigParameter(
114
+ name="enable_file_logging",
115
+ default=True,
116
+ type_=bool,
117
+ help="Enable logging to file",
118
+ )
119
+
120
+ enable_console_logging: ConfigParameter = ConfigParameter(
121
+ name="enable_console_logging",
122
+ default=True,
123
+ type_=bool,
124
+ help="Enable logging to console",
125
+ )
126
+
127
+
128
+ class GuiConfig(BaseConfigCategory):
129
+ """GUI-specific configuration parameters."""
130
+
131
+ def get_category_name(self) -> str:
132
+ return "gui"
133
+
134
+ theme: ConfigParameter = ConfigParameter(
135
+ name="theme",
136
+ default="light",
137
+ type_=str,
138
+ choices=["light", "dark", "auto"],
139
+ help="GUI theme setting",
140
+ )
141
+
142
+ window_width: ConfigParameter = ConfigParameter(
143
+ name="window_width",
144
+ default=800,
145
+ type_=int,
146
+ help="Default window width",
147
+ )
148
+
149
+ window_height: ConfigParameter = ConfigParameter(
150
+ name="window_height",
151
+ default=600,
152
+ type_=int,
153
+ help="Default window height",
154
+ )
155
+
156
+ log_window_height: ConfigParameter = ConfigParameter(
157
+ name="log_window_height",
158
+ default=200,
159
+ type_=int,
160
+ help="Height of the log window in pixels",
161
+ )
162
+
163
+ auto_scroll_log: ConfigParameter = ConfigParameter(
164
+ name="auto_scroll_log",
165
+ default=True,
166
+ type_=bool,
167
+ help="Automatically scroll to newest log entries",
168
+ )
169
+
170
+ max_log_lines: ConfigParameter = ConfigParameter(
171
+ name="max_log_lines",
172
+ default=1000,
173
+ type_=int,
174
+ help="Maximum number of log lines to keep in GUI",
175
+ )
176
+
177
+
178
+ class ConfigParameterManager(ConfigManager): # Inherit from ConfigManager
179
+ """Main configuration manager that handles all parameter categories."""
180
+
181
+ def __init__(self, config_file: str | None = None, **kwargs):
182
+ # Erst den Parent initialisieren
183
+ super().__init__(config_file, **kwargs)
184
+
185
+ # Dann die Kategorien hinzufügen
186
+ self.add_category("cli", CliConfig())
187
+ self.add_category("app", AppConfig())
188
+ self.add_category("gui", GuiConfig())
189
+
190
+
191
+ def main():
192
+ """Main function to generate config file and documentation."""
193
+ default_config: str = "../../config.yaml"
194
+ default_cli_doc: str = "../../docs/usage/cli.md"
195
+ default_config_doc: str = "../../docs/usage/config.md"
196
+ config_manager = ConfigParameterManager()
197
+ docGen = DocumentationGenerator(config_manager)
198
+ docGen.generate_default_config_file(output_file=default_config)
199
+ print(f"Generated: {default_config}")
200
+
201
+ docGen.generate_config_markdown_doc(output_file=default_config_doc)
202
+ print(f"Generated: {default_config_doc}")
203
+
204
+ docGen.generate_cli_markdown_doc(output_file=default_cli_doc)
205
+ print(f"Generated: {default_cli_doc}")
206
+
207
+
208
+ if __name__ == "__main__":
209
+ main()
File without changes