mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
Refactors cli to use the new config approach. Adds template.conf
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
import os
|
||||
import cli.conf as conf
|
||||
from common.tools import extend_paths, check_conf_fields, setup_logging, setup_data_folder
|
||||
|
||||
DATA_DIR = os.path.expanduser("~/.teos_cli/")
|
||||
CONF_FILE_NAME = "teos_cli.conf"
|
||||
LOG_PREFIX = "cli"
|
||||
|
||||
# Load config fields
|
||||
conf_fields = {
|
||||
"DEFAULT_TEOS_API_SERVER": {"value": conf.DEFAULT_TEOS_API_SERVER, "type": str},
|
||||
"DEFAULT_TEOS_API_PORT": {"value": conf.DEFAULT_TEOS_API_PORT, "type": int},
|
||||
"DATA_FOLDER": {"value": conf.DATA_FOLDER, "type": str},
|
||||
"CLIENT_LOG_FILE": {"value": conf.CLIENT_LOG_FILE, "type": str, "path": True},
|
||||
"APPOINTMENTS_FOLDER_NAME": {"value": conf.APPOINTMENTS_FOLDER_NAME, "type": str, "path": True},
|
||||
"CLI_PUBLIC_KEY": {"value": conf.CLI_PUBLIC_KEY, "type": str, "path": True},
|
||||
"CLI_PRIVATE_KEY": {"value": conf.CLI_PRIVATE_KEY, "type": str, "path": True},
|
||||
"TEOS_PUBLIC_KEY": {"value": conf.TEOS_PUBLIC_KEY, "type": str, "path": True},
|
||||
DEFAULT_CONF = {
|
||||
"TEOS_SERVER": {"value": "http://localhost", "type": str},
|
||||
"TEOS_PORT": {"value": 9814, "type": int},
|
||||
"LOG_FILE": {"value": "teos_cli.log", "type": str, "path": True},
|
||||
"APPOINTMENTS_FOLDER_NAME": {"value": "appointment_receipts", "type": str, "path": True},
|
||||
"CLI_PUBLIC_KEY": {"value": "cli_pk.der", "type": str, "path": True},
|
||||
"CLI_PRIVATE_KEY": {"value": "cli_sk.der", "type": str, "path": True},
|
||||
"TEOS_PUBLIC_KEY": {"value": "teos_pk.der", "type": str, "path": True},
|
||||
}
|
||||
|
||||
# Expand user (~) if found and check fields are correct
|
||||
conf_fields["DATA_FOLDER"]["value"] = os.path.expanduser(conf_fields["DATA_FOLDER"]["value"])
|
||||
# Extend relative paths
|
||||
conf_fields = extend_paths(conf_fields["DATA_FOLDER"]["value"], conf_fields)
|
||||
|
||||
# Sanity check fields and build config dictionary
|
||||
config = check_conf_fields(conf_fields)
|
||||
|
||||
setup_data_folder(config.get("DATA_FOLDER"))
|
||||
setup_logging(config.get("CLIENT_LOG_FILE"), LOG_PREFIX)
|
||||
|
||||
Reference in New Issue
Block a user