Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/python-cellframe-modules/pycfhelpers
1 result
Show changes
Commits on Source (6)
# User directories
*_tmp/*
interfaces/*
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
......
from typing import Callable, Protocol
import traceback
from CellFrame import AppCliServer
from DAP.Core import logIt
from optparse import OptionParser
from pycfhelpers.node.types import ReplyId
class ReplyObject:
def __init__(self, reply_id: ReplyId):
self.reply_id = reply_id
def reply(self, message: str):
AppCliServer.setReplyText(message, self.reply_id)
class CliCallback(Protocol):
def __call__(self, *args, reply_object: ReplyObject, **kwargs) -> None:
pass
class CFCliCommand:
def __init__(self, command: str, callback: CliCallback, help_text: str = ""):
"""
Use https://docs.python.org/3.10/library/optparse.html, for configuration cli command
"""
self.command = command
self.callback = callback
self.help_text = help_text
self.parser = OptionParser()
def register(self):
def callback_wrapper(argv: list[str], reply_id: ReplyId):
(options, args) = self.parser.parse_args(argv[1:])
self.callback(*args, reply_object=ReplyObject(reply_id), **options.__dict__)
help_text = self.help_text or self.parser.format_help()
try:
AppCliServer.cmdItemCreate(self.command, callback_wrapper, help_text, "")
except Exception:
logIt.error(f"Error = {traceback.format_exc()}")
from DAP.Core import logIt from DAP.Core import logIt
class CFLog: class CFLog:
def __init__(self):
self._logger = logIt
@staticmethod def debug(self, message: str):
def notice(message : str): self._logger.debug(message)
logIt.notice(message)
def info(self, message: str):
@staticmethod self._logger.info(message)
def warning(message : str):
logIt.warning(message)
def notice(self, message: str):
self._logger.notice(message)
@staticmethod def message(self, message: str):
def error(message : str): self._logger.message(message)
logIt.error(message)
def dap(self, message: str):
self._logger.dap(message)
def warning(self, message: str):
self._logger.warning(message)
def att(self, message: str):
self._logger.att(message)
def error(self, message: str):
self._logger.error(message)
def critical(self, message: str):
self._logger.critical(message)
from typing import Iterator, Callable from typing import Iterator, Callable, Self
from typing_extensions import Self
import traceback import traceback
......