""" PlanarAlly backend server code. This is the code responsible for starting the backend and reacting to socket IO events. """ import save save.check_save() import asyncio import sys from aiohttp import web import routes from api import * from app import app, logger, sio, state from config import config # This is a fix for asyncio problems on windows that make it impossible to do ctrl+c if sys.platform.startswith("win"): def _wakeup(): asyncio.get_event_loop().call_later(0.1, _wakeup) asyncio.get_event_loop().call_later(0.1, _wakeup) async def on_shutdown(_): for sid in list(state.sid_map.keys()): await sio.disconnect(sid, namespace="/planarally")
import aiohttp_security import aiohttp_session import jinja2 from aiohttp import web from aiohttp_security import remember, forget, authorized_userid, login_required, SessionIdentityPolicy from aiohttp_session.cookie_storage import EncryptedCookieStorage import auth import save from planarally import PlanarAlly FILE_DIR = os.path.dirname(os.path.realpath(__file__)) os.chdir(FILE_DIR) SAVE_FILE = "planar.save" save.check_save(SAVE_FILE) PA = PlanarAlly(SAVE_FILE) sio = socketio.AsyncServer(async_mode='aiohttp', engineio_logger=False) app = web.Application() app["AuthzPolicy"] = auth.ShelveDictAuthorizationPolicy(SAVE_FILE) aiohttp_security.setup(app, SessionIdentityPolicy(), app['AuthzPolicy']) aiohttp_session.setup(app, EncryptedCookieStorage(app['AuthzPolicy'].secret_token)) aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates')) sio.attach(app) def nested_dict_update(d, u): for k, v in u.items():