Skip to content

Commit

Permalink
fixed gcode problem
Browse files Browse the repository at this point in the history
  • Loading branch information
aradermacher committed Mar 19, 2024
1 parent 136e9e2 commit 5fd3431
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 1 addition & 3 deletions amworkflow/gcode/gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ def load_standard(self, std: str = None):
:type std: str, optional
:raises ValueError:
"""
directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config")

directory = os.path.join(ROOT_PATH, "amworkflow/gcode/config")
print('check', directory)
config_list_no_ext = [
Expand All @@ -279,7 +277,7 @@ def load_standard(self, std: str = None):
self.standard = std
if self.standard not in config_list_no_ext:
raise ValueError(f"{self.standard} does not exist.")
config = printer_config.read_config(self.standard + ".yaml")
config = printer_config.read_config(directory+"/"+self.standard + ".yaml")
logging.info(f"Load config {self.standard}")
for state in printer_config.PrintState:
if state.name in config:
Expand Down
28 changes: 13 additions & 15 deletions amworkflow/gcode/printer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,36 @@ class CommentInfo(Enum):
ORIGINAL_POINT = "Original Point"


def create_new_config(config_name):
def create_new_config(path_config_file):
"""Create new config file
:param config_name: config file name
:param path_config_file: file path of config file
:type config_name: str
:raises FileExistsError: File already exists
"""
directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config")
print(directory)
file_path = os.path.join(directory, config_name)
if os.path.exists(file_path):
raise FileExistsError(f"{config_name} already exists.")

if os.path.exists(path_config_file):
raise FileExistsError(f"{path_config_file} already exists.")
enum_members_list = [state.name for state in PrintState]
# Write data to the YAML file
with open(file_path, "w", encoding="utf-8") as yaml_file:
with open(path_config_file, "w", encoding="utf-8") as yaml_file:
yaml.dump(enum_members_list, yaml_file, default_flow_style=False)


def read_config(config_name):
def read_config(path_config_file):
"""Read config file
:param config_name: config file name
:param path_config_file: file path of config file
:type config_name: str
:raises FileNotFoundError: File not found
:return: config data
:rtype: dict
"""
directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config")
file_path = os.path.join(directory, config_name)
if not os.path.exists(file_path):
raise FileNotFoundError(f"{config_name} does not exist.")
with open(file_path, "r", encoding="utf-8") as yaml_file:
# directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config")
# file_path = os.path.join(directory, config_name)
if not os.path.exists(path_config_file):
raise FileNotFoundError(f"{path_config_file} does not exist.")
with open(path_config_file, "r", encoding="utf-8") as yaml_file:
loaded_data = yaml.safe_load(yaml_file)
flattened_data = {k: v for d in loaded_data for k, v in d.items()}
return flattened_data

0 comments on commit 5fd3431

Please sign in to comment.