mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Removes Logger dependency from setup_data_folder
Logger was only used to log when a new folder was created, and was making that the setup needed to be done on the main of pisad and cli instead of __init__, which seems a better fit
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import apps.cli.conf as conf
|
import apps.cli.conf as conf
|
||||||
from common.tools import extend_paths, check_conf_fields, setup_logging
|
from common.tools import extend_paths, check_conf_fields, setup_logging, setup_data_folder
|
||||||
|
|
||||||
LOG_PREFIX = "cli"
|
LOG_PREFIX = "cli"
|
||||||
|
|
||||||
@@ -24,4 +24,5 @@ conf_fields = extend_paths(conf_fields["DATA_FOLDER"]["value"], conf_fields)
|
|||||||
# Sanity check fields and build config dictionary
|
# Sanity check fields and build config dictionary
|
||||||
config = check_conf_fields(conf_fields)
|
config = check_conf_fields(conf_fields)
|
||||||
|
|
||||||
|
setup_data_folder(config.get("DATA_FOLDER"))
|
||||||
setup_logging(config.get("CLIENT_LOG_FILE"), LOG_PREFIX)
|
setup_logging(config.get("CLIENT_LOG_FILE"), LOG_PREFIX)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from apps.cli.blob import Blob
|
|||||||
from common.logger import Logger
|
from common.logger import Logger
|
||||||
from common.appointment import Appointment
|
from common.appointment import Appointment
|
||||||
from common.cryptographer import Cryptographer
|
from common.cryptographer import Cryptographer
|
||||||
from common.tools import check_sha256_hex_format, check_locator_format, compute_locator, setup_data_folder
|
from common.tools import check_sha256_hex_format, check_locator_format, compute_locator
|
||||||
|
|
||||||
|
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
@@ -343,9 +343,6 @@ if __name__ == "__main__":
|
|||||||
commands = ["add_appointment", "get_appointment", "help"]
|
commands = ["add_appointment", "get_appointment", "help"]
|
||||||
testing_commands = ["generate_dummy_appointment"]
|
testing_commands = ["generate_dummy_appointment"]
|
||||||
|
|
||||||
# Create user folder if missing
|
|
||||||
setup_data_folder(config.get("DATA_FOLDER"), logger)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt(argv[1:], "s:p:h", ["server", "port", "help"])
|
opts, args = getopt(argv[1:], "s:p:h", ["server", "port", "help"])
|
||||||
|
|
||||||
|
|||||||
@@ -42,17 +42,15 @@ def compute_locator(tx_id):
|
|||||||
return tx_id[:LOCATOR_LEN_HEX]
|
return tx_id[:LOCATOR_LEN_HEX]
|
||||||
|
|
||||||
|
|
||||||
def setup_data_folder(data_folder, logger):
|
def setup_data_folder(data_folder):
|
||||||
"""
|
"""
|
||||||
Create a data folder for either the client or the server side if the folder does not exists.
|
Create a data folder for either the client or the server side if the folder does not exists.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data_folder (:obj:`str`): the path of the folder
|
data_folder (:obj:`str`): the path of the folder
|
||||||
logger (:obj: `Logger <common.logger.Logger>`): a logger instance to notify about the folder creation.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not os.path.isdir(data_folder):
|
if not os.path.isdir(data_folder):
|
||||||
logger.info("Data folder not found. Creating it")
|
|
||||||
os.makedirs(data_folder, exist_ok=True)
|
os.makedirs(data_folder, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import pisa.conf as conf
|
import pisa.conf as conf
|
||||||
from common.tools import check_conf_fields, setup_logging, extend_paths
|
from common.tools import check_conf_fields, setup_logging, extend_paths, setup_data_folder
|
||||||
from pisa.utils.auth_proxy import AuthServiceProxy
|
from pisa.utils.auth_proxy import AuthServiceProxy
|
||||||
|
|
||||||
HOST = "localhost"
|
HOST = "localhost"
|
||||||
@@ -34,4 +34,5 @@ conf_fields = extend_paths(conf_fields["DATA_FOLDER"]["value"], conf_fields)
|
|||||||
# Sanity check fields and build config dictionary
|
# Sanity check fields and build config dictionary
|
||||||
config = check_conf_fields(conf_fields)
|
config = check_conf_fields(conf_fields)
|
||||||
|
|
||||||
|
setup_data_folder(config.get("DATA_FOLDER"))
|
||||||
setup_logging(config.get("SERVER_LOG_FILE"), LOG_PREFIX)
|
setup_logging(config.get("SERVER_LOG_FILE"), LOG_PREFIX)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from sys import argv, exit
|
|||||||
from signal import signal, SIGINT, SIGQUIT, SIGTERM
|
from signal import signal, SIGINT, SIGQUIT, SIGTERM
|
||||||
|
|
||||||
from common.logger import Logger
|
from common.logger import Logger
|
||||||
from common.tools import setup_data_folder
|
|
||||||
|
|
||||||
from pisa import config, LOG_PREFIX
|
from pisa import config, LOG_PREFIX
|
||||||
from pisa.api import API
|
from pisa.api import API
|
||||||
@@ -34,8 +33,6 @@ def main():
|
|||||||
signal(SIGQUIT, handle_signals)
|
signal(SIGQUIT, handle_signals)
|
||||||
|
|
||||||
logger.info("Starting PISA")
|
logger.info("Starting PISA")
|
||||||
|
|
||||||
setup_data_folder(config.get("DATA_FOLDER"), logger)
|
|
||||||
db_manager = DBManager(config.get("DB_PATH"))
|
db_manager = DBManager(config.get("DB_PATH"))
|
||||||
|
|
||||||
if not can_connect_to_bitcoind():
|
if not can_connect_to_bitcoind():
|
||||||
|
|||||||
Reference in New Issue
Block a user