67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
class Anonymous:
|
|
|
|
def __init__(self, mem_web, key):
|
|
self.mem_web = mem_web
|
|
self.__key = key
|
|
|
|
self.__started = False
|
|
|
|
for key in ("settings", "i18n", "_print", "exception", "validate"):
|
|
hasattr(self, key) or setattr(self, key, getattr(mem_web, key))
|
|
|
|
def start(self, callback = None):
|
|
|
|
self._print("info", "mem_web_" + self.__key + "_starting")
|
|
|
|
end = lambda status:MemWeb.execute(callback, status)
|
|
|
|
if self.__started:
|
|
self._print("warn", "mem_web_" + self.__key + "_already_started")
|
|
end(False)
|
|
return False
|
|
|
|
if hasattr(self, "_start"):
|
|
MemWeb.execute(self._start, end)
|
|
self.__started = True
|
|
else:
|
|
self.__started = True
|
|
self._print("ok", "mem_web_" + self.__key + "_started")
|
|
end(True)
|
|
|
|
return True
|
|
|
|
def close(self, callback = None):
|
|
|
|
self._print("info", "mem_web_" + self.__key + "_closing")
|
|
|
|
end = lambda status:MemWeb.execute(callback, status)
|
|
|
|
if not self.__started:
|
|
self._print("warn", "mem_web_" + self.__key + "_already_closed")
|
|
end(False)
|
|
return False
|
|
|
|
if hasattr(self, "_close"):
|
|
MemWeb.execute(self._close, end)
|
|
self.__started = False
|
|
else:
|
|
self.__started = False
|
|
self._print("ok", "mem_web_" + self.__key + "_closed")
|
|
end(True)
|
|
|
|
return True
|
|
|
|
def is_started(self):
|
|
return self.__started
|
|
|
|
if "MemWeb" not in globals():
|
|
class MemWeb:pass
|
|
if not hasattr(MemWeb, "Abstracts"):
|
|
class SubAnonymous:pass
|
|
MemWeb.Abstracts = SubAnonymous
|
|
del globals()["SubAnonymous"]
|
|
MemWeb.Abstracts.Common = Anonymous
|
|
del globals()["Anonymous"] |