-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Use pdm and ruff. Rename "test" to "tests". Introduce semver
- Loading branch information
1 parent
360017a
commit 82ffb9c
Showing
37 changed files
with
1,093 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import datetime | ||
import dataclasses | ||
import datetime | ||
import logging | ||
import os | ||
import random | ||
|
@@ -13,7 +13,6 @@ | |
from flask_sqlalchemy import SQLAlchemy | ||
from sqlalchemy.exc import OperationalError | ||
|
||
|
||
db = SQLAlchemy() | ||
login_manager = flask_login.LoginManager() | ||
|
||
|
@@ -36,7 +35,9 @@ def create_app(config=None): | |
app.socketio = SocketIO(app) | ||
|
||
if os.path.exists(f"config_{socket.gethostname()}.py"): | ||
logging.getLogger(__name__).info(f'Using config file "config_{socket.gethostname()}"') | ||
logging.getLogger(__name__).info( | ||
f'Using config file "config_{socket.gethostname()}"' | ||
) | ||
app.config.from_object(f"config_{socket.gethostname()}") | ||
else: | ||
logging.getLogger(__name__).info('Using config file "config"') | ||
|
@@ -63,7 +64,10 @@ def init_db(app): | |
flask.current_app.db.init_app(app) | ||
|
||
if ( | ||
(flask.current_app.config["DB_BACKEND"] == "sqlite" and not os.path.exists("coffee.db")) | ||
( | ||
flask.current_app.config["DB_BACKEND"] == "sqlite" | ||
and not os.path.exists("coffee.db") | ||
) | ||
or flask.current_app.config.get("ENV") in ("development", "prefilled") | ||
or flask.current_app.testing | ||
): | ||
|
@@ -77,7 +81,10 @@ def init_db(app): | |
if flask.current_app.config.get("ENV") == "development": | ||
flask.current_app.db.session.add( | ||
coffeebuddy.model.User( | ||
tag=bytes.fromhex("01020304"), name="Mustermann", prename="Max", email="[email protected]" | ||
tag=bytes.fromhex("01020304"), | ||
name="Mustermann", | ||
prename="Max", | ||
email="[email protected]", | ||
) | ||
) | ||
flask.current_app.db.session.commit() | ||
|
@@ -86,8 +93,14 @@ def init_db(app): | |
prefill() | ||
|
||
if flask.current_app.config["GUEST"]: | ||
if not coffeebuddy.model.User.query.filter(coffeebuddy.model.User.name == "Guest").first(): | ||
flask.current_app.db.session.add(coffeebuddy.model.User(tag=b"\xff\xff\xff\xff", name="Guest", prename="")) | ||
if not coffeebuddy.model.User.query.filter( | ||
coffeebuddy.model.User.name == "Guest" | ||
).first(): | ||
flask.current_app.db.session.add( | ||
coffeebuddy.model.User( | ||
tag=b"\xff\xff\xff\xff", name="Guest", prename="" | ||
) | ||
) | ||
flask.current_app.db.session.commit() | ||
|
||
return flask.current_app.db | ||
|
@@ -129,12 +142,42 @@ def prefill(): | |
import coffeebuddy.model | ||
|
||
demousers = [ | ||
{"prename": "Donald", "postname": "Duck", "email": "[email protected]", "oneswipe": True}, | ||
{"prename": "Dagobert", "postname": "Duck", "email": "[email protected]", "oneswipe": False}, | ||
{"prename": "Gyro", "postname": " Gearloose", "email": "[email protected]", "oneswipe": False}, | ||
{"prename": "Tick ", "postname": "Duck", "email": "[email protected]", "oneswipe": False}, | ||
{"prename": "Trick", "postname": "Duck", "email": "[email protected]", "oneswipe": False}, | ||
{"prename": "Truck", "postname": "Duck", "email": "[email protected]", "oneswipe": False}, | ||
{ | ||
"prename": "Donald", | ||
"postname": "Duck", | ||
"email": "[email protected]", | ||
"oneswipe": True, | ||
}, | ||
{ | ||
"prename": "Dagobert", | ||
"postname": "Duck", | ||
"email": "[email protected]", | ||
"oneswipe": False, | ||
}, | ||
{ | ||
"prename": "Gyro", | ||
"postname": " Gearloose", | ||
"email": "[email protected]", | ||
"oneswipe": False, | ||
}, | ||
{ | ||
"prename": "Tick ", | ||
"postname": "Duck", | ||
"email": "[email protected]", | ||
"oneswipe": False, | ||
}, | ||
{ | ||
"prename": "Trick", | ||
"postname": "Duck", | ||
"email": "[email protected]", | ||
"oneswipe": False, | ||
}, | ||
{ | ||
"prename": "Truck", | ||
"postname": "Duck", | ||
"email": "[email protected]", | ||
"oneswipe": False, | ||
}, | ||
] | ||
for idx, data in enumerate(demousers): | ||
flask.current_app.db.session.add( | ||
|
@@ -151,7 +194,8 @@ def prefill(): | |
coffeebuddy.model.Drink( | ||
userid=random.randint(0, len(demousers)), | ||
price=flask.current_app.config["PRICE"], | ||
timestamp=datetime.datetime.now() - datetime.timedelta(seconds=random.randint(0, 365 * 24 * 60 * 60)), | ||
timestamp=datetime.datetime.now() | ||
- datetime.timedelta(seconds=random.randint(0, 365 * 24 * 60 * 60)), | ||
) | ||
) | ||
flask.current_app.db.session.commit() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.