Example #1
0
 def delete_node(self, node: dict) -> None:
     del_node = self.query.filter(
         self.__class__.id == node.get("id")).first()
     if del_node is not None:
         db.session.delete(del_node)
         db.session.commit()
         mainLogger.info("Delete the node: {0} successful".format(del_node))
     else:
         mainLogger.warn(
             "this node {0} is not existing, so couldn't delete it".format(
                 node))
Example #2
0
 def update_node(self, node: dict) -> None:
     upd_node = self.query.filter(
         self.__class__.id == node.get("id")).first()
     for key, value in node.items():
         if hasattr(upd_node, key):
             setattr(upd_node, key, value)
         else:
             mainLogger.warn(
                 "During the update, the {0}={1} is not for Node".format(
                     key, value))
     db.session.update(upd_node)
     db.session.commit()
     mainLogger.info("Updated the node: {0}".format(upd_node))
Example #3
0
 def update_domain(self, domain: dict) -> None:
     my_domain = self.query.get(1)
     if isinstance(domain, dict):
         for key, value in domain.items():
             if hasattr(my_domain, key):
                 setattr(my_domain, key, value)
             else:
                 mainLogger.warn("the {0}={1} is not for Domain".format(
                     key, value))
     elif isinstance(domain, self.__class__):
         my_domain = domain
         # only one record
         my_domain.id = 1
     db.session.commit()
Example #4
0
 def insert_node(self, node: dict) -> None:
     if isinstance(node, dict):
         new_node = Node()
         for key, value in node.items():
             if hasattr(new_node, key):
                 setattr(new_node, key, value)
             else:
                 mainLogger.warn(
                     "During the insert, the {0}={1} is not for Node".
                     format(key, value))
     elif isinstance(node, self.__class__):
         new_node = node
     else:
         mainLogger.error("the node {0} is not supported".format(node))
     db.session.add(new_node)
     db.session.commit()
Example #5
0
 def insert_domain(self, domain) -> None:
     """
     新加入一条Domain
     :param domain: dict或者Domain的实例
     :return:
     """
     if isinstance(domain, dict):
         my_domain = self.__class__()
         for key, value in domain.items():
             if hasattr(my_domain, key):
                 setattr(my_domain, key, value)
             else:
                 mainLogger.warn("the {0}={1} is not for Domain".format(
                     key, value))
     elif isinstance(domain, self.__class__):
         my_domain = domain
     db.session.add(my_domain)
     db.session.commit()