Fixed #18 : Parsing and evaluating Python
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from common.global_symbols import NotFound
|
||||
from common.utils import sheerka_deepcopy
|
||||
from core.Sheerka import Sheerka
|
||||
|
||||
|
||||
class BaseService:
|
||||
"""
|
||||
Base class for services
|
||||
"""
|
||||
|
||||
def __init__(self, sheerka: Sheerka, order=999):
|
||||
self.sheerka = sheerka
|
||||
self.order = order # initialisation order. The lowest is initialized first
|
||||
|
||||
def initialize(self):
|
||||
"""
|
||||
Adds cache or bind methods
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
def state_properties(self):
|
||||
pass
|
||||
|
||||
def push_state(self, context):
|
||||
"""
|
||||
Use variable Manager to store the state of the service
|
||||
"""
|
||||
args = self.state_properties()
|
||||
if args:
|
||||
for prop_name in args:
|
||||
self.sheerka.record_var(context, self.NAME, prop_name, sheerka_deepcopy(getattr(self, prop_name)))
|
||||
|
||||
def pop_state(self):
|
||||
"""
|
||||
Use Variable Manager to restore the state of a service
|
||||
:return:
|
||||
"""
|
||||
args = self.state_properties()
|
||||
if args:
|
||||
for prop_name in args:
|
||||
if (value := self.sheerka.load_var(self.NAME, prop_name)) is not NotFound:
|
||||
setattr(self, prop_name, value)
|
||||
|
||||
def store_var(self, context, var_name):
|
||||
"""
|
||||
Store/record the value of an attribute
|
||||
"""
|
||||
self.sheerka.record_var(context, self.NAME, var_name, getattr(self, var_name))
|
||||
Reference in New Issue
Block a user