Compare commits

..

3 commits

Author SHA1 Message Date
426d70672a Bump version: 0.0.1 → 0.1.0 2022-02-07 02:01:24 +01:00
87725686bc add bump2version requirement 2022-02-07 02:01:12 +01:00
40faac8a07 parse cmdline arguments 2022-02-07 01:59:48 +01:00
9 changed files with 40 additions and 15 deletions

View file

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.0.1 current_version = 0.1.0
commit = True commit = True
tag = True tag = True

View file

@ -2,3 +2,4 @@ grpcio-tools~=1.43.0
mypy-protobuf~=3.2.0 mypy-protobuf~=3.2.0
types-protobuf~=3.19.6 types-protobuf~=3.19.6
grpc-stubs~=1.24.7 grpc-stubs~=1.24.7
bump2version

View file

@ -6,7 +6,7 @@ with open('README.rst') as f:
setuptools.setup( setuptools.setup(
name='TSGRain Controller', name='TSGRain Controller',
version='0.0.1', version='0.1.0',
author='ThetaDev', author='ThetaDev',
description='TSGRain irrigation controller', description='TSGRain irrigation controller',
long_description=README, long_description=README,

View file

@ -34,7 +34,7 @@ def app(mocker):
return_value=fixtures.TestingIo()) return_value=fixtures.TestingIo())
with tempfile.TemporaryDirectory() as td: with tempfile.TemporaryDirectory() as td:
app = application.Application(io_factory.IoType.VOID, td, app = application.Application(io_factory.IoType.NONE, td,
fixtures.FILE_CFG) fixtures.FILE_CFG)
assert not app.is_running() assert not app.is_running()

View file

@ -37,7 +37,7 @@ def app(mocker):
return_value=fixtures.TestingIo()) return_value=fixtures.TestingIo())
with tempfile.TemporaryDirectory() as td: with tempfile.TemporaryDirectory() as td:
app = application.Application(io_factory.IoType.VOID, td, app = application.Application(io_factory.IoType.NONE, td,
fixtures.FILE_CFG) fixtures.FILE_CFG)
assert not app.is_running() assert not app.is_running()
app.start() app.start()

View file

@ -1 +1 @@
__version__ = '0.0.1' __version__ = '0.1.0'

View file

@ -2,25 +2,46 @@ import signal
import sys import sys
import os import os
import traceback import traceback
import argparse
import pathlib
from tsgrain_controller import __version__, application from tsgrain_controller import __version__, application
from tsgrain_controller.io import io_factory 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(): def run():
print(f'TSGRain Controller {__version__}\n') print(f'TSGRain Controller {__version__}\n')
args = _parse_args()
io_type = io_factory.IoType.MCP23017 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: cfg_path = None
arg1 = sys.argv[1] if args.cfg:
if arg1.startswith('c'): cfg_path = args.cfg.name
io_type = io_factory.IoType.CONSOLE
if arg1.startswith('v'): app = application.Application(io_type, cfg_path=cfg_path)
io_type = io_factory.IoType.VOID
app = application.Application(io_type)
def _signal_handler(sig, frame): # pylint: disable=unused-argument def _signal_handler(sig, frame): # pylint: disable=unused-argument
app.stop() app.stop()

View file

@ -20,11 +20,14 @@ class Application(models.AppInterface):
cfg_path = os.path.join(workdir, 'tsgrain.toml') cfg_path = os.path.join(workdir, 'tsgrain.toml')
self.logger = logging.getLogger() self.logger = logging.getLogger()
self.logger.setLevel(logging.DEBUG) self.logger.setLevel(logging.INFO)
self.cfg = config.Config(cfg_path) self.cfg = config.Config(cfg_path)
self.cfg.load_file() self.cfg.load_file()
if self.cfg.log_debug:
self.logger.setLevel(logging.DEBUG)
if self.cfg.db_path: if self.cfg.db_path:
db_path = self.cfg.db_path db_path = self.cfg.db_path
else: else:

View file

@ -4,7 +4,7 @@ from tsgrain_controller import models, io
class IoType(Enum): class IoType(Enum):
VOID = 0 NONE = 0
CONSOLE = 1 CONSOLE = 1
MCP23017 = 2 MCP23017 = 2