Skip to content

Commit

Permalink
fix yaml issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Apr 1, 2024
1 parent e08e4d3 commit 54e364b
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions app/yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@
import os
from file_data import FileData
import yaml
from types import SimpleNamespace
from yamlpath.common import Parsers
from yamlpath.wrappers import ConsolePrinter
from yamlpath import Processor
from yamlpath import YAMLPath
from yamlpath.exceptions import YAMLPathException
# from types import SimpleNamespace
# from yamlpath.common import Parsers
# from yamlpath.wrappers import ConsolePrinter
# from yamlpath import Processor
# from yamlpath import YAMLPath
# from yamlpath.exceptions import YAMLPathException

class YamlParser:
def __init__(self):
self.file_cache = {}
self.pwd = os.path.dirname(os.path.realpath(__file__))

logging_args = SimpleNamespace(quiet=True, verbose=False, debug=False)
log = ConsolePrinter(logging_args)
parser = Parsers.get_yaml_editor()

# At this point, you'd load or parse your YAML file, stream, or string. This
# example demonstrates loading YAML data from an external file. You could also
# use the same function to load data from STDIN or even a String variable. See
# the Parser class for more detail.
self.layout = os.path.join(self.pwd, "configs/layout.yml")
print(self.layout)
(yaml_data, doc_loaded) = Parsers.get_yaml_data(parser, log, self.layout)
if not doc_loaded:
# There was an issue loading the file; an error message has already been
# printed via ConsolePrinter.
exit(1)

# Pass the logging facility and parsed YAML data to the YAMLPath Processor
self.processor = Processor(log, yaml_data)

def find_widget(self, widget_name):
yaml_path = YAMLPath(f"/tabs/*/widgets[name = '{widget_name}']")

try:
for node in self.processor.get_nodes(yaml_path, return_coordinates=True, return_node=True, mustexist=True):
return node.node
except YAMLPathException as ex:
print(ex)
# logging_args = SimpleNamespace(quiet=True, verbose=False, debug=False)
# log = ConsolePrinter(logging_args)
# parser = Parsers.get_yaml_editor()

# # At this point, you'd load or parse your YAML file, stream, or string. This
# # example demonstrates loading YAML data from an external file. You could also
# # use the same function to load data from STDIN or even a String variable. See
# # the Parser class for more detail.
# self.layout = os.path.join(self.pwd, "configs/layout.yml")
# print(self.layout)
# (yaml_data, doc_loaded) = Parsers.get_yaml_data(parser, log, self.layout)
# if not doc_loaded:
# # There was an issue loading the file; an error message has already been
# # printed via ConsolePrinter.
# exit(1)

# # Pass the logging facility and parsed YAML data to the YAMLPath Processor
# self.processor = Processor(log, yaml_data)

# def find_widget(self, widget_name):
# yaml_path = YAMLPath(f"/tabs/*/widgets[name = '{widget_name}']")

# try:
# for node in self.processor.get_nodes(yaml_path, return_coordinates=True, return_node=True, mustexist=True):
# return node.node
# except YAMLPathException as ex:
# print(ex)

return None
# return None


def load_layout(self):
Expand Down

0 comments on commit 54e364b

Please sign in to comment.