diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 4c902d9..d189120 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.0.1 +current_version = 0.1.0 commit = True tag = True diff --git a/requirements_dev.txt b/requirements_dev.txt index b28ee75..0a98eec 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,3 +2,4 @@ grpcio-tools~=1.43.0 mypy-protobuf~=3.2.0 types-protobuf~=3.19.6 grpc-stubs~=1.24.7 +bump2version diff --git a/setup.py b/setup.py index 1da1300..e2b9ac9 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open('README.rst') as f: setuptools.setup( name='TSGRain Controller', - version='0.0.1', + version='0.1.0', author='ThetaDev', description='TSGRain irrigation controller', long_description=README, diff --git a/tests/test_application.py b/tests/test_application.py index 7899580..ba3947d 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -34,7 +34,7 @@ def app(mocker): return_value=fixtures.TestingIo()) with tempfile.TemporaryDirectory() as td: - app = application.Application(io_factory.IoType.VOID, td, + app = application.Application(io_factory.IoType.NONE, td, fixtures.FILE_CFG) assert not app.is_running() diff --git a/tests/test_grpc_server.py b/tests/test_grpc_server.py index 5774a48..1181009 100644 --- a/tests/test_grpc_server.py +++ b/tests/test_grpc_server.py @@ -37,7 +37,7 @@ def app(mocker): return_value=fixtures.TestingIo()) with tempfile.TemporaryDirectory() as td: - app = application.Application(io_factory.IoType.VOID, td, + app = application.Application(io_factory.IoType.NONE, td, fixtures.FILE_CFG) assert not app.is_running() app.start() diff --git a/tsgrain_controller/__init__.py b/tsgrain_controller/__init__.py index b8023d8..b794fd4 100644 --- a/tsgrain_controller/__init__.py +++ b/tsgrain_controller/__init__.py @@ -1 +1 @@ -__version__ = '0.0.1' +__version__ = '0.1.0' diff --git a/tsgrain_controller/__main__.py b/tsgrain_controller/__main__.py index b1c8974..e06fe53 100644 --- a/tsgrain_controller/__main__.py +++ b/tsgrain_controller/__main__.py @@ -2,25 +2,46 @@ import signal import sys import os import traceback +import argparse +import pathlib from tsgrain_controller import __version__, application from tsgrain_controller.io import io_factory +def _get_io_types() -> str: + io_types = [t.name for t in io_factory.IoType] + return '|'.join(io_types) + + +def _parse_args(): + parser = argparse.ArgumentParser(description='TSGRain Controller') + parser.add_argument('-c, --config', + dest='cfg', + type=pathlib.Path, + help='Pfad der Konfigurationsdatei') + + parser.add_argument('--io', dest='io', help=f'IO-Typ: {_get_io_types()}') + return parser.parse_args() + + def run(): print(f'TSGRain Controller {__version__}\n') + args = _parse_args() io_type = io_factory.IoType.MCP23017 + if args.io: + try: + io_type = io_factory.IoType[args.io.upper()] + except KeyError: + print(f'IO-Typ {args.io} ungültig. Verwende {_get_io_types()}') + sys.exit(1) - if len(sys.argv) > 1: - arg1 = sys.argv[1] - if arg1.startswith('c'): - io_type = io_factory.IoType.CONSOLE + cfg_path = None + if args.cfg: + cfg_path = args.cfg.name - if arg1.startswith('v'): - io_type = io_factory.IoType.VOID - - app = application.Application(io_type) + app = application.Application(io_type, cfg_path=cfg_path) def _signal_handler(sig, frame): # pylint: disable=unused-argument app.stop() diff --git a/tsgrain_controller/application.py b/tsgrain_controller/application.py index 471284d..c30bc45 100644 --- a/tsgrain_controller/application.py +++ b/tsgrain_controller/application.py @@ -20,11 +20,14 @@ class Application(models.AppInterface): cfg_path = os.path.join(workdir, 'tsgrain.toml') self.logger = logging.getLogger() - self.logger.setLevel(logging.DEBUG) + self.logger.setLevel(logging.INFO) self.cfg = config.Config(cfg_path) self.cfg.load_file() + if self.cfg.log_debug: + self.logger.setLevel(logging.DEBUG) + if self.cfg.db_path: db_path = self.cfg.db_path else: diff --git a/tsgrain_controller/io/io_factory.py b/tsgrain_controller/io/io_factory.py index 726acf1..0309e0e 100644 --- a/tsgrain_controller/io/io_factory.py +++ b/tsgrain_controller/io/io_factory.py @@ -4,7 +4,7 @@ from tsgrain_controller import models, io class IoType(Enum): - VOID = 0 + NONE = 0 CONSOLE = 1 MCP23017 = 2