S allius/issue180 (#265)
* move default_config.toml into src/cnf/. * improve file handling * remove obsolete rules
This commit is contained in:
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [unreleased]
|
## [unreleased]
|
||||||
|
|
||||||
|
- fix the path handling for logging.ini and default_config.toml [#180](https://github.com/s-allius/tsun-gen3-proxy/issues/180)
|
||||||
|
|
||||||
## [0.12.0] - 2024-12-22
|
## [0.12.0] - 2024-12-22
|
||||||
|
|
||||||
- add hadolint configuration
|
- add hadolint configuration
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ RUN python -m pip install --no-cache-dir --no-cache --no-index /root/wheels/* &&
|
|||||||
|
|
||||||
# copy the content of the local src and config directory to the working directory
|
# copy the content of the local src and config directory to the working directory
|
||||||
COPY --chmod=0700 entrypoint.sh /root/entrypoint.sh
|
COPY --chmod=0700 entrypoint.sh /root/entrypoint.sh
|
||||||
COPY config .
|
|
||||||
COPY src .
|
COPY src .
|
||||||
RUN echo ${VERSION} > /proxy-version.txt \
|
RUN echo ${VERSION} > /proxy-version.txt \
|
||||||
&& date > /build-date.txt
|
&& date > /build-date.txt
|
||||||
|
|||||||
33
app/Makefile
33
app/Makefile
@@ -7,23 +7,6 @@ IMAGE = tsun-gen3-proxy
|
|||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
SRC=.
|
SRC=.
|
||||||
SRC_PROXY=$(SRC)/src
|
|
||||||
CNF_PROXY=$(SRC)/config
|
|
||||||
|
|
||||||
DST=rootfs
|
|
||||||
DST_PROXY=$(DST)/home/proxy
|
|
||||||
|
|
||||||
# collect source files
|
|
||||||
SRC_FILES := $(wildcard $(SRC_PROXY)/*.py)\
|
|
||||||
$(wildcard $(SRC_PROXY)/*.ini)\
|
|
||||||
$(wildcard $(SRC_PROXY)/cnf/*.py)\
|
|
||||||
$(wildcard $(SRC_PROXY)/gen3/*.py)\
|
|
||||||
$(wildcard $(SRC_PROXY)/gen3plus/*.py)
|
|
||||||
CNF_FILES := $(wildcard $(CNF_PROXY)/*.toml)
|
|
||||||
|
|
||||||
# determine destination files
|
|
||||||
TARGET_FILES = $(SRC_FILES:$(SRC_PROXY)/%=$(DST_PROXY)/%)
|
|
||||||
CONFIG_FILES = $(CNF_FILES:$(CNF_PROXY)/%=$(DST_PROXY)/%)
|
|
||||||
|
|
||||||
export BUILD_DATE := ${shell date -Iminutes}
|
export BUILD_DATE := ${shell date -Iminutes}
|
||||||
VERSION := $(shell cat $(SRC)/.version)
|
VERSION := $(shell cat $(SRC)/.version)
|
||||||
@@ -48,20 +31,4 @@ preview rc rel:
|
|||||||
docker buildx bake -f docker-bake.hcl $@
|
docker buildx bake -f docker-bake.hcl $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: debug dev preview rc rel
|
.PHONY: debug dev preview rc rel
|
||||||
|
|
||||||
|
|
||||||
$(CONFIG_FILES): $(DST_PROXY)/% : $(CNF_PROXY)/%
|
|
||||||
@echo Copy $< to $@
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
@cp $< $@
|
|
||||||
|
|
||||||
$(TARGET_FILES): $(DST_PROXY)/% : $(SRC_PROXY)/%
|
|
||||||
@echo Copy $< to $@
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
@cp $< $@
|
|
||||||
|
|
||||||
$(DST)/requirements.txt : $(SRC)/requirements.txt
|
|
||||||
@echo Copy $< to $@
|
|
||||||
@cp $< $@
|
|
||||||
|
|||||||
@@ -156,8 +156,10 @@ def main(): # pragma: no cover
|
|||||||
|
|
||||||
setattr(logging.handlers, "log_path", args.log_path)
|
setattr(logging.handlers, "log_path", args.log_path)
|
||||||
setattr(logging.handlers, "log_backups", args.log_backups)
|
setattr(logging.handlers, "log_backups", args.log_backups)
|
||||||
|
os.makedirs(args.log_path, exist_ok=True)
|
||||||
|
|
||||||
logging.config.fileConfig('logging.ini')
|
src_dir = os.path.dirname(__file__) + '/'
|
||||||
|
logging.config.fileConfig(src_dir + 'logging.ini')
|
||||||
logging.info(f'Server "{serv_name} - {version}" will be started')
|
logging.info(f'Server "{serv_name} - {version}" will be started')
|
||||||
logging.info(f'current dir: {os.getcwd()}')
|
logging.info(f'current dir: {os.getcwd()}')
|
||||||
logging.info(f"config_path: {args.config_path}")
|
logging.info(f"config_path: {args.config_path}")
|
||||||
@@ -184,7 +186,7 @@ def main(): # pragma: no cover
|
|||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
|
||||||
# read config file
|
# read config file
|
||||||
Config.init(ConfigReadToml("default_config.toml"))
|
Config.init(ConfigReadToml(src_dir + "cnf/default_config.toml"))
|
||||||
ConfigReadEnv()
|
ConfigReadEnv()
|
||||||
ConfigReadJson(args.config_path + "config.json")
|
ConfigReadJson(args.config_path + "config.json")
|
||||||
ConfigReadToml(args.config_path + "config.toml")
|
ConfigReadToml(args.config_path + "config.toml")
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ def ConfigComplete():
|
|||||||
}
|
}
|
||||||
|
|
||||||
def test_default_config():
|
def test_default_config():
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
validated = Config.def_config
|
validated = Config.def_config
|
||||||
assert validated == {'gen3plus': {'at_acl': {'mqtt': {'allow': ['AT+'], 'block': []}, 'tsun': {'allow': ['AT+Z', 'AT+UPURL', 'AT+SUPDATE'], 'block': []}}}, 'tsun': {'enabled': True, 'host': 'logger.talent-monitoring.com', 'port': 5005}, 'solarman': {'enabled': True, 'host': 'iot.talent-monitoring.com', 'port': 10000}, 'mqtt': {'host': 'mqtt', 'port': 1883, 'user': None, 'passwd': None}, 'ha': {'auto_conf_prefix': 'homeassistant', 'discovery_prefix': 'homeassistant', 'entity_prefix': 'tsun', 'proxy_node_id': 'proxy', 'proxy_unique_id': 'P170000000000001'},
|
assert validated == {'gen3plus': {'at_acl': {'mqtt': {'allow': ['AT+'], 'block': []}, 'tsun': {'allow': ['AT+Z', 'AT+UPURL', 'AT+SUPDATE'], 'block': []}}}, 'tsun': {'enabled': True, 'host': 'logger.talent-monitoring.com', 'port': 5005}, 'solarman': {'enabled': True, 'host': 'iot.talent-monitoring.com', 'port': 10000}, 'mqtt': {'host': 'mqtt', 'port': 1883, 'user': None, 'passwd': None}, 'ha': {'auto_conf_prefix': 'homeassistant', 'discovery_prefix': 'homeassistant', 'entity_prefix': 'tsun', 'proxy_node_id': 'proxy', 'proxy_unique_id': 'P170000000000001'},
|
||||||
'inverters': {
|
'inverters': {
|
||||||
@@ -193,7 +193,7 @@ def test_full_config(ConfigComplete):
|
|||||||
def test_read_empty(ConfigDefault):
|
def test_read_empty(ConfigDefault):
|
||||||
test_buffer.rd = ""
|
test_buffer.rd = ""
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -216,14 +216,14 @@ def test_no_file():
|
|||||||
assert defcnf == None
|
assert defcnf == None
|
||||||
|
|
||||||
def test_no_file2():
|
def test_no_file2():
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
assert Config.err == None
|
assert Config.err == None
|
||||||
ConfigReadToml("_no__file__no_")
|
ConfigReadToml("_no__file__no_")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
assert err == None
|
assert err == None
|
||||||
|
|
||||||
def test_invalid_filename():
|
def test_invalid_filename():
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
assert Config.err == None
|
assert Config.err == None
|
||||||
ConfigReadToml(None)
|
ConfigReadToml(None)
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -232,7 +232,7 @@ def test_invalid_filename():
|
|||||||
def test_read_cnf1():
|
def test_read_cnf1():
|
||||||
test_buffer.rd = "solarman.enabled = false"
|
test_buffer.rd = "solarman.enabled = false"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -279,7 +279,7 @@ def test_read_cnf1():
|
|||||||
def test_read_cnf2():
|
def test_read_cnf2():
|
||||||
test_buffer.rd = "solarman.enabled = 'FALSE'"
|
test_buffer.rd = "solarman.enabled = 'FALSE'"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -322,7 +322,7 @@ def test_read_cnf2():
|
|||||||
def test_read_cnf3(ConfigDefault):
|
def test_read_cnf3(ConfigDefault):
|
||||||
test_buffer.rd = "solarman.port = 'FALSE'"
|
test_buffer.rd = "solarman.port = 'FALSE'"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -334,7 +334,7 @@ def test_read_cnf3(ConfigDefault):
|
|||||||
def test_read_cnf4():
|
def test_read_cnf4():
|
||||||
test_buffer.rd = "solarman.port = 5000"
|
test_buffer.rd = "solarman.port = 5000"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -377,7 +377,7 @@ def test_read_cnf4():
|
|||||||
def test_read_cnf5():
|
def test_read_cnf5():
|
||||||
test_buffer.rd = "solarman.port = 1023"
|
test_buffer.rd = "solarman.port = 1023"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -386,7 +386,7 @@ def test_read_cnf5():
|
|||||||
def test_read_cnf6():
|
def test_read_cnf6():
|
||||||
test_buffer.rd = "solarman.port = 65536"
|
test_buffer.rd = "solarman.port = 65536"
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadToml("config/config.toml")
|
ConfigReadToml("config/config.toml")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def test_extend_key():
|
|||||||
assert conf == {'': 'testuser'}
|
assert conf == {'': 'testuser'}
|
||||||
|
|
||||||
def test_read_env_config():
|
def test_read_env_config():
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
assert Config.get('mqtt') == {'host': 'mqtt', 'port': 1883, 'user': None, 'passwd': None}
|
assert Config.get('mqtt') == {'host': 'mqtt', 'port': 1883, 'user': None, 'passwd': None}
|
||||||
for _ in patch_getenv():
|
for _ in patch_getenv():
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def ConfigTomlEmpty():
|
|||||||
def test_no_config(ConfigDefault):
|
def test_no_config(ConfigDefault):
|
||||||
test_buffer.rd = "" # empty buffer, no json
|
test_buffer.rd = "" # empty buffer, no json
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadJson()
|
ConfigReadJson()
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -96,7 +96,7 @@ def test_no_config(ConfigDefault):
|
|||||||
def test_no_file(ConfigDefault):
|
def test_no_file(ConfigDefault):
|
||||||
test_buffer.rd = "" # empty buffer, no json
|
test_buffer.rd = "" # empty buffer, no json
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadJson("_no__file__no_")
|
ConfigReadJson("_no__file__no_")
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -108,7 +108,7 @@ def test_no_file(ConfigDefault):
|
|||||||
def test_invalid_filename(ConfigDefault):
|
def test_invalid_filename(ConfigDefault):
|
||||||
test_buffer.rd = "" # empty buffer, no json
|
test_buffer.rd = "" # empty buffer, no json
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadJson(None)
|
ConfigReadJson(None)
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -340,7 +340,7 @@ def test_cnv6():
|
|||||||
def test_empty_config(ConfigDefault):
|
def test_empty_config(ConfigDefault):
|
||||||
test_buffer.rd = "{}" # empty json
|
test_buffer.rd = "{}" # empty json
|
||||||
|
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadJson()
|
ConfigReadJson()
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
@@ -401,7 +401,7 @@ def test_full_config(ConfigComplete):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
Config.init(ConfigReadToml("app/config/default_config.toml"))
|
Config.init(ConfigReadToml("app/src/cnf/default_config.toml"))
|
||||||
for _ in patch_open():
|
for _ in patch_open():
|
||||||
ConfigReadJson()
|
ConfigReadJson()
|
||||||
err = Config.get_error()
|
err = Config.get_error()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ TEMPL=templates
|
|||||||
SRC_FILES := $(wildcard $(SRC_PROXY)/*.py)\
|
SRC_FILES := $(wildcard $(SRC_PROXY)/*.py)\
|
||||||
$(wildcard $(SRC_PROXY)/*.ini)\
|
$(wildcard $(SRC_PROXY)/*.ini)\
|
||||||
$(wildcard $(SRC_PROXY)/cnf/*.py)\
|
$(wildcard $(SRC_PROXY)/cnf/*.py)\
|
||||||
|
$(wildcard $(SRC_PROXY)/cnf/*.toml)\
|
||||||
$(wildcard $(SRC_PROXY)/gen3/*.py)\
|
$(wildcard $(SRC_PROXY)/gen3/*.py)\
|
||||||
$(wildcard $(SRC_PROXY)/gen3plus/*.py)
|
$(wildcard $(SRC_PROXY)/gen3plus/*.py)
|
||||||
CNF_FILES := $(wildcard $(CNF_PROXY)/*.toml)
|
CNF_FILES := $(wildcard $(CNF_PROXY)/*.toml)
|
||||||
|
|||||||
Reference in New Issue
Block a user