Skip to content
Snippets Groups Projects
Commit a7ccd1fa authored by Guido Sterbini's avatar Guido Sterbini
Browse files

Adding the py_to_yaml

parent 793561c7
No related branches found
No related tags found
2 merge requests!2Dev v0.0.1,!1Dev v0.0.1
Pipeline #2790146 passed
......@@ -7,6 +7,11 @@ NodeJob.py
.. autoclass:: tree_maker.NodeJob.NodeJob
:members:
general.py
------
.. automodule:: tree_maker.general
:members:
tag.py
------
.. automodule:: tree_maker.tag
......
......@@ -11,6 +11,7 @@ from .general import tree_from_yaml
from .general import tree_from_json
from .general import from_yaml
from .general import from_json
from .general import py_to_yaml
from .tag import *
from .tag_json import *
......
......@@ -10,14 +10,17 @@ import orjson
ryaml = ruamel.yaml.YAML()
def tree_from_yaml(filename='tree.yaml'):
'''Import the tree structure from the yaml formatted *filename*'''
with open(filename, "r") as file:
return DictImporter(nodecls=NodeJob).import_(yaml.load(file, Loader=yaml.FullLoader))
def tree_from_json(filename='tree.json'):
'''Import the tree structure from the json formatted *filename*'''
with open(filename, "r") as file:
return DictImporter(nodecls=NodeJob).import_(orjson.loads(file.read()))
def from_yaml(filename):
'''Load the *filename* yaml file'''
try:
with open(filename, 'r') as file:
return ryaml.load(file)
......@@ -26,9 +29,17 @@ def from_yaml(filename):
return {}
def from_json(filename, verbose=False):
'''Load the *filename* json file'''
try:
with open(filename, 'r') as file:
return orjson.loads(file.read())
except Exception as e:
if verbose: print(e)
return {}
def py_to_yaml(filename):
'''Convert the *filename*.py (containg dictionaries) to an
equivalent *filename*.yaml'''
import filename as my_dict
with open(filename+'.yaml', 'w') as fid:
yaml.dump(my_dict, fid)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment