comparison libervia/cli/loops.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 0f8ea0768a3b
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
21 import logging as log 21 import logging as log
22 from libervia.backend.core.i18n import _ 22 from libervia.backend.core.i18n import _
23 from libervia.cli.constants import Const as C 23 from libervia.cli.constants import Const as C
24 from libervia.frontends.tools import aio 24 from libervia.frontends.tools import aio
25 25
26 log.basicConfig(level=log.WARNING, 26 log.basicConfig(level=log.WARNING, format="[%(name)s] %(message)s")
27 format='[%(name)s] %(message)s')
28 27
29 USER_INTER_MSG = _("User interruption: good bye") 28 USER_INTER_MSG = _("User interruption: good bye")
30 29
31 30
32 class QuitException(BaseException): 31 class QuitException(BaseException):
35 This is used to stop execution when host.quit() is called 34 This is used to stop execution when host.quit() is called
36 """ 35 """
37 36
38 37
39 def get_libervia_cli_loop(bridge_name): 38 def get_libervia_cli_loop(bridge_name):
40 if 'dbus' in bridge_name: 39 if "dbus" in bridge_name:
41 import signal 40 import signal
42 41
43 class LiberviaCLILoop: 42 class LiberviaCLILoop:
44 43
45 def __init__(self): 44 def __init__(self):
74 73
75 Print user interruption message, set exit code and stop reactor 74 Print user interruption message, set exit code and stop reactor
76 """ 75 """
77 print("\r" + USER_INTER_MSG) 76 print("\r" + USER_INTER_MSG)
78 self.quit(C.EXIT_USER_CANCELLED) 77 self.quit(C.EXIT_USER_CANCELLED)
78
79 else: 79 else:
80 import signal 80 import signal
81 from twisted.internet import asyncioreactor 81 from twisted.internet import asyncioreactor
82
82 asyncioreactor.install() 83 asyncioreactor.install()
83 from twisted.internet import reactor, defer 84 from twisted.internet import reactor, defer
84 85
85 class LiberviaCLILoop: 86 class LiberviaCLILoop:
86 87
103 fut = asyncio.ensure_future(libervia_cli.main(*args)) 104 fut = asyncio.ensure_future(libervia_cli.main(*args))
104 try: 105 try:
105 await defer.Deferred.fromFuture(fut) 106 await defer.Deferred.fromFuture(fut)
106 except BaseException: 107 except BaseException:
107 import traceback 108 import traceback
109
108 traceback.print_exc() 110 traceback.print_exc()
109 libervia_cli.quit(1) 111 libervia_cli.quit(1)
110 112
111 def quit(self, exit_code): 113 def quit(self, exit_code):
112 self._exit_code = exit_code 114 self._exit_code = exit_code
134 """ 136 """
135 print("\r" + USER_INTER_MSG) 137 print("\r" + USER_INTER_MSG)
136 self._exit_code = C.EXIT_USER_CANCELLED 138 self._exit_code = C.EXIT_USER_CANCELLED
137 reactor.callFromThread(reactor.stop) 139 reactor.callFromThread(reactor.stop)
138 140
139
140 if bridge_name == "embedded": 141 if bridge_name == "embedded":
141 raise NotImplementedError 142 raise NotImplementedError
142 # from sat.core import sat_main 143 # from sat.core import sat_main
143 # sat = sat_main.SAT() 144 # sat = sat_main.SAT()
144 145