98 lines
3.1 KiB
Python
98 lines
3.1 KiB
Python
from typing import Optional, Dict
|
|
|
|
from PyTeX.build.build import BuildDirConfig
|
|
from PyTeX.format.formatting_config import FormattingConfig
|
|
from .constants import *
|
|
from ...format.config import Config
|
|
|
|
|
|
class PyTeXConfig(Config):
|
|
def __init__(
|
|
self,
|
|
build_dir_spec: Optional[BuildDirConfig] = None
|
|
):
|
|
self._build_dir_specification: Optional[BuildDirConfig] = build_dir_spec
|
|
|
|
self._default_formatting_config: Optional[FormattingConfig] = None
|
|
|
|
self._recursive: Optional[bool] = None
|
|
self._overwrite_existing_files: Optional[bool] = None
|
|
self._clean_old_files: Optional[bool] = None
|
|
self._allow_dirty: Optional[bool] = None
|
|
|
|
self._force_mode: Optional[bool] = None
|
|
|
|
self._configs: Optional[Dict] = None
|
|
|
|
def to_json(self) -> Dict:
|
|
return {
|
|
YAML_BUILD_ROOT: {
|
|
YAML_RECURSIVE: self._recursive,
|
|
YAML_OVERWRITE_FILES: self._overwrite_existing_files,
|
|
YAML_CLEAN_OLD_FILES: self._clean_old_files,
|
|
YAML_ALLOW_DIRTY_BUILD: self._allow_dirty,
|
|
YAML_FORCE_MODE: self._force_mode,
|
|
YAML_DIRS: self.build_dir_specification.to_json()
|
|
},
|
|
YAML_DEFAULT: self.default_formatting_config.to_json(),
|
|
YAML_CONFIGS: self._configs
|
|
}
|
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
|
filled_content = self._fill_keys(content)
|
|
|
|
build = filled_content[YAML_BUILD]
|
|
self._build_dir_specification = BuildDirConfig.from_json(build[YAML_DIRS])
|
|
self._recursive = build[YAML_RECURSIVE]
|
|
self._clean_old_files = build[YAML_CLEAN_OLD_FILES]
|
|
self._overwrite_existing_files = build[YAML_OVERWRITE_FILES]
|
|
self._allow_dirty = build[YAML_ALLOW_DIRTY_BUILD]
|
|
self._force_mode = build[YAML_FORCE_MODE]
|
|
|
|
self._default_formatting_config = FormattingConfig.from_json(
|
|
filled_content[YAML_DEFAULT]
|
|
)
|
|
|
|
self._configs = filled_content[YAML_CONFIGS]
|
|
|
|
@property
|
|
def build_dir_specification(self):
|
|
if self._build_dir_specification is None:
|
|
return BuildDirConfig()
|
|
else:
|
|
return self._build_dir_specification
|
|
|
|
@property
|
|
def recursive(self) -> bool:
|
|
if self._recursive is None:
|
|
return True
|
|
else:
|
|
return self._recursive
|
|
|
|
@property
|
|
def overwrite_existing_files(self) -> bool:
|
|
if self._overwrite_existing_files is None:
|
|
return False
|
|
else:
|
|
return self._overwrite_existing_files
|
|
|
|
@property
|
|
def clean_old_files(self) -> bool:
|
|
if self._clean_old_files is None:
|
|
return False
|
|
else:
|
|
return self._clean_old_files
|
|
|
|
@property
|
|
def allow_dirty(self) -> bool:
|
|
if self._allow_dirty is None:
|
|
return False
|
|
else:
|
|
return self._allow_dirty
|
|
|
|
@property
|
|
def default_formatting_config(self) -> FormattingConfig:
|
|
if self._default_formatting_config is None:
|
|
return FormattingConfig()
|
|
else:
|
|
return self._default_formatting_config
|