| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/usr/bin/env python3
- from dataclasses import dataclass, asdict
- from panoramisk import Message
- TRUEs = ('true', '1', 'y', 'yes')
- NONEs = (None,'none','')
- NO_AUTH_ROUTES = ('/ui','/openapi.json','/favicon.ico')
- SWAGGER_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.37.2/swagger-ui-bundle.js"
- SWAGGER_CSS_URL = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.37.2/swagger-ui.min.css"
- SWAGGER_TEMPLATE = '''
- <head>
- <link type="text/css" rel="stylesheet" href="{{ css_url }}">
- <title>{{ title }}</title>
- </head>
- <body>
- <div id="swagger-ui"></div>
- <script src="{{ js_url }}"></script>
- <script>
- const ui = SwaggerUIBundle({
- deepLinking: true,
- dom_id: "#swagger-ui",
- layout: "BaseLayout",
- presets: [
- SwaggerUIBundle.presets.apis,
- SwaggerUIBundle.SwaggerUIStandalonePreset
- ],
- showExtensions: true,
- showCommonExtensions: true,
- url: "/openapi.json"
- });
- </script>
- </body>'''
- def followMe2DevState(followMeState):
- if followMeState == 'DIRECT':
- return 'INUSE'
- if followMeState == 'EXTENSION':
- return 'NOT_INUSE'
- return 'INVALID'
- @dataclass
- class QueueMember:
- user: str
- name: str = ''
- location: str = ''
- membership: str = ''
- stateinterface: str = ''
- status: str = ''
- def fromMessage(self, _m: Message):
- for key in asdict(self).keys():
- if key in _m:
- setattr(self, key, _m[key])
- return self
- @dataclass
- class GlobalVars:
- FMDEVSTATE: str = ''
- QUEDEVSTATE: str = ''
- QUEUETOGGLE: str = ''
- QUEUEPAUSETOGGLE: str = ''
- INTERCOMCODE: str = ''
- CAMPONTOGGLE: str = ''
- DNDDEVSTATE: str = ''
- CFDEVSTATE: str = ''
- def d(self):
- return asdict(self)
- def jsonAPIReply(success, result):
- return {'success':success, 'result': result}
- def noUser(user):
- return jsonAPIReply(False, 'user {} does not exist'.format(user))
- def noDevice(device):
- return jsonAPIReply(False, 'device {} does not exist'.format(device))
- def beenBound(user, device):
- return jsonAPIReply(True, '{} is bound to {}'.format(user, device))
- def bindError(user, device):
- return jsonAPIReply(False, 'Failed binding {} to {}'.format(user, device))
- def hintError(user, device):
- return jsonAPIReply(False, 'Failed setting hint for {}@{}'.format(user, device))
- def noUserBound(device):
- return jsonAPIReply(False, 'no user is bound to {}'.format(device))
- def beenUnbound(user, device):
- return jsonAPIReply(True, '{} unbound from {}'.format(user, device))
|