FabOMatic 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- FabOMatic/__init__.py +1 -0
- FabOMatic/__main__.py +85 -0
- FabOMatic/alembic/README +1 -0
- FabOMatic/alembic/env.py +78 -0
- FabOMatic/alembic/script.py.mako +26 -0
- FabOMatic/alembic/versions/123b2cca325f_added_boards_table.py +38 -0
- FabOMatic/alembic/versions/2dc275252e0e_initial_database_creation.py +135 -0
- FabOMatic/alembic/versions/3cb12dfd8d6e_maintenance_added_short_lcd_message.py +30 -0
- FabOMatic/alembic/versions/3f3f601505a6_added_replay_columns_for_use_and_.py +33 -0
- FabOMatic/alembic/versions/88feb1b31a1f_added_grace_period_column_on_machinetype.py +32 -0
- FabOMatic/alembic/versions/aa9ed3e094d5_maintenance_added_url_field_and_removed_.py +60 -0
- FabOMatic/alembic/versions/dfd2b0db0016_machine_types_added_possibility_to_.py +30 -0
- FabOMatic/alembic/versions/e544554c7d29_boards_added_columns_for_serial_number_.py +32 -0
- FabOMatic/babel.cfg +3 -0
- FabOMatic/conf/settings.toml +24 -0
- FabOMatic/database/DatabaseBackend.py +337 -0
- FabOMatic/database/__init__.py +0 -0
- FabOMatic/database/constants.py +15 -0
- FabOMatic/database/models.py +397 -0
- FabOMatic/database/repositories.py +748 -0
- FabOMatic/flask_app/static/css/all.css +8003 -0
- FabOMatic/flask_app/static/css/all.min.css +9 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.css +4085 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.rtl.css +4084 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.rtl.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.rtl.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-grid.rtl.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.css +591 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.rtl.css +588 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.rtl.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.rtl.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-reboot.rtl.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.css +5397 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.rtl.css +5388 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.rtl.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.rtl.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap-utilities.rtl.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap.css +12113 -0
- FabOMatic/flask_app/static/css/bootstrap.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap.min.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap.rtl.css +12077 -0
- FabOMatic/flask_app/static/css/bootstrap.rtl.css.map +1 -0
- FabOMatic/flask_app/static/css/bootstrap.rtl.min.css +6 -0
- FabOMatic/flask_app/static/css/bootstrap.rtl.min.css.map +1 -0
- FabOMatic/flask_app/static/css/brands.css +1573 -0
- FabOMatic/flask_app/static/css/brands.min.css +6 -0
- FabOMatic/flask_app/static/css/fontawesome.css +6369 -0
- FabOMatic/flask_app/static/css/fontawesome.min.css +9 -0
- FabOMatic/flask_app/static/css/regular.css +19 -0
- FabOMatic/flask_app/static/css/regular.min.css +6 -0
- FabOMatic/flask_app/static/css/solid.css +19 -0
- FabOMatic/flask_app/static/css/solid.min.css +6 -0
- FabOMatic/flask_app/static/css/svg-with-js.css +640 -0
- FabOMatic/flask_app/static/css/svg-with-js.min.css +6 -0
- FabOMatic/flask_app/static/css/v4-font-face.css +26 -0
- FabOMatic/flask_app/static/css/v4-font-face.min.css +6 -0
- FabOMatic/flask_app/static/css/v4-shims.css +2194 -0
- FabOMatic/flask_app/static/css/v4-shims.min.css +6 -0
- FabOMatic/flask_app/static/css/v5-font-face.css +22 -0
- FabOMatic/flask_app/static/css/v5-font-face.min.css +6 -0
- FabOMatic/flask_app/static/js/bootstrap.bundle.js +6295 -0
- FabOMatic/flask_app/static/js/bootstrap.bundle.js.map +1 -0
- FabOMatic/flask_app/static/js/bootstrap.bundle.min.js +7 -0
- FabOMatic/flask_app/static/js/bootstrap.bundle.min.js.map +1 -0
- FabOMatic/flask_app/static/js/bootstrap.esm.js +4423 -0
- FabOMatic/flask_app/static/js/bootstrap.esm.js.map +1 -0
- FabOMatic/flask_app/static/js/bootstrap.esm.min.js +7 -0
- FabOMatic/flask_app/static/js/bootstrap.esm.min.js.map +1 -0
- FabOMatic/flask_app/static/js/bootstrap.js +4469 -0
- FabOMatic/flask_app/static/js/bootstrap.js.map +1 -0
- FabOMatic/flask_app/static/js/bootstrap.min.js +7 -0
- FabOMatic/flask_app/static/js/bootstrap.min.js.map +1 -0
- FabOMatic/flask_app/static/webfonts/fa-brands-400.ttf +0 -0
- FabOMatic/flask_app/static/webfonts/fa-brands-400.woff2 +0 -0
- FabOMatic/flask_app/static/webfonts/fa-regular-400.ttf +0 -0
- FabOMatic/flask_app/static/webfonts/fa-regular-400.woff2 +0 -0
- FabOMatic/flask_app/static/webfonts/fa-solid-900.ttf +0 -0
- FabOMatic/flask_app/static/webfonts/fa-solid-900.woff2 +0 -0
- FabOMatic/flask_app/static/webfonts/fa-v4compatibility.ttf +0 -0
- FabOMatic/flask_app/static/webfonts/fa-v4compatibility.woff2 +0 -0
- FabOMatic/flask_app/templates/about.html +50 -0
- FabOMatic/flask_app/templates/add_authorization.html +23 -0
- FabOMatic/flask_app/templates/add_intervention.html +34 -0
- FabOMatic/flask_app/templates/add_machine.html +30 -0
- FabOMatic/flask_app/templates/add_machinetype.html +35 -0
- FabOMatic/flask_app/templates/add_maintenance.html +34 -0
- FabOMatic/flask_app/templates/add_role.html +26 -0
- FabOMatic/flask_app/templates/add_use.html +36 -0
- FabOMatic/flask_app/templates/add_user.html +38 -0
- FabOMatic/flask_app/templates/base.html +17 -0
- FabOMatic/flask_app/templates/base_body.html +90 -0
- FabOMatic/flask_app/templates/base_refresh.html +19 -0
- FabOMatic/flask_app/templates/bulkadd_authorizations.html +59 -0
- FabOMatic/flask_app/templates/delete_authorization.html +9 -0
- FabOMatic/flask_app/templates/delete_intervention.html +12 -0
- FabOMatic/flask_app/templates/delete_machine.html +12 -0
- FabOMatic/flask_app/templates/delete_machinetype.html +12 -0
- FabOMatic/flask_app/templates/delete_maintenance.html +12 -0
- FabOMatic/flask_app/templates/delete_role.html +12 -0
- FabOMatic/flask_app/templates/delete_use.html +23 -0
- FabOMatic/flask_app/templates/delete_user.html +12 -0
- FabOMatic/flask_app/templates/edit_authorization.html +24 -0
- FabOMatic/flask_app/templates/edit_intervention.html +38 -0
- FabOMatic/flask_app/templates/edit_machine.html +31 -0
- FabOMatic/flask_app/templates/edit_machinetype.html +35 -0
- FabOMatic/flask_app/templates/edit_maintenance.html +40 -0
- FabOMatic/flask_app/templates/edit_role.html +36 -0
- FabOMatic/flask_app/templates/edit_user.html +41 -0
- FabOMatic/flask_app/templates/forgot_password.html +25 -0
- FabOMatic/flask_app/templates/index.html +7 -0
- FabOMatic/flask_app/templates/login.html +18 -0
- FabOMatic/flask_app/templates/macros.html +4 -0
- FabOMatic/flask_app/templates/reset_token.html +24 -0
- FabOMatic/flask_app/templates/reset_user.html +12 -0
- FabOMatic/flask_app/templates/view_authorizations.html +51 -0
- FabOMatic/flask_app/templates/view_interventions.html +68 -0
- FabOMatic/flask_app/templates/view_machine_use_history.html +31 -0
- FabOMatic/flask_app/templates/view_machines.html +60 -0
- FabOMatic/flask_app/templates/view_machinetypes.html +55 -0
- FabOMatic/flask_app/templates/view_maintenances.html +48 -0
- FabOMatic/flask_app/templates/view_roles.html +63 -0
- FabOMatic/flask_app/templates/view_system.html +89 -0
- FabOMatic/flask_app/templates/view_users.html +81 -0
- FabOMatic/flask_app/templates/view_uses.html +101 -0
- FabOMatic/logger.py +53 -0
- FabOMatic/logic/MachineLogic.py +245 -0
- FabOMatic/logic/MsgMapper.py +169 -0
- FabOMatic/logic/__init__.py +0 -0
- FabOMatic/mqtt/MQTTInterface.py +252 -0
- FabOMatic/mqtt/__init__.py +0 -0
- FabOMatic/mqtt/mqtt_types.py +199 -0
- FabOMatic/translations/en/LC_MESSAGES/messages.mo +0 -0
- FabOMatic/translations/en/LC_MESSAGES/messages.po +1091 -0
- FabOMatic/translations/it/LC_MESSAGES/messages.mo +0 -0
- FabOMatic/translations/it/LC_MESSAGES/messages.po +1086 -0
- FabOMatic/web/__init__.py +14 -0
- FabOMatic/web/authentication.py +101 -0
- FabOMatic/web/routes_authorizations.py +142 -0
- FabOMatic/web/routes_interventions.py +126 -0
- FabOMatic/web/routes_languages.py +8 -0
- FabOMatic/web/routes_machines.py +116 -0
- FabOMatic/web/routes_machinetypes.py +109 -0
- FabOMatic/web/routes_maintenance.py +121 -0
- FabOMatic/web/routes_roles.py +89 -0
- FabOMatic/web/routes_system.py +145 -0
- FabOMatic/web/routes_users.py +169 -0
- FabOMatic/web/routes_uses.py +174 -0
- FabOMatic/web/webapplication.py +169 -0
- fabomatic-0.4.2.dist-info/METADATA +247 -0
- fabomatic-0.4.2.dist-info/RECORD +162 -0
- fabomatic-0.4.2.dist-info/WHEEL +4 -0
- fabomatic-0.4.2.dist-info/licenses/LICENSE +21 -0
FabOMatic/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .__main__ import start
|
FabOMatic/__main__.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Main module of the backend."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import threading
|
|
5
|
+
from time import sleep
|
|
6
|
+
|
|
7
|
+
from FabOMatic.database.DatabaseBackend import DatabaseBackend
|
|
8
|
+
from FabOMatic.mqtt.MQTTInterface import MQTTInterface
|
|
9
|
+
from FabOMatic.logic.MsgMapper import MsgMapper
|
|
10
|
+
from FabOMatic.logger import configure_logger
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Backend:
|
|
14
|
+
"""Backend class."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, config_file: str = None):
|
|
17
|
+
if config_file is None:
|
|
18
|
+
self._db = DatabaseBackend()
|
|
19
|
+
self._mqtt = MQTTInterface()
|
|
20
|
+
else:
|
|
21
|
+
self._db = DatabaseBackend(config_file)
|
|
22
|
+
self._mqtt = MQTTInterface(config_file)
|
|
23
|
+
|
|
24
|
+
self._mapper = MsgMapper(self._mqtt, self._db)
|
|
25
|
+
self._mapper.registerHandlers()
|
|
26
|
+
self._flaskThread = None
|
|
27
|
+
|
|
28
|
+
def connect(self) -> bool:
|
|
29
|
+
"""Connect to the MQTT broker and the database."""
|
|
30
|
+
try:
|
|
31
|
+
session = self._db.getSession()
|
|
32
|
+
logging.info(f"Session info: {session.info}")
|
|
33
|
+
self._db.createAndUpdateDatabase()
|
|
34
|
+
self._mqtt.connect()
|
|
35
|
+
return True
|
|
36
|
+
except Exception as ex:
|
|
37
|
+
logging.error("Connection failed: %s", ex, exc_info=True)
|
|
38
|
+
return False
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def connected(self) -> bool:
|
|
42
|
+
"""Check if the MQTT broker is connected."""
|
|
43
|
+
return self._mqtt.connected
|
|
44
|
+
|
|
45
|
+
def disconnect(self):
|
|
46
|
+
"""Disconnect from the MQTT broker"""
|
|
47
|
+
self._mqtt.disconnect()
|
|
48
|
+
|
|
49
|
+
def publishStats(self):
|
|
50
|
+
self._mqtt.publishStats()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
_flaskThread: threading.Thread = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _startApp() -> None:
|
|
57
|
+
from FabOMatic.web.webapplication import app
|
|
58
|
+
|
|
59
|
+
app.run(host="0.0.0.0", port=23336, debug=True, use_reloader=False, ssl_context="adhoc")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def startServer() -> None:
|
|
63
|
+
global _flaskThread
|
|
64
|
+
_flaskThread = threading.Thread(target=lambda: _startApp(), daemon=True)
|
|
65
|
+
_flaskThread.start()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def start(loglevel):
|
|
69
|
+
"""Main function of the backend."""
|
|
70
|
+
configure_logger(loglevel)
|
|
71
|
+
logging.info("Starting backend...")
|
|
72
|
+
back = Backend()
|
|
73
|
+
startServer()
|
|
74
|
+
|
|
75
|
+
while True:
|
|
76
|
+
if not back.connected:
|
|
77
|
+
if not back.connect():
|
|
78
|
+
logging.error("Failed to connect to Database or MQTT broker")
|
|
79
|
+
else:
|
|
80
|
+
back.publishStats()
|
|
81
|
+
sleep(5)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
start(10)
|
FabOMatic/alembic/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Generic single-database configuration.
|
FabOMatic/alembic/env.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from logging.config import fileConfig
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import engine_from_config
|
|
4
|
+
from sqlalchemy import pool
|
|
5
|
+
from FabOMatic.database.DatabaseBackend import getDatabaseUrl
|
|
6
|
+
from alembic import context
|
|
7
|
+
from FabOMatic.database import models
|
|
8
|
+
|
|
9
|
+
# this is the Alembic Config object, which provides
|
|
10
|
+
# access to the values within the .ini file in use.
|
|
11
|
+
config = context.config
|
|
12
|
+
|
|
13
|
+
# Interpret the config file for Python logging.
|
|
14
|
+
# This line sets up loggers basically.
|
|
15
|
+
if config.config_file_name is not None and config.attributes.get("configure_logger", True):
|
|
16
|
+
fileConfig(config.config_file_name, disable_existing_loggers=False)
|
|
17
|
+
|
|
18
|
+
# add your model's MetaData object here
|
|
19
|
+
# for 'autogenerate' support
|
|
20
|
+
# from myapp import mymodel
|
|
21
|
+
# target_metadata = mymodel.Base.metadata
|
|
22
|
+
target_metadata = models.Base.metadata
|
|
23
|
+
|
|
24
|
+
print("Using database=", config.get_main_option("sqlalchemy.url"))
|
|
25
|
+
# other values from the config, defined by the needs of env.py,
|
|
26
|
+
# can be acquired:
|
|
27
|
+
# my_important_option = config.get_main_option("my_important_option")
|
|
28
|
+
# ... etc.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def run_migrations_offline() -> None:
|
|
32
|
+
"""Run migrations in 'offline' mode.
|
|
33
|
+
|
|
34
|
+
This configures the context with just a URL
|
|
35
|
+
and not an Engine, though an Engine is acceptable
|
|
36
|
+
here as well. By skipping the Engine creation
|
|
37
|
+
we don't even need a DBAPI to be available.
|
|
38
|
+
|
|
39
|
+
Calls to context.execute() here emit the given string to the
|
|
40
|
+
script output.
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
url = config.get_main_option("sqlalchemy.url")
|
|
44
|
+
context.configure(
|
|
45
|
+
url=url,
|
|
46
|
+
target_metadata=target_metadata,
|
|
47
|
+
literal_binds=True,
|
|
48
|
+
dialect_opts={"paramstyle": "named"},
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
with context.begin_transaction():
|
|
52
|
+
context.run_migrations()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def run_migrations_online() -> None:
|
|
56
|
+
"""Run migrations in 'online' mode.
|
|
57
|
+
|
|
58
|
+
In this scenario we need to create an Engine
|
|
59
|
+
and associate a connection with the context.
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
connectable = engine_from_config(
|
|
63
|
+
config.get_section(config.config_ini_section, {}),
|
|
64
|
+
prefix="sqlalchemy.",
|
|
65
|
+
poolclass=pool.NullPool,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
with connectable.connect() as connection:
|
|
69
|
+
context.configure(connection=connection, target_metadata=target_metadata)
|
|
70
|
+
|
|
71
|
+
with context.begin_transaction():
|
|
72
|
+
context.run_migrations()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if context.is_offline_mode():
|
|
76
|
+
run_migrations_offline()
|
|
77
|
+
else:
|
|
78
|
+
run_migrations_online()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
Create Date: ${create_date}
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
${imports if imports else ""}
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = ${repr(up_revision)}
|
|
16
|
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
${upgrades if upgrades else "pass"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
${downgrades if downgrades else "pass"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Added Boards table
|
|
2
|
+
|
|
3
|
+
Revision ID: 123b2cca325f
|
|
4
|
+
Revises: 88feb1b31a1f
|
|
5
|
+
Create Date: 2024-02-20 23:00:47.808587
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = '123b2cca325f'
|
|
16
|
+
down_revision: Union[str, None] = '88feb1b31a1f'
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.create_table('boards',
|
|
24
|
+
sa.Column('board_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
25
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
26
|
+
sa.Column('ip_address', sa.String(), nullable=False),
|
|
27
|
+
sa.Column('fw_version', sa.String(), nullable=False),
|
|
28
|
+
sa.Column('last_seen', sa.Float(), nullable=False),
|
|
29
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
30
|
+
sa.PrimaryKeyConstraint('board_id')
|
|
31
|
+
)
|
|
32
|
+
# ### end Alembic commands ###
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def downgrade() -> None:
|
|
36
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
37
|
+
op.drop_table('boards')
|
|
38
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Initial database creation
|
|
2
|
+
|
|
3
|
+
Revision ID: 2dc275252e0e
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2024-01-28 16:25:31.644671
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = '2dc275252e0e'
|
|
16
|
+
down_revision: Union[str, None] = None
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.create_table('machine_types',
|
|
24
|
+
sa.Column('type_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
25
|
+
sa.Column('type_name', sa.String(), nullable=False),
|
|
26
|
+
sa.Column('type_timeout_min', sa.Integer(), nullable=False),
|
|
27
|
+
sa.PrimaryKeyConstraint('type_id'),
|
|
28
|
+
sa.UniqueConstraint('type_name')
|
|
29
|
+
)
|
|
30
|
+
op.create_index('idx_machine_types_type_name_unique', 'machine_types', ['type_name'], unique=True)
|
|
31
|
+
op.create_table('roles',
|
|
32
|
+
sa.Column('role_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
33
|
+
sa.Column('role_name', sa.String(), nullable=False),
|
|
34
|
+
sa.Column('authorize_all', sa.Boolean(), nullable=False),
|
|
35
|
+
sa.Column('reserved', sa.Boolean(), nullable=False),
|
|
36
|
+
sa.Column('maintenance', sa.Boolean(), nullable=False),
|
|
37
|
+
sa.Column('backend_admin', sa.Boolean(), nullable=False),
|
|
38
|
+
sa.PrimaryKeyConstraint('role_id'),
|
|
39
|
+
sa.UniqueConstraint('role_name')
|
|
40
|
+
)
|
|
41
|
+
op.create_index('idx_roles_role_name_unique', 'roles', ['role_name'], unique=True)
|
|
42
|
+
op.create_table('machines',
|
|
43
|
+
sa.Column('machine_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
44
|
+
sa.Column('machine_name', sa.String(), nullable=False),
|
|
45
|
+
sa.Column('machine_type_id', sa.Integer(), nullable=True),
|
|
46
|
+
sa.Column('machine_hours', sa.Float(), nullable=False),
|
|
47
|
+
sa.Column('blocked', sa.Boolean(), nullable=False),
|
|
48
|
+
sa.Column('last_seen', sa.Float(), nullable=True),
|
|
49
|
+
sa.ForeignKeyConstraint(['machine_type_id'], ['machine_types.type_id'], ),
|
|
50
|
+
sa.PrimaryKeyConstraint('machine_id'),
|
|
51
|
+
sa.UniqueConstraint('machine_name')
|
|
52
|
+
)
|
|
53
|
+
op.create_index('idx_machines_machine_name_unique', 'machines', ['machine_name'], unique=True)
|
|
54
|
+
op.create_table('users',
|
|
55
|
+
sa.Column('user_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
56
|
+
sa.Column('name', sa.String(), nullable=False),
|
|
57
|
+
sa.Column('surname', sa.String(), nullable=False),
|
|
58
|
+
sa.Column('role_id', sa.Integer(), nullable=False),
|
|
59
|
+
sa.Column('card_UUID', sa.String(), nullable=True),
|
|
60
|
+
sa.Column('disabled', sa.Boolean(), nullable=False),
|
|
61
|
+
sa.Column('deleted', sa.Boolean(), nullable=False),
|
|
62
|
+
sa.Column('password_hash', sa.String(length=128), nullable=True),
|
|
63
|
+
sa.Column('email', sa.String(), nullable=True),
|
|
64
|
+
sa.ForeignKeyConstraint(['role_id'], ['roles.role_id'], ),
|
|
65
|
+
sa.PrimaryKeyConstraint('user_id'),
|
|
66
|
+
sa.UniqueConstraint('card_UUID')
|
|
67
|
+
)
|
|
68
|
+
op.create_index('idx_users_card_UUID_unique', 'users', ['card_UUID'], unique=True)
|
|
69
|
+
op.create_table('authorizations',
|
|
70
|
+
sa.Column('authorization_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
71
|
+
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
72
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
73
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
74
|
+
sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ),
|
|
75
|
+
sa.PrimaryKeyConstraint('authorization_id'),
|
|
76
|
+
sa.UniqueConstraint('user_id', 'machine_id', name='uix_1')
|
|
77
|
+
)
|
|
78
|
+
op.create_table('maintenances',
|
|
79
|
+
sa.Column('maintenance_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
80
|
+
sa.Column('hours_between', sa.Float(), nullable=False),
|
|
81
|
+
sa.Column('description', sa.String(), nullable=False),
|
|
82
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
83
|
+
sa.Column('attachment', sa.String(), nullable=True),
|
|
84
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
85
|
+
sa.PrimaryKeyConstraint('maintenance_id')
|
|
86
|
+
)
|
|
87
|
+
op.create_table('unknown_cards',
|
|
88
|
+
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
89
|
+
sa.Column('card_UUID', sa.String(), nullable=False),
|
|
90
|
+
sa.Column('timestamp', sa.Float(), nullable=False),
|
|
91
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
92
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
93
|
+
sa.PrimaryKeyConstraint('id')
|
|
94
|
+
)
|
|
95
|
+
op.create_table('uses',
|
|
96
|
+
sa.Column('use_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
97
|
+
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
98
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
99
|
+
sa.Column('start_timestamp', sa.Float(), nullable=False),
|
|
100
|
+
sa.Column('last_seen', sa.Float(), nullable=False),
|
|
101
|
+
sa.Column('end_timestamp', sa.Float(), nullable=True),
|
|
102
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
103
|
+
sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ),
|
|
104
|
+
sa.PrimaryKeyConstraint('use_id')
|
|
105
|
+
)
|
|
106
|
+
op.create_table('interventions',
|
|
107
|
+
sa.Column('intervention_id', sa.Integer(), autoincrement=True, nullable=False),
|
|
108
|
+
sa.Column('maintenance_id', sa.Integer(), nullable=False),
|
|
109
|
+
sa.Column('machine_id', sa.Integer(), nullable=False),
|
|
110
|
+
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
111
|
+
sa.Column('timestamp', sa.Float(), nullable=False),
|
|
112
|
+
sa.ForeignKeyConstraint(['machine_id'], ['machines.machine_id'], ),
|
|
113
|
+
sa.ForeignKeyConstraint(['maintenance_id'], ['maintenances.maintenance_id'], ),
|
|
114
|
+
sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ),
|
|
115
|
+
sa.PrimaryKeyConstraint('intervention_id')
|
|
116
|
+
)
|
|
117
|
+
# ### end Alembic commands ###
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def downgrade() -> None:
|
|
121
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
122
|
+
op.drop_table('interventions')
|
|
123
|
+
op.drop_table('uses')
|
|
124
|
+
op.drop_table('unknown_cards')
|
|
125
|
+
op.drop_table('maintenances')
|
|
126
|
+
op.drop_table('authorizations')
|
|
127
|
+
op.drop_index('idx_users_card_UUID_unique', table_name='users')
|
|
128
|
+
op.drop_table('users')
|
|
129
|
+
op.drop_index('idx_machines_machine_name_unique', table_name='machines')
|
|
130
|
+
op.drop_table('machines')
|
|
131
|
+
op.drop_index('idx_roles_role_name_unique', table_name='roles')
|
|
132
|
+
op.drop_table('roles')
|
|
133
|
+
op.drop_index('idx_machine_types_type_name_unique', table_name='machine_types')
|
|
134
|
+
op.drop_table('machine_types')
|
|
135
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Maintenance: added short lcd message
|
|
2
|
+
|
|
3
|
+
Revision ID: 3cb12dfd8d6e
|
|
4
|
+
Revises: e544554c7d29
|
|
5
|
+
Create Date: 2024-04-24 22:17:20.179783
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = '3cb12dfd8d6e'
|
|
16
|
+
down_revision: Union[str, None] = 'e544554c7d29'
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.add_column('maintenances', sa.Column('lcd_message', sa.String(), nullable=True))
|
|
24
|
+
# ### end Alembic commands ###
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def downgrade() -> None:
|
|
28
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
29
|
+
op.drop_column('maintenances', 'lcd_message')
|
|
30
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Added replay columns for Use and Intervention
|
|
2
|
+
|
|
3
|
+
Revision ID: 3f3f601505a6
|
|
4
|
+
Revises: dfd2b0db0016
|
|
5
|
+
Create Date: 2024-05-30 23:09:40.723754
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Sequence, Union
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# revision identifiers, used by Alembic.
|
|
16
|
+
revision: str = "3f3f601505a6"
|
|
17
|
+
down_revision: Union[str, None] = "dfd2b0db0016"
|
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def upgrade() -> None:
|
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
24
|
+
op.add_column("interventions", sa.Column("replay", sa.Boolean(), nullable=True))
|
|
25
|
+
op.add_column("uses", sa.Column("replay", sa.Boolean(), nullable=True))
|
|
26
|
+
# ### end Alembic commands ###
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def downgrade() -> None:
|
|
30
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
31
|
+
op.drop_column("uses", "replay")
|
|
32
|
+
op.drop_column("interventions", "replay")
|
|
33
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Added grace period column on MachineType
|
|
2
|
+
|
|
3
|
+
Revision ID: 88feb1b31a1f
|
|
4
|
+
Revises: 2dc275252e0e
|
|
5
|
+
Create Date: 2024-02-18 21:20:47.213287
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Sequence, Union
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# revision identifiers, used by Alembic.
|
|
16
|
+
revision: str = "88feb1b31a1f"
|
|
17
|
+
down_revision: Union[str, None] = "2dc275252e0e"
|
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def upgrade() -> None:
|
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
24
|
+
op.add_column("machine_types", sa.Column("grace_period_min", sa.Integer(), nullable=True))
|
|
25
|
+
# ### end Alembic commands ###
|
|
26
|
+
op.execute("UPDATE machine_types SET grace_period_min=2 WHERE grace_period_min IS NULL")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def downgrade() -> None:
|
|
30
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
31
|
+
op.drop_column("machine_types", "grace_period_min")
|
|
32
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Maintenance: added URL field and removed attachments.
|
|
2
|
+
|
|
3
|
+
Revision ID: aa9ed3e094d5
|
|
4
|
+
Revises: 3cb12dfd8d6e
|
|
5
|
+
Create Date: 2024-04-24 22:39:03.511051
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Sequence, Union
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# revision identifiers, used by Alembic.
|
|
16
|
+
revision: str = "aa9ed3e094d5"
|
|
17
|
+
down_revision: Union[str, None] = "3cb12dfd8d6e"
|
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
20
|
+
|
|
21
|
+
from alembic import op
|
|
22
|
+
from sqlalchemy import engine_from_config
|
|
23
|
+
from sqlalchemy import inspect
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _table_has_column(table, column):
|
|
27
|
+
config = op.get_context().config
|
|
28
|
+
engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.")
|
|
29
|
+
insp = inspect(engine)
|
|
30
|
+
has_column = False
|
|
31
|
+
for col in insp.get_columns(table):
|
|
32
|
+
if column not in col["name"]:
|
|
33
|
+
continue
|
|
34
|
+
has_column = True
|
|
35
|
+
return has_column
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _is_sqllite():
|
|
39
|
+
return op.get_context().dialect.name == "sqlite"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def upgrade() -> None:
|
|
43
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
44
|
+
if not _table_has_column("maintenances", "instructions_url"):
|
|
45
|
+
op.add_column("maintenances", sa.Column("instructions_url", sa.String(), nullable=True))
|
|
46
|
+
if _table_has_column("maintenances", "attachment"):
|
|
47
|
+
if not _is_sqllite():
|
|
48
|
+
op.drop_column("maintenances", "attachment")
|
|
49
|
+
# ### end Alembic commands ###
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def downgrade() -> None:
|
|
53
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
54
|
+
if _table_has_column("maintenances", "instructions_url"):
|
|
55
|
+
if not _is_sqllite():
|
|
56
|
+
op.drop_column("maintenances", "instructions_url")
|
|
57
|
+
|
|
58
|
+
if not _table_has_column("maintenances", "attachment"):
|
|
59
|
+
op.add_column("maintenances", sa.Column("attachment", sa.String(), nullable=True))
|
|
60
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Machine types: added possibility to disable authorization
|
|
2
|
+
|
|
3
|
+
Revision ID: dfd2b0db0016
|
|
4
|
+
Revises: aa9ed3e094d5
|
|
5
|
+
Create Date: 2024-05-05 20:27:50.705509
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = 'dfd2b0db0016'
|
|
16
|
+
down_revision: Union[str, None] = 'aa9ed3e094d5'
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.add_column('machine_types', sa.Column('access_management', sa.Integer(), nullable=True))
|
|
24
|
+
# ### end Alembic commands ###
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def downgrade() -> None:
|
|
28
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
29
|
+
op.drop_column('machine_types', 'access_management')
|
|
30
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Boards: added columns for serial number and free heap
|
|
2
|
+
|
|
3
|
+
Revision ID: e544554c7d29
|
|
4
|
+
Revises: 123b2cca325f
|
|
5
|
+
Create Date: 2024-04-21 13:24:54.520194
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = 'e544554c7d29'
|
|
16
|
+
down_revision: Union[str, None] = '123b2cca325f'
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.add_column('boards', sa.Column('serial', sa.String(), nullable=True))
|
|
24
|
+
op.add_column('boards', sa.Column('heap', sa.Integer(), nullable=True))
|
|
25
|
+
# ### end Alembic commands ###
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def downgrade() -> None:
|
|
29
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
30
|
+
op.drop_column('boards', 'heap')
|
|
31
|
+
op.drop_column('boards', 'serial')
|
|
32
|
+
# ### end Alembic commands ###
|
FabOMatic/babel.cfg
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[database]
|
|
2
|
+
url = "sqlite:///database.sqldb" # Database source. Will be seeded if empty.
|
|
3
|
+
name = "fablab" # Name of the database
|
|
4
|
+
|
|
5
|
+
[MQTT]
|
|
6
|
+
broker = "fabpi" # Name / IP of the MQTT broker
|
|
7
|
+
port = 1883 # MQTT broker port
|
|
8
|
+
client_id = "backend-3" # MQTT Client name
|
|
9
|
+
topic = "machine" # Machine topic to be monitored. All subtopics with <topic>/<ID> will be subscribed. Do not include leading or trailing slashes.
|
|
10
|
+
reply_subtopic = "/reply" # appended to the <topic>/<id> for replies by backend. E.g. machine/1/reply
|
|
11
|
+
stats_topic = "stats" # Stats will be published in this topic on MQTT server.
|
|
12
|
+
user = "" # Auth not used
|
|
13
|
+
|
|
14
|
+
[web]
|
|
15
|
+
secret_key = "ç°32è+3242039ikòlòà" # Used for encryption by Flask. Change it to a random string.
|
|
16
|
+
default_admin_email = "admin@fablab.org" # Email of the admin, used for 1st login and seeding.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[email]
|
|
20
|
+
server = "smtp.google.com"
|
|
21
|
+
port = 587
|
|
22
|
+
use_tls = true
|
|
23
|
+
username = ""
|
|
24
|
+
password = ""
|