Skip to content

Commit

Permalink
feat: check db access
Browse files Browse the repository at this point in the history
  • Loading branch information
flobz committed Jan 15, 2024
1 parent 8d35953 commit 6cb6bf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions psa_car_controller/psacc/application/car_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import atexit
import logging
import socket
import sys
import threading
from os import environ, path

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions psa_car_controller/psacc/repository/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6cb6bf6

Please sign in to comment.