Skip to content

Commit f9abdc3

Browse files
committed
simplify config override
1 parent 0007f23 commit f9abdc3

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

alembic_db/alembic/versions/ef49f6644e0c_save_user_code.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from alembic_db.alembic_post_utils import write_revision_post_alembic
1515

16-
from mycodo.config import SQL_DATABASE_MYCODO
1716
from mycodo.config import ID_FILE
1817
from mycodo.config import STATS_CSV
1918

@@ -24,8 +23,6 @@
2423
branch_labels = None
2524
depends_on = None
2625

27-
MYCODO_DB_PATH = f'sqlite:///{SQL_DATABASE_MYCODO}'
28-
2926

3027
def upgrade():
3128
write_revision_post_alembic(revision)

mycodo/config.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
# config.py - Global Mycodo settings
44
#
55
import binascii
6-
import sys
6+
import os
77
import subprocess
8+
import sys
89
from datetime import timedelta
910

10-
import os
1111
from flask_babel import lazy_gettext as lg
1212

1313
# Append proper path for other software reading this config file
1414
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
15-
1615
from config_translations import TRANSLATIONS as T
17-
try:
18-
import config_override
19-
except:
20-
pass
2116

2217
MYCODO_VERSION = '8.16.0'
2318
ALEMBIC_VERSION = '5966b3569c89'
@@ -40,25 +35,21 @@
4035
# Install path (the parent directory of this file)
4136
INSTALL_DIRECTORY = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..')
4237

43-
# Database
38+
# Settings database
4439
DATABASE_PATH = os.path.join(INSTALL_DIRECTORY, 'databases')
4540
DATABASE_NAME = "mycodo.db"
4641
SQL_DATABASE_MYCODO = os.path.join(DATABASE_PATH, DATABASE_NAME)
42+
ALEMBIC_PATH = os.path.join(INSTALL_DIRECTORY, 'alembic_db')
43+
ALEMBIC_UPGRADE_POST = os.path.join(ALEMBIC_PATH, 'alembic_post_upgrade_versions')
44+
4745
try:
46+
import config_override
4847
MYCODO_DB_PATH = config_override.MYCODO_DB_PATH
4948
except:
5049
MYCODO_DB_PATH = f'sqlite:///{SQL_DATABASE_MYCODO}'
5150

52-
# Alembic
53-
ALEMBIC_PATH = os.path.join(INSTALL_DIRECTORY, 'alembic_db')
54-
ALEMBIC_UPGRADE_POST = os.path.join(ALEMBIC_PATH, 'alembic_post_upgrade_versions')
55-
try: # Ensure the correct alembic url is set
56-
ALEMBIC_URL = config_override.ALEMBIC_URL
57-
cmd = f'/opt/Mycodo/env/bin/crudini --set /opt/Mycodo/alembic_db/alembic.ini alembic sqlalchemy.url {ALEMBIC_URL}'
58-
subprocess.Popen(cmd, shell=True)
59-
except:
60-
cmd = '/opt/Mycodo/env/bin/crudini --set /opt/Mycodo/alembic_db/alembic.ini alembic sqlalchemy.url sqlite:///../databases/mycodo.db'
61-
subprocess.Popen(cmd, shell=True)
51+
cmd = f'/opt/Mycodo/env/bin/crudini --set /opt/Mycodo/alembic_db/alembic.ini alembic sqlalchemy.url {MYCODO_DB_PATH}'
52+
subprocess.Popen(cmd, shell=True)
6253

6354
# Misc paths
6455
PATH_1WIRE = '/sys/bus/w1/devices/'

mycodo/functions/example_function_all_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def loop(self):
374374
# Deactivate controller in the SQL database
375375
self.logger.debug(
376376
"Deactivating (SQL) Custom controller select_device_2 with ID {}".format(self.select_device_2_id))
377-
from mycodo.config import MYCODO_DB_PATH, SQL_DATABASE_MYCODO
377+
from mycodo.config import MYCODO_DB_PATH
378378
from mycodo.databases.utils import session_scope
379379
with session_scope(MYCODO_DB_PATH) as new_session:
380380
mod_cont = new_session.query(CustomController).filter(

mycodo/utils/tools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ def create_settings_export(save_path=None):
8686
try:
8787
data = io.BytesIO()
8888
with zipfile.ZipFile(data, mode='w') as z:
89-
z.write(SQL_DATABASE_MYCODO,
90-
os.path.basename(SQL_DATABASE_MYCODO))
89+
try:
90+
z.write(SQL_DATABASE_MYCODO,
91+
os.path.basename(SQL_DATABASE_MYCODO))
92+
except:
93+
logger.error(f"Could not find database file {SQL_DATABASE_MYCODO}")
94+
9195
export_directories = [
9296
(PATH_FUNCTIONS_CUSTOM, "custom_functions"),
9397
(PATH_ACTIONS_CUSTOM, "custom_actions"),

0 commit comments

Comments
 (0)