mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 17:49:17 +00:00
migrate from PyYAML to ruamel.yaml
This commit is contained in:
@@ -11,7 +11,7 @@ import string
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
|
||||
import yaml
|
||||
from ruamel.yaml import YAML as yaml
|
||||
|
||||
from dotdrop.options import Options
|
||||
from dotdrop.linktypes import LinkTypes
|
||||
@@ -221,9 +221,8 @@ def create_yaml_keyval(pairs, parent_dir=None, top_key=None):
|
||||
if not parent_dir:
|
||||
parent_dir = get_tempdir()
|
||||
|
||||
fd, file_name = tempfile.mkstemp(dir=parent_dir, suffix='.yaml', text=True)
|
||||
with os.fdopen(fd, 'w') as f:
|
||||
yaml.safe_dump(pairs, f)
|
||||
_, file_name = tempfile.mkstemp(dir=parent_dir, suffix='.yaml', text=True)
|
||||
yaml_dump(pairs, file_name)
|
||||
return file_name
|
||||
|
||||
|
||||
@@ -234,8 +233,7 @@ def populate_fake_config(config, dotfiles={}, profiles={}, actions={},
|
||||
is_path = isinstance(config, str)
|
||||
if is_path:
|
||||
config_path = config
|
||||
with open(config_path) as config_file:
|
||||
config = yaml.safe_load(config_file)
|
||||
config = yaml_load(config_path)
|
||||
|
||||
config['dotfiles'] = dotfiles
|
||||
config['profiles'] = profiles
|
||||
@@ -246,9 +244,7 @@ def populate_fake_config(config, dotfiles={}, profiles={}, actions={},
|
||||
config['dynvariables'] = dynvariables
|
||||
|
||||
if is_path:
|
||||
with open(config_path, 'w') as config_file:
|
||||
yaml.safe_dump(config, config_file, default_flow_style=False,
|
||||
indent=2)
|
||||
yaml_dump(config, config_path)
|
||||
|
||||
|
||||
def file_in_yaml(yaml_file, path, link=False):
|
||||
@@ -256,8 +252,7 @@ def file_in_yaml(yaml_file, path, link=False):
|
||||
strip = get_path_strip_version(path)
|
||||
|
||||
if isinstance(yaml_file, str):
|
||||
with open(yaml_file) as f:
|
||||
yaml_conf = yaml.safe_load(f)
|
||||
yaml_conf = yaml_load(yaml_file)
|
||||
else:
|
||||
yaml_conf = yaml_file
|
||||
|
||||
@@ -275,3 +270,18 @@ def file_in_yaml(yaml_file, path, link=False):
|
||||
return False
|
||||
return in_src and in_dst and has_link
|
||||
return in_src and in_dst
|
||||
|
||||
|
||||
def yaml_load(path):
|
||||
with open(path, 'r') as f:
|
||||
content = yaml(typ='safe').load(f)
|
||||
return content
|
||||
|
||||
|
||||
def yaml_dump(content, path):
|
||||
with open(path, 'w') as f:
|
||||
y = yaml()
|
||||
y.default_flow_style = False
|
||||
y.indent = 2
|
||||
y.typ = 'safe'
|
||||
y.dump(content, f)
|
||||
|
||||
Reference in New Issue
Block a user