Commit 0deb75de authored by Fabrice Salvaire's avatar Fabrice Salvaire

implemented lazy loading for config

parent cdcf451e
......@@ -24,6 +24,7 @@
####################################################################################################
__all__ = [
'Config',
'Parameter',
'Parameters',
'Letters',
......@@ -244,3 +245,54 @@ class ModalGroups(YamlMixin):
def __getitem__(self, index):
return self._groups[index_]
####################################################################################################
class Config:
##############################################
def __init__(self,
execution_order,
gcodes,
letters,
modal_groups,
parameters,
):
self._execution_order = str(execution_order)
self._gcodes = str(gcodes)
self._letters = str(letters)
self._modal_groups = str(modal_groups)
self._parameters = str(parameters)
##############################################
@property
def execution_order(self):
if isinstance(self._execution_order, str):
self._execution_order = ExecutionOrder(self._execution_order)
return self._execution_order
@property
def gcodes(self):
if isinstance(self._gcodes, str):
self._gcodes = Gcodes(self._gcodes)
return self._gcodes
@property
def letters(self):
if isinstance(self._letters, str):
self._letters = Letters(self._letters)
return self._letters
@property
def modal_groups(self):
if isinstance(self._modal_groups, str):
self._modal_groups = ModalGroups(self._modal_groups)
return self._modal_groups
@property
def parameters(self):
if isinstance(self._parameters, str):
self._parameters = Parameters(self._parameters)
return self._parameters
......@@ -390,23 +390,17 @@ are executed in a particular order if they occur on the same line.
####################################################################################################
from pathlib import Path
from pathlib import Path as _Path
from .Config import Config as _Config
from .Parser import GcodeParser, GcodeParserError
from .Config import (
Parameters,
Letters,
Gcodes,
ModalGroups,
ExecutionOrder,
)
_data_path = Path(__file__).parent.joinpath('data')
_data_path = _Path(__file__).parent.joinpath('data')
# Fixme: lazy
parameters = Parameters(_data_path.joinpath('rs274-default-parameter-file.yaml'))
execution_order = ExecutionOrder(_data_path.joinpath('rs274-execution-order.yaml'))
gcodes = Gcodes(_data_path.joinpath('rs274-gcodes.yaml'))
modal_groups = ModalGroups(_data_path.joinpath('rs274-modal-groups.yaml'))
letters = Letters(_data_path.joinpath('rs274-word-starting-letter.yaml'))
config = _Config(
execution_order=_data_path.joinpath('rs274-execution-order.yaml'),
gcodes=_data_path.joinpath('rs274-gcodes.yaml'),
letters=_data_path.joinpath('rs274-word-starting-letter.yaml'),
modal_groups=_data_path.joinpath('rs274-modal-groups.yaml'),
parameters=_data_path.joinpath('rs274-default-parameter-file.yaml'),
)
......@@ -30,7 +30,7 @@
from pathlib import Path
from PythonicGcodeMachine.Gcode.Rs274 import GcodeParser, gcodes, letters
from PythonicGcodeMachine.Gcode.Rs274 import GcodeParser, config
####################################################################################################
......@@ -53,10 +53,10 @@ for line in program:
print(str(line))
for word in line.iter_on_word():
if word.letter in 'GM':
meaning = gcodes[str(word)].meaning
meaning = config.gcodes[str(word)].meaning
print(meaning_format.format(str(word), meaning))
else:
letter = word.letter
meaning = letters[letter].meaning
meaning = config.letters[letter].meaning
print(meaning_format.format(letter, meaning))
#o#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment