mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-04 16:50:11 +02:00
bluepy_scratch_link: Add __main__.py
Add __main__.py to the bluepy-scratch-link package to invoke its feature using the package name. Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
This commit is contained in:
6
bluepy_scratch_link/__main__.py
Normal file
6
bluepy_scratch_link/__main__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from scratch_link import main as _main
|
||||
|
||||
if __name__ == '__main__':
|
||||
_main()
|
@@ -651,16 +651,6 @@ class BLESession(Session):
|
||||
self.delegate.restart_notification_event.set()
|
||||
return self.status == self.DONE
|
||||
|
||||
# Prepare certificate of the WSS server
|
||||
gencert.prep_cert()
|
||||
|
||||
# kick start WSS server
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
localhost_cer = gencert.cert_file_path
|
||||
localhost_key = gencert.key_file_path
|
||||
ssl_context.load_cert_chain(localhost_cer, localhost_key)
|
||||
sessionTypes = { '/scratch/ble': BLESession, '/scratch/bt': BTSession }
|
||||
|
||||
async def ws_handler(websocket, path):
|
||||
try:
|
||||
logger.info(f"Start session for web socket path: {path}")
|
||||
@@ -671,10 +661,6 @@ async def ws_handler(websocket, path):
|
||||
logger.error(f"Failure in session for web socket path: {path}")
|
||||
logger.error(e)
|
||||
|
||||
start_server = websockets.serve(
|
||||
ws_handler, "device-manager.scratch.mit.edu", 20110, ssl=ssl_context
|
||||
)
|
||||
|
||||
def stack_trace():
|
||||
print("in stack_trace")
|
||||
code = []
|
||||
@@ -689,14 +675,29 @@ def stack_trace():
|
||||
for line in code:
|
||||
print(line)
|
||||
|
||||
while True:
|
||||
try:
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
logger.info("Started scratch-link")
|
||||
asyncio.get_event_loop().run_forever()
|
||||
except KeyboardInterrupt as e:
|
||||
stack_trace()
|
||||
break
|
||||
except Exception as e:
|
||||
logger.info("Restarting scratch-link...")
|
||||
def main():
|
||||
# Prepare certificate of the WSS server
|
||||
gencert.prep_cert()
|
||||
|
||||
# kick start WSS server
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
localhost_cer = gencert.cert_file_path
|
||||
localhost_key = gencert.key_file_path
|
||||
ssl_context.load_cert_chain(localhost_cer, localhost_key)
|
||||
sessionTypes = { '/scratch/ble': BLESession, '/scratch/bt': BTSession }
|
||||
|
||||
start_server = websockets.serve(
|
||||
ws_handler, "device-manager.scratch.mit.edu", 20110, ssl=ssl_context
|
||||
)
|
||||
|
||||
while True:
|
||||
try:
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
logger.info("Started scratch-link")
|
||||
asyncio.get_event_loop().run_forever()
|
||||
except KeyboardInterrupt as e:
|
||||
stack_trace()
|
||||
break
|
||||
except Exception as e:
|
||||
logger.info("Restarting scratch-link...")
|
||||
|
||||
|
Reference in New Issue
Block a user