mirror of
https://github.com/markqvist/rnsh.git
synced 2025-01-22 04:01:00 -05:00
Performance tweaks
This commit is contained in:
parent
2e61b70996
commit
7d711cde6d
@ -192,6 +192,9 @@ class TTYRestorer(contextlib.AbstractContextManager):
|
||||
"""
|
||||
Set raw mode on tty
|
||||
"""
|
||||
if not self._fd:
|
||||
return
|
||||
|
||||
tty.setraw(self._fd, termios.TCSADRAIN)
|
||||
|
||||
def current_attr(self) -> [any]:
|
||||
@ -199,13 +202,21 @@ class TTYRestorer(contextlib.AbstractContextManager):
|
||||
Get the current termios attributes for the wrapped fd.
|
||||
:return: attribute array
|
||||
"""
|
||||
return termios.tcgetattr(self._fd).copy()
|
||||
if not self._fd:
|
||||
return None
|
||||
|
||||
return termios.tcgetattr(self._fd)
|
||||
|
||||
def set_attr(self, attr: [any], when: int = termios.TCSANOW):
|
||||
"""
|
||||
Set termios attributes
|
||||
:param attr: attribute list to set
|
||||
:param when: when attributes should be applied (termios.TCSANOW, termios.TCSADRAIN, termios.TCSAFLUSH)
|
||||
"""
|
||||
if not attr or not self._fd:
|
||||
return
|
||||
|
||||
with contextlib.suppress(termios.error):
|
||||
termios.tcsetattr(self._fd, when, attr)
|
||||
|
||||
def restore(self):
|
||||
@ -216,7 +227,6 @@ class TTYRestorer(contextlib.AbstractContextManager):
|
||||
|
||||
def __exit__(self, __exc_type: typing.Type[BaseException], __exc_value: BaseException,
|
||||
__traceback: types.TracebackType) -> bool:
|
||||
with contextlib.suppress(termios.error):
|
||||
self.restore()
|
||||
return __exc_type is not None and issubclass(__exc_type, termios.error)
|
||||
|
||||
|
@ -115,7 +115,8 @@ async def _listen(configdir, command, identitypath=None, service_name="default",
|
||||
log = _get_logger("_listen")
|
||||
_cmd = command
|
||||
|
||||
targetloglevel = 3 + verbosity - quietness
|
||||
targetloglevel = RNS.LOG_INFO + verbosity - quietness
|
||||
rnslogging.RnsHandler.set_global_log_level(__logging.INFO)
|
||||
_reticulum = RNS.Reticulum(configdir=configdir, loglevel=targetloglevel)
|
||||
_prepare_identity(identitypath)
|
||||
_destination = RNS.Destination(_identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, service_name)
|
||||
@ -636,7 +637,8 @@ async def _execute(configdir, identitypath=None, verbosity=0, quietness=0, noid=
|
||||
raise RemoteExecutionError("Invalid destination entered. Check your input.")
|
||||
|
||||
if _reticulum is None:
|
||||
targetloglevel = 2 + verbosity - quietness
|
||||
targetloglevel = RNS.LOG_ERROR + verbosity - quietness
|
||||
rnslogging.RnsHandler.set_global_log_level(__logging.ERROR)
|
||||
_reticulum = RNS.Reticulum(configdir=configdir, loglevel=targetloglevel)
|
||||
|
||||
if _identity is None:
|
||||
|
@ -60,6 +60,11 @@ class RnsHandler(Handler):
|
||||
return RNS.LOG_DEBUG
|
||||
return RNS.LOG_DEBUG
|
||||
|
||||
@classmethod
|
||||
def set_global_log_level(cls, log_level: int):
|
||||
logging.getLogger().setLevel(log_level)
|
||||
RNS.loglevel = cls.get_rns_loglevel(log_level)
|
||||
|
||||
def emit(self, record):
|
||||
"""
|
||||
Emit a record.
|
||||
@ -110,6 +115,7 @@ def _rns_log(msg, level=3, _override_destination=False):
|
||||
try:
|
||||
with process.TTYRestorer(sys.stdin.fileno()) as tr:
|
||||
attr = tr.current_attr()
|
||||
if attr:
|
||||
attr[process.TTYRestorer.ATTR_IDX_OFLAG] = attr[process.TTYRestorer.ATTR_IDX_OFLAG] | \
|
||||
termios.ONLRET | termios.ONLCR | termios.OPOST
|
||||
tr.set_attr(attr)
|
||||
@ -118,7 +124,7 @@ def _rns_log(msg, level=3, _override_destination=False):
|
||||
_rns_log_orig(msg, level, _override_destination)
|
||||
|
||||
try:
|
||||
if _loop:
|
||||
if _loop and _loop.is_running():
|
||||
_loop.call_soon_threadsafe(_rns_log_inner)
|
||||
else:
|
||||
_rns_log_inner()
|
||||
|
Loading…
Reference in New Issue
Block a user