Spaces:
Sleeping
Sleeping
UPDATE
Browse files- analyticsHub/components/__init__.py +25 -2
- app.py +0 -1
analyticsHub/components/__init__.py
CHANGED
|
@@ -1,2 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import traceback
|
| 3 |
+
import contextlib
|
| 4 |
+
|
| 5 |
+
class REPLManager:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.__stdout = io.StringIO()
|
| 8 |
+
self.__stderr = io.StringIO()
|
| 9 |
+
def run(self, codeString):
|
| 10 |
+
with contextlib.redirect_stdout(self.__stdout), contextlib.redirect_stderr(self.__stderr):
|
| 11 |
+
try:
|
| 12 |
+
exec(codeString)
|
| 13 |
+
except Exception:
|
| 14 |
+
traceback.print_exc(file=self.__stderr)
|
| 15 |
+
output, error = self.__stdout.getvalue(), self.__stderr.getvalue()
|
| 16 |
+
self.__stdout.truncate(0)
|
| 17 |
+
self.__stdout.seek(0)
|
| 18 |
+
self.__stderr.truncate(0)
|
| 19 |
+
self.__stderr.seek(0)
|
| 20 |
+
if error == "":
|
| 21 |
+
return output
|
| 22 |
+
else:
|
| 23 |
+
return error
|
| 24 |
+
|
| 25 |
+
replManager = REPLManager()
|
app.py
CHANGED
|
@@ -40,7 +40,6 @@ app.include_router(utilities.router, prefix = "/utils", tags = ["Utilities"])
|
|
| 40 |
|
| 41 |
@app.on_event("startup")
|
| 42 |
async def startupEvent():
|
| 43 |
-
projectIds = [x["projectId"] for x in client.table("Projects").select("projectId").execute().data]
|
| 44 |
params = readYaml("params.yaml")
|
| 45 |
_ = replManager.run(params["redisFunctionCode"])
|
| 46 |
_ = replManager.run(params["jsonSerializer"])
|
|
|
|
| 40 |
|
| 41 |
@app.on_event("startup")
|
| 42 |
async def startupEvent():
|
|
|
|
| 43 |
params = readYaml("params.yaml")
|
| 44 |
_ = replManager.run(params["redisFunctionCode"])
|
| 45 |
_ = replManager.run(params["jsonSerializer"])
|