Skip to content

Commit

Permalink
Merge branch 'fork/ebwinters/progress'
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jan 23, 2024
2 parents d87ac7e + 1b6d29c commit e48eef3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -75,6 +75,7 @@ Developers
* Gabriel Liss - https://github.com/gabeliss
* Alexandra Rhodes - https://github.com/arhodes130
* Jayanth Bontha - https://github.com/JayanthBontha
* Ethan Winters - https://github.com/ebwinters

Translators
-----------
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -5,6 +5,7 @@
# Application
bleach[css]~=6.1
crispy-bootstrap5==2023.10
tqdm==4.66.1

# this is a fork of django-bootstrap-breadcrumbs
# we might need to think about migrating away from this completely
Expand Down
54 changes: 24 additions & 30 deletions wger/tasks.py
Expand Up @@ -20,6 +20,7 @@
import pathlib
import sys
import tempfile
from tqdm import tqdm

# Django
import django
Expand All @@ -33,22 +34,18 @@
import requests
from invoke import task


logger = logging.getLogger(__name__)
FIXTURE_URL = 'https://github.com/wger-project/data/raw/master/fixtures/'


@task(
help={
'address':
'Address to bind to. Default: localhost',
'port':
'Port to use. Default: 8000',
'settings-path':
'Path to settings file (absolute path). Leave empty for default',
'address': 'Address to bind to. Default: localhost',
'port': 'Port to use. Default: 8000',
'settings-path': 'Path to settings file (absolute path). Leave empty for default',
'extra-args':
'Additional arguments to pass to the builtin server. Pass as string: '
'"--arg1 --arg2=value". Default: none'
'Additional arguments to pass to the builtin server. Pass as string: '
'"--arg1 --arg2=value". Default: none'
}
)
def start(context, address='localhost', port=8000, settings_path=None, extra_args=''):
Expand All @@ -69,10 +66,8 @@ def start(context, address='localhost', port=8000, settings_path=None, extra_arg

@task(
help={
'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default',
'database-path': 'Path to sqlite database (absolute path). Leave empty '
'for default'
'settings-path': 'Path to settings file (absolute path). Leave empty for default',
'database-path': 'Path to sqlite database (absolute path). Leave empty for default'
}
)
def bootstrap(context, settings_path=None, database_path=None):
Expand Down Expand Up @@ -103,12 +98,9 @@ def bootstrap(context, settings_path=None, database_path=None):

@task(
help={
'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default',
'database-path': 'Path to sqlite database (absolute path). Leave empty '
'for default',
'database-type': 'Database type to use. Supported: sqlite3, postgresql. Default: '
'sqlite3',
'settings-path': 'Path to settings file (absolute path). Leave empty for default',
'database-path': 'Path to sqlite database (absolute path). Leave empty for default',
'database-type': 'Database type to use. Supported: sqlite3, postgresql. Default: sqlite3',
'key-length': 'Length of the generated secret key. Default: 50'
}
)
Expand Down Expand Up @@ -180,8 +172,7 @@ def create_settings(
settings_file.write(settings_content)


@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default'})
@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for default'})
def create_or_reset_admin(context, settings_path=None):
"""
Creates an admin user or resets the password for an existing one
Expand All @@ -206,8 +197,7 @@ def create_or_reset_admin(context, settings_path=None):
call_command("loaddata", path + "users.json")


@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default'})
@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for default'})
def migrate_db(context, settings_path=None):
"""
Run all database migrations
Expand All @@ -219,8 +209,7 @@ def migrate_db(context, settings_path=None):
call_command("migrate")


@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default'})
@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for default'})
def load_fixtures(context, settings_path=None):
"""
Loads all fixtures
Expand Down Expand Up @@ -260,13 +249,13 @@ def load_fixtures(context, settings_path=None):


@task(help={'settings-path': 'Path to settings file (absolute path). Leave empty for '
'default'})
'default'})
def load_online_fixtures(context, settings_path=None):
"""
Downloads fixtures from server and installs them (at the moment only ingredients)
"""

# Find the path to the settings and setup the django environment
# Find the path to the settings and set up the django environment
setup_django_environment(settings_path)

# Prepare the download
Expand All @@ -275,14 +264,19 @@ def load_online_fixtures(context, settings_path=None):

print(f'Downloading fixture data from {url}...')
response = requests.get(url, stream=True)
total_size = int(response.headers.get("content-length", 0))
size = int(response.headers["content-length"]) / (1024 * 1024)
print(f'-> fixture size: {size:.3} MB')

# Save to temporary file and load the data
f = tempfile.NamedTemporaryFile(delete=False, suffix='.json.zip')
print(f'-> saving to temp file {f.name}')
f.write(response.content)
with tempfile.NamedTemporaryFile(delete=False, suffix='.json.zip') as f:
print(f'-> saving to temp file {f.name}')
with tqdm(total=total_size, unit='B', unit_scale=True, desc='Downloading') as pbar:
for data in response.iter_content(chunk_size=1024):
f.write(data)
pbar.update(len(data))
f.close()
print('Loading downloaded data, this may take a while...')
call_command("loaddata", f.name)
print('-> removing temp file')
print('')
Expand Down

0 comments on commit e48eef3

Please sign in to comment.