|
13 | 13 | - Metadata caching to reduce redundant downloads. |
14 | 14 | """ |
15 | 15 |
|
16 | | -from pathlib import Path |
| 16 | +from .settings import settings |
17 | 17 |
|
18 | | - |
19 | | -class AppConfig: |
20 | | - """Manages application-wide configuration settings. |
21 | | -
|
22 | | - This class uses class variables to store configuration data and |
23 | | - class methods to manage and access that data. It provides access |
24 | | - to configuration parameters such as verbosity level, log file path, |
25 | | - and the metadata cache file path. |
26 | | - """ |
27 | | - |
28 | | - _cache_file: Path = Path("metadata_cache.json") |
29 | | - _log_file: Path | None = None |
30 | | - _max_concurrency: int = 10 |
31 | | - _report_dir: Path = Path("recipe_reports") |
32 | | - _verbosity_level: int = 0 |
33 | | - |
34 | | - @classmethod |
35 | | - def set_config( |
36 | | - cls, |
37 | | - *, |
38 | | - max_concurrency: int | None = None, |
39 | | - verbosity_level: int | None = None, |
40 | | - cache_file: Path | None = None, |
41 | | - report_dir: Path | None = None, |
42 | | - log_file: Path | None = None, |
43 | | - ) -> None: |
44 | | - """Set the application configuration parameters. |
45 | | -
|
46 | | - This method updates the class variables that store the verbosity |
47 | | - level, log file path, and cache file path. It does *not* initialize |
48 | | - the logging system; `initialize_logger()` must be called separately. |
49 | | -
|
50 | | - Args: |
51 | | - verbosity_level: The integer verbosity level (0, 1, 2, etc.). |
52 | | - max_concurrency: The integer concurrency limit. |
53 | | - log_file: Optional path to the log file. If specified, logging |
54 | | - output will be written to this file in addition to the console. |
55 | | - cache_file: The path to the cache file. |
56 | | - report_dir: The path to the directory used for storing AutoPkg recipe |
57 | | - recipts and recipe reports. |
58 | | - """ |
59 | | - if verbosity_level is not None: |
60 | | - cls._verbosity_level = verbosity_level |
61 | | - |
62 | | - if log_file is not None: |
63 | | - cls._log_file = log_file |
64 | | - |
65 | | - if cache_file is not None: |
66 | | - cls._cache_file = cache_file |
67 | | - |
68 | | - if max_concurrency is not None: |
69 | | - cls._max_concurrency = max_concurrency |
70 | | - |
71 | | - if report_dir is not None: |
72 | | - cls._report_dir = report_dir |
73 | | - |
74 | | - @classmethod |
75 | | - def cache_file(cls) -> Path: |
76 | | - """Returns the path to the metadata cache file.""" |
77 | | - return cls._cache_file |
78 | | - |
79 | | - @classmethod |
80 | | - def log_file(cls) -> Path | None: |
81 | | - """Returns the path to the log file, if any. |
82 | | -
|
83 | | - Returns: |
84 | | - The path to the log file as a `pathlib.Path`, or None if no log file is |
85 | | - configured. |
86 | | - """ |
87 | | - return cls._log_file |
88 | | - |
89 | | - @classmethod |
90 | | - def report_dir(cls) -> Path: |
91 | | - """Returns the directory path for recipe reports. |
92 | | -
|
93 | | - Returns: |
94 | | - The path to the report directory as a `pathlib.Path`. |
95 | | - """ |
96 | | - return cls._report_dir |
97 | | - |
98 | | - @classmethod |
99 | | - def max_concurrency(cls) -> int: |
100 | | - """Returns the maximum number of concurrent tasks. |
101 | | -
|
102 | | - Returns: |
103 | | - Returns the maximum number of concurrent tasks as an integer. |
104 | | - """ |
105 | | - return cls._max_concurrency |
106 | | - |
107 | | - @classmethod |
108 | | - def verbosity_int(cls, delta: int = 0) -> int: |
109 | | - """Returns the verbosity level. |
110 | | -
|
111 | | - Args: |
112 | | - delta: An optional integer to add to the base verbosity level. |
113 | | - This can be used to temporarily increase or decrease the |
114 | | - verbosity for specific operations. |
115 | | -
|
116 | | - Returns: |
117 | | - The integer verbosity level, adjusted by the delta. |
118 | | - """ |
119 | | - level = cls._verbosity_level + delta |
120 | | - if level <= 0: |
121 | | - return 0 |
122 | | - return level |
123 | | - |
124 | | - @classmethod |
125 | | - def verbosity_str(cls, delta: int = 0) -> str: |
126 | | - """Convert an integer verbosity level to a string of `-v` flags. |
127 | | -
|
128 | | - Args: |
129 | | - delta: An optional integer to add to the base verbosity level. |
130 | | - This can be used to temporarily increase or decrease the |
131 | | - verbosity for specific operations. |
132 | | -
|
133 | | - Returns: |
134 | | - A string consisting of `-` followed by `v` repeated `verbosity_level` |
135 | | - times. Returns an empty string if verbosity_level is 0 or negative. |
136 | | -
|
137 | | - Examples: |
138 | | - verbosity_str(0) == "" |
139 | | - verbosity_str(1) == "-v" |
140 | | - verbosity_str(2) == "-vv" |
141 | | - verbosity_str(3) == "-vvv" |
142 | | - """ |
143 | | - level = cls._verbosity_level + delta |
144 | | - if level <= 0: |
145 | | - return "" |
146 | | - return "-" + "v" * level |
147 | | - |
148 | | - |
149 | | -# Located here to prevent circular imports |
150 | | -def list_possible_file_names(recipe_name: str) -> list[str]: |
151 | | - """Generate a list of possible AutoPkg recipe file names. |
152 | | -
|
153 | | - Given a recipe name, this function returns a list of possible file names |
154 | | - by appending common AutoPkg recipe file extensions. If the recipe name |
155 | | - already ends with a known extension, it returns a list containing only the |
156 | | - original recipe name. |
157 | | -
|
158 | | - Args: |
159 | | - recipe_name: The name of the AutoPkg recipe. |
160 | | -
|
161 | | - Returns: |
162 | | - A list of possible file names for the recipe. |
163 | | - """ |
164 | | - if recipe_name.endswith((".recipe", ".recipe.plist", ".recipe.yaml")): |
165 | | - return [recipe_name] |
166 | | - |
167 | | - return [ |
168 | | - recipe_name + ".recipe", |
169 | | - recipe_name + ".recipe.plist", |
170 | | - recipe_name + ".recipe.yaml", |
171 | | - ] |
| 18 | +__all__ = [ |
| 19 | + "settings", |
| 20 | +] |
0 commit comments