Add the command that registers to the SMO; Make the create registration and create...
[pti/o2.git] / o2common / domain / base.py
1 # Copyright (C) 2021 Wind River Systems, Inc.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 from datetime import datetime\r
16 from typing import List\r
17 from sqlalchemy.inspection import inspect\r
18 from sqlalchemy.exc import NoInspectionAvailable\r
19 # from sqlalchemy.orm.exc import DetachedInstanceError\r
20 from .events import Event\r
21 \r
22 \r
23 class AgRoot:\r
24 \r
25     events = []\r
26 \r
27     def __init__(self) -> None:\r
28         self.hash = ""\r
29         self.updatetime = datetime.now()\r
30         self.createtime = datetime.now()\r
31         self.events = []  # type: List[Event]\r
32         # self.id = ""\r
33 \r
34     # def append_event(self, event: Event):\r
35     #     self.events = self.events.append(event)\r
36 \r
37 \r
38 class Serializer(object):\r
39 \r
40     def serialize(self):\r
41         try:\r
42             # d = {c: getattr(self, c) for c in inspect(self).attrs.keys()}\r
43             # if 'createtime' in d:\r
44             #     d['createtime'] = d['createtime'].isoformat()\r
45             # if 'updatetime' in d:\r
46             #     d['updatetime'] = d['updatetime'].isoformat()\r
47             # return d\r
48             return {c: getattr(self, c) for c in inspect(self).attrs.keys()}\r
49         except NoInspectionAvailable:\r
50             return self.__dict__\r
51 \r
52     @staticmethod\r
53     def serialize_list(li):\r
54         return [m.serialize() for m in li]\r