Skip to content

Commit

Permalink
today()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Oct 19, 2023
1 parent d797c8c commit a32b23d
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 559 deletions.
4 changes: 4 additions & 0 deletions pyxcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"""Universal Calibration Protocol for Python"""
import sys

from rich.traceback import install

install(show_locals=True, max_frames=3) # Install custom exception handler.

if sys.platform == "win32" and sys.version_info[:2] < (3, 11):
# patch the time module with the high resolution alternatives
try:
Expand Down
62 changes: 11 additions & 51 deletions pyxcp/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,30 @@
Parse (transport-layer specific) command line parameters
and create a XCP master instance.
"""
import argparse
import warnings

from pyxcp.config import application
from pyxcp.config import readConfiguration
from pyxcp.master import Master
from pyxcp.transport.can import registered_drivers
from pyxcp.transport.can import try_to_install_system_supplied_drivers

try_to_install_system_supplied_drivers()
warnings.simplefilter("always")

CAN_DRIVERS = registered_drivers()

class FakeParser:
def __getattr__(self, key):
if key == "add_argument":
warnings.warn("Argument parser extension is currently not supported.", DeprecationWarning)
return lambda *args, **kws: None

class ArgumentParser:
"""
Parameter
---------
callout: callable
Process user-supplied arguments.
"""

class ArgumentParser:
def __init__(self, callout=None, *args, **kws):
self.callout = callout
kws.update(formatter_class=argparse.RawDescriptionHelpFormatter, add_help=True)
self._parser = argparse.ArgumentParser(*args, **kws)
self._parser.add_argument(
"-c",
"--config-file",
type=argparse.FileType("r"),
dest="conf",
help="File to read (extended) parameters from.",
)
self._parser.add_argument(
"-l",
"--loglevel",
choices=["ERROR", "WARN", "INFO", "DEBUG"],
default="INFO",
)
self._parser.epilog = "To get specific help on transport layers\nuse <layer> -h, e.g. {} eth -h".format(self._parser.prog)
self._args = []

@property
def args(self):
return self._args
self._parser = FakeParser()
if callout is not None:
warnings.warn("callout argument is not supported anymore", DeprecationWarning)

def run(self, policy=None):
""""""
self._args = self.parser.parse_args()
args = self.args
if args.conf is None:
raise RuntimeError("Configuration file must be specified! (option: -c <file>)")
config = readConfiguration(args.conf)
from pprint import pprint

pprint(config)
# config["LOGLEVEL"] = args.loglevel
# if "TRANSPORT" not in config:
# raise AttributeError("TRANSPORT must be specified in config!")
# transport = config["TRANSPORT"].lower()
transport = application.transport.layer
master = Master(transport, config=application, policy=policy)
if self.callout:
self.callout(master, args)
return master

@property
Expand Down
Loading

0 comments on commit a32b23d

Please sign in to comment.