summaryrefslogtreecommitdiff
path: root/qvisqve/entity_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'qvisqve/entity_manager.py')
-rw-r--r--qvisqve/entity_manager.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/qvisqve/entity_manager.py b/qvisqve/entity_manager.py
new file mode 100644
index 0000000..da42f5b
--- /dev/null
+++ b/qvisqve/entity_manager.py
@@ -0,0 +1,50 @@
+# Copyright (C) 2018 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import os
+
+import yaml
+
+
+class EntityManager:
+
+ def __init__(self, rs, resource_type):
+ self._store = rs
+ self._type = resource_type
+
+ def list(self):
+ return self._store.list(self._type)
+
+ def get(self, entity_id):
+ return self._store.get(self._type, entity_id)
+
+ def create(self, entity_id, entity):
+ self._store.create(self._type, entity_id, entity)
+
+
+class ApplicationManager(EntityManager):
+
+ def __init__(self, rs):
+ super().__init__(rs, 'application')
+
+ def get_callbacks(self, app_id):
+ app = self.get(app_id)
+ return app.get('callbacks', [])
+
+ def add_callback(self, app_id, url):
+ app = self.get(app_id)
+ app['callbacks'] = app.get('callbacks', []) + [url]
+ self.create(app_id, app)