implement i/o of pytex config
This commit is contained in:
parent
08c9ac19bc
commit
fd54e5221a
2 changed files with 47 additions and 2 deletions
|
@ -8,3 +8,7 @@ YAML_OVERWRITE_FILES = 'overwrite'
|
||||||
YAML_ALLOW_DIRTY_BUILD = 'dirty'
|
YAML_ALLOW_DIRTY_BUILD = 'dirty'
|
||||||
YAML_FORCE_MODE = 'force'
|
YAML_FORCE_MODE = 'force'
|
||||||
YAML_WRAPPER_DIR = 'wrapper'
|
YAML_WRAPPER_DIR = 'wrapper'
|
||||||
|
YAML_BUILD = 'build'
|
||||||
|
YAML_DEFAULT = 'default'
|
||||||
|
YAML_CONFIGS = 'configs'
|
||||||
|
YAML_DIRS = 'dirs'
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from typing import Optional
|
from typing import Optional, Dict
|
||||||
|
|
||||||
from PyTeX.build.build import BuildDirConfig
|
from PyTeX.build.build import BuildDirConfig
|
||||||
from PyTeX.format.formatting_config import FormattingConfig
|
from PyTeX.format.formatting_config import FormattingConfig
|
||||||
|
from ...format.config import Config
|
||||||
|
from .constants import *
|
||||||
|
|
||||||
|
|
||||||
class PyTeXConfig:
|
class PyTeXConfig(Config):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
build_dir_spec: Optional[BuildDirConfig] = None
|
build_dir_spec: Optional[BuildDirConfig] = None
|
||||||
|
@ -18,6 +20,45 @@ class PyTeXConfig:
|
||||||
self._clean_old_files: Optional[bool] = None
|
self._clean_old_files: Optional[bool] = None
|
||||||
self._allow_dirty: 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: Dict):
|
||||||
|
content = self._fill_keys(content)
|
||||||
|
|
||||||
|
build = 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(
|
||||||
|
content[YAML_DEFAULT]
|
||||||
|
)
|
||||||
|
|
||||||
|
self._configs = content[YAML_CONFIGS]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def build_dir_specification(self):
|
def build_dir_specification(self):
|
||||||
if self._build_dir_specification is None:
|
if self._build_dir_specification is None:
|
||||||
|
|
Loading…
Reference in a new issue