adjusted database and config paths

This commit is contained in:
DJ2LS 2024-03-01 21:29:11 +01:00
parent 297be826dd
commit 7ff95571c3
6 changed files with 33 additions and 16 deletions

View File

@ -77,7 +77,6 @@ def freedv_get_mode_name_by_value(mode: int) -> str:
# Get the directory of the current script file
script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_dir)
# Use script_dir to construct the paths for file search
if sys.platform == "linux":
files = glob.glob(os.path.join(script_dir, "**/*libcodec2*"), recursive=True)

View File

@ -2,12 +2,16 @@ from message_system_db_manager import DatabaseManager
from message_system_db_model import MessageAttachment, Attachment, P2PMessage
import json
import hashlib
import os
class DatabaseManagerAttachments(DatabaseManager):
def __init__(self, uri='sqlite:///freedata-messages.db'):
super().__init__(uri)
def __init__(self, db_file=None):
if not db_file:
script_dir = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(script_dir, 'freedata-messages.db')
db_file = 'sqlite:///' + db_path
super().__init__(db_file)
def add_attachment(self, session, message, attachment_data):

View File

@ -4,14 +4,16 @@ from sqlalchemy.orm import scoped_session, sessionmaker
from threading import local
from message_system_db_model import Base, Beacon, Station, Status, Attachment, P2PMessage
from datetime import timezone, timedelta, datetime
import json
import structlog
import helpers
import os
class DatabaseManagerBeacon(DatabaseManager):
def __init__(self, uri):
super().__init__(uri)
def __init__(self, db_file=None):
if not db_file:
script_dir = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(script_dir, 'freedata-messages.db')
db_file = 'sqlite:///' + db_path
super().__init__(db_file)
def add_beacon(self, timestamp, callsign, snr, gridsquare):
session = None

View File

@ -7,12 +7,17 @@ from threading import local
from message_system_db_model import Base, Station, Status
import structlog
import helpers
import os
class DatabaseManager:
def __init__(self, event_manger, uri='sqlite:///freedata-messages.db'):
def __init__(self, event_manger, db_file=None):
self.event_manager = event_manger
if not db_file:
script_dir = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(script_dir, 'freedata-messages.db')
db_file = 'sqlite:///' + db_path
self.engine = create_engine(uri, echo=False)
self.engine = create_engine(db_file, echo=False)
self.thread_local = local()
self.session_factory = sessionmaker(bind=self.engine)
Base.metadata.create_all(self.engine)

View File

@ -4,12 +4,18 @@ from message_system_db_model import Status, P2PMessage
from sqlalchemy.exc import IntegrityError
from datetime import datetime
import json
import os
class DatabaseManagerMessages(DatabaseManager):
def __init__(self, uri='sqlite:///freedata-messages.db'):
super().__init__(uri)
self.attachments_manager = DatabaseManagerAttachments(uri)
def __init__(self, db_file=None):
if not db_file:
script_dir = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(script_dir, 'freedata-messages.db')
db_file = 'sqlite:///' + db_path
super().__init__(db_file)
self.attachments_manager = DatabaseManagerAttachments(db_file)
def add_message(self, message_data, statistics, direction='receive', status=None, is_read=True):
session = self.get_thread_scoped_session()

View File

@ -36,7 +36,8 @@ def set_config():
if 'FREEDATA_CONFIG' in os.environ:
config_file = os.environ['FREEDATA_CONFIG']
else:
config_file = 'config.ini'
script_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(script_dir, 'config.ini')
if os.path.exists(config_file):
print(f"Using config from {config_file}")