Refactored sdp serializers
This commit is contained in:
@@ -13,6 +13,7 @@ class Concept:
|
||||
self.pre = None # list of pre conditions before calling the main function
|
||||
self.post = None # list of post conditions after calling the main function
|
||||
self.main = None # main method
|
||||
self.value = None # value of the concept
|
||||
self.id = Concept.concepts_id
|
||||
Concept.concepts_id = Concept.concepts_id + 1
|
||||
|
||||
|
||||
+11
-4
@@ -2,6 +2,7 @@ import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
from core.concept import Concept
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProvider
|
||||
|
||||
|
||||
class Singleton(type):
|
||||
@@ -52,6 +53,8 @@ class Sheerka(Concept, metaclass=Singleton):
|
||||
|
||||
self.create_builtin_concepts()
|
||||
|
||||
self.sdp = None
|
||||
|
||||
def create_builtin_concepts(self):
|
||||
"""
|
||||
Initializes the builtin concepts
|
||||
@@ -62,7 +65,7 @@ class Sheerka(Concept, metaclass=Singleton):
|
||||
self.concepts.append(Concept(Sheerka.SUCCESS_CONCEPT_NAME))
|
||||
self.concepts.append(Concept(Sheerka.ERROR_CONCEPT_NAME))
|
||||
|
||||
def initialize(self, root_folder):
|
||||
def initialize(self, root_folder=None):
|
||||
"""
|
||||
Starting Sheerka
|
||||
Loads the current configuration
|
||||
@@ -70,10 +73,9 @@ class Sheerka(Concept, metaclass=Singleton):
|
||||
:param root_folder: root configuration folder
|
||||
:return: ReturnValue(Success or Error)
|
||||
"""
|
||||
# create the folder configuration folder if needed
|
||||
|
||||
try:
|
||||
if not os.path.exists(root_folder):
|
||||
os.makedirs(root_folder)
|
||||
self.sdp = SheerkaDataProvider(root_folder)
|
||||
except IOError as e:
|
||||
return ReturnValue(False, self.get_concept(Sheerka.ERROR_CONCEPT_NAME, True), e)
|
||||
|
||||
@@ -101,3 +103,8 @@ class Sheerka(Concept, metaclass=Singleton):
|
||||
return False
|
||||
|
||||
return concept1.id == concept2.id
|
||||
|
||||
def record_event(self, event):
|
||||
self.sdp.save_event(event)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
def sysarg_to_string(argv):
|
||||
"""
|
||||
Transform a list of strings into a single string
|
||||
Add quotes if needed
|
||||
:return:
|
||||
"""
|
||||
if argv is None or not argv:
|
||||
return ""
|
||||
|
||||
result = ""
|
||||
first = True
|
||||
for s in argv:
|
||||
if not first:
|
||||
result += " "
|
||||
|
||||
result += '"' + s + '"' if " " in s else s
|
||||
first = False
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user