mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 00:16:12 +00:00
handle toml for #343
This commit is contained in:
@@ -26,6 +26,7 @@ import io
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from ruamel.yaml import YAML as yaml
|
from ruamel.yaml import YAML as yaml
|
||||||
|
import toml
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from dotdrop.version import __version__ as VERSION
|
from dotdrop.version import __version__ as VERSION
|
||||||
@@ -1210,6 +1211,17 @@ class CfgYaml:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _yaml_load(cls, path):
|
def _yaml_load(cls, path):
|
||||||
|
"""load config file"""
|
||||||
|
is_yaml = path.lower().endswith(".yaml")
|
||||||
|
if is_yaml:
|
||||||
|
return cls.__yaml_load(path)
|
||||||
|
is_toml = path.lower().endswith(".toml")
|
||||||
|
if is_toml:
|
||||||
|
return cls.__toml_load(path)
|
||||||
|
raise YamlException("unsupported format")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __yaml_load(cls, path):
|
||||||
"""load from yaml"""
|
"""load from yaml"""
|
||||||
with open(path, 'r', encoding='utf8') as file:
|
with open(path, 'r', encoding='utf8') as file:
|
||||||
data = yaml()
|
data = yaml()
|
||||||
@@ -1217,8 +1229,27 @@ class CfgYaml:
|
|||||||
content = data.load(file)
|
content = data.load(file)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __toml_load(cls, path):
|
||||||
|
"""load from toml"""
|
||||||
|
with open(path, 'r', encoding='utf8') as file:
|
||||||
|
data = file.read()
|
||||||
|
content = toml.loads(data)
|
||||||
|
return content
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _yaml_dump(cls, content, where):
|
def _yaml_dump(cls, content, where):
|
||||||
|
"""dump config file"""
|
||||||
|
is_yaml = where.lower().endswith(".yaml")
|
||||||
|
if is_yaml:
|
||||||
|
return cls.__yaml_dump(content, where)
|
||||||
|
is_toml = where.lower().endswith(".toml")
|
||||||
|
if is_toml:
|
||||||
|
return cls.__toml_dump(content, where)
|
||||||
|
raise YamlException("unsupported format")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __yaml_dump(cls, content, where):
|
||||||
"""dump to yaml"""
|
"""dump to yaml"""
|
||||||
data = yaml()
|
data = yaml()
|
||||||
data.default_flow_style = False
|
data.default_flow_style = False
|
||||||
@@ -1226,6 +1257,12 @@ class CfgYaml:
|
|||||||
data.typ = 'rt'
|
data.typ = 'rt'
|
||||||
data.dump(content, where)
|
data.dump(content, where)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __toml_dump(cls, content, where):
|
||||||
|
"""dump to toml"""
|
||||||
|
with open(where, 'w', encoding='utf8') as file:
|
||||||
|
toml.dump(content, file)
|
||||||
|
|
||||||
########################################################
|
########################################################
|
||||||
# templating
|
# templating
|
||||||
########################################################
|
########################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user