Initialized logging

This commit is contained in:
2019-11-05 19:56:00 +01:00
parent b12204360e
commit 0d2adf1b6c
10 changed files with 448 additions and 249 deletions
+24 -11
View File
@@ -1,5 +1,8 @@
import hashlib
from enum import Enum
import logging
log = logging.getLogger(__name__)
class ConceptParts(Enum):
@@ -15,11 +18,9 @@ class Concept:
A concept is a the base object of our universe
Everything is a concept
"""
props_to_serialize = ("id", "name", "where", "pre", "post", "body", "desc")
props_to_serialize = ("id", "is_builtin", "name", "where", "pre", "post", "body", "desc")
key_name = "concepts"
def __init__(self, name=None, is_builtin=False, where=None, pre=None, post=None, body=None, desc=None):
def __init__(self, name=None, is_builtin=False, where=None, pre=None, post=None, body=None, desc=None, key=None):
self.name = name
self.is_builtin = is_builtin
self.where = where # condition to recognize variables in name
@@ -27,16 +28,16 @@ class Concept:
self.post = post # list of post conditions after calling the main function
self.body = body # main method, can also be the value of the concept
self.desc = desc
self.key = None
self.parent = None
self.id = None
self.key = key
self.props = [] # list of Property for this concept
self.functions = {} # list of helper functions
self.codes = {}
self.codes = {} # cached ast for the where, pre, post and body parts
def __repr__(self):
return f"({self.key}){self.name}"
return f"({self.id}){self.name}"
def __eq__(self, other):
if not isinstance(other, Concept):
@@ -50,6 +51,9 @@ class Concept:
def __hash__(self):
return hash(self.name)
def get_key(self):
return self.key
def add_codes(self, codes):
"""
From a dict of <ConceptParts, AST>
@@ -73,13 +77,22 @@ class Concept:
def to_dict(self):
props_as_dict = dict((prop, getattr(self, prop)) for prop in self.props_to_serialize)
props_as_dict["props"] = [(p.name, p.value) for p in self.props]
return props_as_dict
def from_dict(self, as_dict):
for prop in self.props_to_serialize:
setattr(self, prop, as_dict[prop])
if prop in as_dict:
setattr(self, prop, as_dict[prop])
if "props" in as_dict:
for n, v in as_dict["props"]:
self.props.append(Property(n, v))
return self
def update_from(self, other):
for prop in self.props_to_serialize:
setattr(self, prop, getattr(other, prop))
class ErrorConcept(Concept):
def __init__(self, where=None, pre=None, post=None, body=None, desc=None):
@@ -94,6 +107,6 @@ class Property:
Defines a behaviour of Concept
"""
def __init__(self, concept, value):
self.concept = concept
def __init__(self, name, value):
self.name = name
self.value = value