mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 17:06:18 +00:00
feat: check db access
This commit is contained in:
committed by
Florian BEZANNIER
parent
8d35953747
commit
6cb6bf6578
@@ -2,6 +2,7 @@ import argparse
|
||||
import atexit
|
||||
import logging
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
from os import environ, path
|
||||
|
||||
@@ -11,6 +12,7 @@ from oauth2_client.credentials_manager import OAuthError
|
||||
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 @@ class PSACarController(metaclass=Singleton):
|
||||
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
|
||||
|
||||
@@ -128,6 +128,15 @@ class Database:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user