2018-05-11 17:55:46 +02:00
|
|
|
import shutil
|
|
|
|
|
2020-09-16 15:41:02 +02:00
|
|
|
from fittrackee import create_app, db
|
2020-09-16 18:58:11 +02:00
|
|
|
from fittrackee.activities.models import Activity
|
2020-09-16 15:41:02 +02:00
|
|
|
from fittrackee.activities.utils import update_activity
|
2020-09-16 18:58:11 +02:00
|
|
|
from fittrackee.application.utils import init_config
|
2019-01-06 16:01:44 +01:00
|
|
|
from tqdm import tqdm
|
2017-12-16 21:00:46 +01:00
|
|
|
|
2020-09-16 18:58:11 +02:00
|
|
|
from .database_utils import init_database
|
|
|
|
|
2018-04-09 22:09:58 +02:00
|
|
|
app = create_app()
|
|
|
|
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
@app.cli.command()
|
2018-01-20 19:12:34 +01:00
|
|
|
def drop_db():
|
2018-05-10 11:36:08 +02:00
|
|
|
"""Empty database for dev environments."""
|
|
|
|
db.engine.execute("DROP TABLE IF EXISTS alembic_version;")
|
2017-12-16 21:00:46 +01:00
|
|
|
db.drop_all()
|
2018-01-20 19:12:34 +01:00
|
|
|
db.session.commit()
|
|
|
|
print('Database dropped.')
|
2018-05-11 17:55:46 +02:00
|
|
|
shutil.rmtree(app.config['UPLOAD_FOLDER'], ignore_errors=True)
|
|
|
|
print('Uploaded files deleted.')
|
2018-01-20 19:12:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.cli.command()
|
2018-11-18 13:55:21 +01:00
|
|
|
def initdata():
|
2020-09-16 18:58:11 +02:00
|
|
|
"""Init the database and application config."""
|
|
|
|
init_database(app)
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
|
2019-01-06 16:01:44 +01:00
|
|
|
@app.cli.command()
|
|
|
|
def recalculate():
|
|
|
|
print("Starting activities data refresh")
|
2019-08-28 13:25:39 +02:00
|
|
|
activities = (
|
2020-07-14 16:23:48 +02:00
|
|
|
Activity.query.filter(Activity.gpx != None) # noqa
|
2019-08-28 13:25:39 +02:00
|
|
|
.order_by(Activity.activity_date.asc()) # noqa
|
|
|
|
.all()
|
|
|
|
)
|
2019-01-06 16:01:44 +01:00
|
|
|
if len(activities) == 0:
|
|
|
|
print('➡️ no activities to upgrade.')
|
|
|
|
return None
|
|
|
|
pbar = tqdm(activities)
|
|
|
|
for activity in pbar:
|
|
|
|
update_activity(activity)
|
|
|
|
pbar.set_postfix(activitiy_id=activity.id)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2019-11-13 18:40:01 +01:00
|
|
|
@app.cli.command('init-app-config')
|
|
|
|
def init_app_config():
|
|
|
|
"""Init application configuration."""
|
|
|
|
print("Init application configuration")
|
|
|
|
config_created, _ = init_config()
|
|
|
|
if config_created:
|
|
|
|
print("Creation done!")
|
|
|
|
else:
|
|
|
|
print(
|
|
|
|
"Application configuration already existing in database. "
|
|
|
|
"Please use web application to update it."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-12-16 21:00:46 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run()
|