config
Configuration module for the moduli generator project. Centralizes all default configuration values.
__all__
module-attribute
__all__ = [
"ModuliConfig",
"default_config",
"iso_utc_timestamp",
"iso_utc_time_notzinfo",
"strip_punction_from_datetime_str",
"DEFAULT_MARIADB_DB_NAME",
"DEFAULT_MARIADB_CNF",
"DEFAULT_KEY_LENGTHS",
"TEST_MARIADB_DB_NAME",
"__version__",
]
DEFAULT_MODULI_GENERATOR_HOME
module-attribute
DEFAULT_PRESERVE_MODULI_AFTER_DBSTORE
module-attribute
DEFAULT_DELETE_RECORDS_ON_MODULI_WRITE
module-attribute
CONST_CANDIDATE_IDX_FILENAME_PATTERN
module-attribute
DEFAULT_MODULI_FILE
module-attribute
ModuliConfig
Class representing the configuration for Moduli generation and management.
This class is used to define directories, file patterns, database configurations, logging, and other essential components required for handling Moduli operations.
Attributes:
| Name | Type | Description |
|---|---|---|
moduli_home |
PosixPath
|
Base directory for Moduli files, derived from a user-provided path, environment variable, or a default directory. |
candidates_dir |
PosixPath
|
Directory for storing candidate files. |
moduli_dir |
PosixPath
|
Directory for storing Moduli files. |
log_dir |
PosixPath
|
Directory for storing log files. |
log_file |
PosixPath
|
Full path to the default log file. |
key_lengths |
list
|
List of default key lengths for Moduli generation. |
generator_type |
str
|
Default generator type used during Moduli generation. |
nice_value |
int
|
Default "nice" value for adjusting process priority. |
db_name |
str
|
Name of the MariaDB database used for storing Moduli data. |
table_name |
str
|
Name of the MariaDB table used for Moduli storage. |
view_name |
str
|
Name of the MariaDB view for querying Moduli data. |
records_per_keylength |
int
|
Number of records generated or stored per key length. |
config_id |
int
|
Unique ID used to link constants in the Moduli file to the database table. |
mariadb_cnf |
PosixPath
|
Path to the MariaDB configuration file. |
moduli_file_pattern |
str
|
Default filename pattern for Moduli files. |
candidate_idx_pattern |
str
|
Default filename pattern for candidate index files. |
moduli_file_pfx |
str
|
Prefix for naming Moduli output files. |
moduli_file |
PosixPath
|
Path to the default Moduli file. |
preserve_moduli_after_dbstore |
bool
|
Flag indicating whether to preserve Moduli files after being stored in the database. |
delete_records_on_moduli_write |
bool
|
Flag indicating whether to delete database records after writing to Moduli files successfully. |
version |
str
|
The version of the Moduli project. |
Source code in config/__init__.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
ensure_directories
Ensures that a set of directories (base, candidates, moduli, and log directories) exist. If they do not exist, they will be created. This method ensures all necessary directories are ready for further operations.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
ModuliConfig
|
The current instance after ensuring directories exist. |
Source code in config/__init__.py
get_logger
Initializes and returns a logger instance configured for file-based logging.
This function ensures that the required directories and configuration files exist
before setting up the logging system. It verifies the existence of the base logging
directory, the default log directory, and the MariaDB configuration file. If they do not
exist, they are created as needed. Once these prerequisites are met, the logger is
configured with a specific logging level, format, and file output.
Returns:
| Type | Description |
|---|---|
Logger
|
Logging.Logger: Configured logger instance. |
Raises:
| Type | Description |
|---|---|
OSError
|
If there is an issue, create required directories or files. |
IOError
|
If there is an issue, read the default MariaDB configuration file. |
Source code in config/__init__.py
get_log_file
Retrieve the log file path, either by name or default log file path.
This method determines whether a specific log file name is provided. If a
name is given, the method constructs and returns the full path to the named
log file within the logging directory. If no name is provided, it returns the
path to the default log file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Name of the log file to retrieve. If None, the default log file path is returned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
PosixPath
|
The full path to the specified log file if a name is provided, or the default log file path otherwise. |
Source code in config/__init__.py
with_base_dir
staticmethod
Creates a new instance of ModuliConfig with the given base directory.
This static method provides a convenience to instantiate the ModuliConfig
class with a specified base directory. It ensures that the provided base
directory is explicitly set during the object creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
str
|
The base directory to be used for initialization. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ModuliConfig |
ModuliConfig
|
A new instance of the ModuliConfig class initialized with the given base directory. |
Source code in config/__init__.py
iso_utc_timestamp
Generates a UTC timestamp in ISO 8601 format. Optionally, the output can be compressed to remove non-numeric characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compress
|
bool
|
Specifies whether the timestamp should be compressed by removing non-numeric characters. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The generated UTC timestamp as a string. If |
Source code in config/__init__.py
iso_utc_time_notzinfo
Generates and returns the current time in UTC format, stripped of timezone information. This function uses the UTC timezone to fetch the current time but removes the timezone information from the resulting datetime object.
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
The current UTC time as a timezone-naive datetime object. |
Source code in config/__init__.py
strip_punction_from_datetime_str
Compresses a datetime object into a compact string format by removing non-numeric characters from its ISO 8601 format string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
Datetime
|
A datetime object to compress into a string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the given datetime with all non-numeric characters removed. |
Source code in config/__init__.py
default_config
Generates and ensures the default configuration directories and structure.
Returns:
| Name | Type | Description |
|---|---|---|
ModuliConfig |
ModuliConfig
|
An instance of ModuliConfig with directories ensured. |
Source code in config/__init__.py
options: members: true