mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
adjusted database and config paths
This commit is contained in:
parent
297be826dd
commit
7ff95571c3
|
@ -77,7 +77,6 @@ def freedv_get_mode_name_by_value(mode: int) -> str:
|
||||||
# Get the directory of the current script file
|
# Get the directory of the current script file
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
sys.path.append(script_dir)
|
sys.path.append(script_dir)
|
||||||
|
|
||||||
# Use script_dir to construct the paths for file search
|
# Use script_dir to construct the paths for file search
|
||||||
if sys.platform == "linux":
|
if sys.platform == "linux":
|
||||||
files = glob.glob(os.path.join(script_dir, "**/*libcodec2*"), recursive=True)
|
files = glob.glob(os.path.join(script_dir, "**/*libcodec2*"), recursive=True)
|
||||||
|
|
|
@ -2,12 +2,16 @@ from message_system_db_manager import DatabaseManager
|
||||||
from message_system_db_model import MessageAttachment, Attachment, P2PMessage
|
from message_system_db_model import MessageAttachment, Attachment, P2PMessage
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManagerAttachments(DatabaseManager):
|
class DatabaseManagerAttachments(DatabaseManager):
|
||||||
def __init__(self, uri='sqlite:///freedata-messages.db'):
|
def __init__(self, db_file=None):
|
||||||
super().__init__(uri)
|
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):
|
def add_attachment(self, session, message, attachment_data):
|
||||||
|
|
|
@ -4,14 +4,16 @@ from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
from threading import local
|
from threading import local
|
||||||
from message_system_db_model import Base, Beacon, Station, Status, Attachment, P2PMessage
|
from message_system_db_model import Base, Beacon, Station, Status, Attachment, P2PMessage
|
||||||
from datetime import timezone, timedelta, datetime
|
from datetime import timezone, timedelta, datetime
|
||||||
import json
|
import os
|
||||||
import structlog
|
|
||||||
import helpers
|
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManagerBeacon(DatabaseManager):
|
class DatabaseManagerBeacon(DatabaseManager):
|
||||||
def __init__(self, uri):
|
def __init__(self, db_file=None):
|
||||||
super().__init__(uri)
|
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):
|
def add_beacon(self, timestamp, callsign, snr, gridsquare):
|
||||||
session = None
|
session = None
|
||||||
|
|
|
@ -7,12 +7,17 @@ from threading import local
|
||||||
from message_system_db_model import Base, Station, Status
|
from message_system_db_model import Base, Station, Status
|
||||||
import structlog
|
import structlog
|
||||||
import helpers
|
import helpers
|
||||||
|
import os
|
||||||
|
|
||||||
class DatabaseManager:
|
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
|
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.thread_local = local()
|
||||||
self.session_factory = sessionmaker(bind=self.engine)
|
self.session_factory = sessionmaker(bind=self.engine)
|
||||||
Base.metadata.create_all(self.engine)
|
Base.metadata.create_all(self.engine)
|
||||||
|
|
|
@ -4,12 +4,18 @@ from message_system_db_model import Status, P2PMessage
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManagerMessages(DatabaseManager):
|
class DatabaseManagerMessages(DatabaseManager):
|
||||||
def __init__(self, uri='sqlite:///freedata-messages.db'):
|
def __init__(self, db_file=None):
|
||||||
super().__init__(uri)
|
if not db_file:
|
||||||
self.attachments_manager = DatabaseManagerAttachments(uri)
|
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):
|
def add_message(self, message_data, statistics, direction='receive', status=None, is_read=True):
|
||||||
session = self.get_thread_scoped_session()
|
session = self.get_thread_scoped_session()
|
||||||
|
|
|
@ -36,7 +36,8 @@ def set_config():
|
||||||
if 'FREEDATA_CONFIG' in os.environ:
|
if 'FREEDATA_CONFIG' in os.environ:
|
||||||
config_file = os.environ['FREEDATA_CONFIG']
|
config_file = os.environ['FREEDATA_CONFIG']
|
||||||
else:
|
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):
|
if os.path.exists(config_file):
|
||||||
print(f"Using config from {config_file}")
|
print(f"Using config from {config_file}")
|
||||||
|
|
Loading…
Reference in a new issue