From 563284ab6562f91dbb69f9ce1acd3f15404eab29 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kalvoda?= <jirikalvoda@kam.mff.cuni.cz>
Date: Fri, 19 Jul 2024 11:58:59 +0200
Subject: [PATCH] Create admin server (for data management)

---
 prog/admin_server.py  |  8 ++++++++
 prog/communication.py | 22 ++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100755 prog/admin_server.py

diff --git a/prog/admin_server.py b/prog/admin_server.py
new file mode 100755
index 0000000..7deb1bf
--- /dev/null
+++ b/prog/admin_server.py
@@ -0,0 +1,8 @@
+import communication
+import asyncio
+
+async def main():
+    s = await communication.StdInOutSocket().connect()
+    await communication.AdminServer(s, is_server=True)._server_.run()
+
+asyncio.run(main())
diff --git a/prog/communication.py b/prog/communication.py
index 5c3e609..0114861 100644
--- a/prog/communication.py
+++ b/prog/communication.py
@@ -350,14 +350,6 @@ class MainServer(FuncCaller):
         else:
             return '{}', source_timestamps
 
-    @server_exec()
-    async def remove_data(self, dt: datetime.datetime):
-        path = "data/realtime/"+dt_to_path(dt)
-        out = {}
-        for filename in os.listdir(path):
-            os.remove(path+'/'+filename)
-        os.rmdir(path)
-
     @server_exec()
     async def gtfs_get_file(self, dt: datetime.datetime, filename: str):
         assert all(i in "_./" or i.isalnum() for i in filename)
@@ -422,3 +414,17 @@ class MainServer(FuncCaller):
         else:
             return r
 
+
+class AdminServer(MainServer):
+    @server_exec()
+    async def remove_data(self, dt: datetime.datetime):
+        path = "data/realtime/"+dt_to_path(dt)
+        out = {}
+        if os.path.isdir(path):
+            for filename in os.listdir(path):
+                os.remove(path+'/'+filename)
+            os.rmdir(path)
+        if os.path.isfile(path+".json.zst"):
+            os.remove(path+".json.zst")
+        if os.path.isfile(path+".json.gzip")):
+            os.remove(path+".json.gzip")
-- 
GitLab