diff --git a/psa_car_controller/psacc/application/car_controller.py b/psa_car_controller/psacc/application/car_controller.py index 5e06a31e..64e6e7a3 100644 --- a/psa_car_controller/psacc/application/car_controller.py +++ b/psa_car_controller/psacc/application/car_controller.py @@ -2,6 +2,7 @@ import atexit import logging import socket +import sys import threading from os import environ, path @@ -11,6 +12,7 @@ from .charge_control import ChargeControls from .charging import Charging from psa_car_controller.psacc.repository.config_repository import ConfigRepository +from psa_car_controller.psacc.repository.db import Database from psa_car_controller.psacc.utils.utils import Singleton from .psa_client import PSAClient from psa_car_controller.common.mylogger import my_logger @@ -88,6 +90,8 @@ def load_app(self) -> bool: return False else: raise FileNotFoundError(self.config_name) + if not Database.check_db_access(): + sys.exit(1) atexit.register(self.save_config) self.myp.set_record(self.args.record) Charging.elec_price = self.config.Electricity_config diff --git a/psa_car_controller/psacc/repository/db.py b/psa_car_controller/psacc/repository/db.py index 8e497ff9..4dd0c038 100644 --- a/psa_car_controller/psacc/repository/db.py +++ b/psa_car_controller/psacc/repository/db.py @@ -128,6 +128,15 @@ def init_db(conn): sqlite3.register_adapter(datetime, Database.convert_datetime_to_string) Database.db_initialized = True + @staticmethod + def check_db_access() -> bool: + try: + Database.get_db() + return True + except sqlite3.OperationalError: + logger.fatal("Can't access to db file check permission") + return False + @staticmethod def get_db(db_file=None, update_callback=True) -> CustomSqliteConnection: if db_file is None: