Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Move tasks file to wger folder

Roland Geidere5e0a288891c
diff --git a/MANIFEST.in b/MANIFEST.in
index 07285af5e..a85b00b96 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -7,4 +7,17 @@ include requirements.txt
recursive-include wger *.*
recursive-exclude wger *.pyc
recursive-exclude wger *.swp
-recursive-exclude wger *~
\ No newline at end of file
+recursive-exclude wger *~
+
+# added by check_manifest.py
+include *.rst
+include *.txt
+recursive-include docs *.bat
+recursive-include docs *.py
+recursive-include docs *.rst
+recursive-include docs Makefile
+recursive-include extras *.README
+recursive-include extras *.conf
+recursive-include extras *.csv
+recursive-include extras *.py
+recursive-include extras *.txt
diff --git a/README.rst b/README.rst
index 2436c1485..c060796a1 100644
--- a/README.rst
+++ b/README.rst
@@ -53,9 +53,8 @@ state.
$ git clone https://github.com/rolandgeider/wger.git
$ cd wger
- $ npm install bower
$ pip install -r requirements.txt # or requirements_devel.txt to develop
- $ invoke bootstrap_wger
+ $ invoke --root wger bootstrap_wger
3) Log in as: **admin**, password **admin**
diff --git a/docs/development.rst b/docs/development.rst
index b0ffb99d1..33514d280 100644
--- a/docs/development.rst
+++ b/docs/development.rst
@@ -14,8 +14,7 @@ and populate it with data on the first run::
$ git clone https://github.com/rolandgeider/wger.git
$ cd wger
$ pip install -r requirements_devel.txt
- $ npm install bower
- $ invoke bootstrap_wger
+ $ invoke --root wger bootstrap_wger
That's it. You can log in with the default administator user:
diff --git a/extras/docker/apache/Dockerfile b/extras/docker/apache/Dockerfile
index 36346d608..f6de492da 100644
--- a/extras/docker/apache/Dockerfile
+++ b/extras/docker/apache/Dockerfile
@@ -30,10 +30,12 @@ RUN npm install bower \
&& . /home/wger/venv/bin/activate \
&& pip install --upgrade pip \
&& pip install -r requirements.txt \
- && invoke create_settings \
+ && invoke --root wger create_settings \
--settings-path /home/wger/src/settings.py \
--database-path /home/wger/db/database.sqlite \
- && invoke bootstrap_wger --settings-path /home/wger/src/settings.py --no-start-server
+ && invoke --root wger bootstrap_wger \
+ --settings-path /home/wger/src/settings.py \
+ --no-start-server
# Change permissions of some files and folders so the apache process
diff --git a/extras/docker/development/Dockerfile b/extras/docker/development/Dockerfile
index c2521b55d..139844bb8 100644
--- a/extras/docker/development/Dockerfile
+++ b/extras/docker/development/Dockerfile
@@ -21,16 +21,18 @@ RUN apt-get install -y vim
# Set up the application
USER wger
RUN git clone https://github.com/rolandgeider/wger.git /home/wger/src
+
WORKDIR /home/wger/src
RUN virtualenv --python python3 /home/wger/venv
-RUN npm install bower \
- && . /home/wger/venv/bin/activate \
+RUN . /home/wger/venv/bin/activate \
&& pip install --upgrade pip \
&& pip install -r requirements_devel.txt \
- && invoke create_settings \
+ && invoke --root wgercreate_settings \
--settings-path /home/wger/src/settings.py \
--database-path /home/wger/db/database.sqlite \
- && invoke bootstrap_wger --settings-path /home/wger/src/settings.py --no-start-server
+ && invoke --root wger bootstrap_wger \
+ --settings-path /home/wger/src/settings.py \
+ --no-start-server
-CMD ["/bin/bash"]
+CMD ["/bin/bash"]
\ No newline at end of file
diff --git a/manage.py b/manage.py
index f96ff50df..d5c1c05be 100755
--- a/manage.py
+++ b/manage.py
@@ -3,7 +3,7 @@ import sys
from django.core.management import execute_from_command_line
-from wger.utils.main import (
+from wger.tasks import (
setup_django_environment,
get_user_config_path
)
diff --git a/setup.cfg b/setup.cfg
index 1cdf3f6a6..38fe76970 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,4 +1,4 @@
[pep8]
-exclude = urls.py,*migrations*,*bower_components*
+exclude = urls.py,tasks.py,*migrations*,*bower_components*
max-line-length = 100
ignore = W503
diff --git a/wger/__main__.py b/wger/__main__.py
index 0732105e2..f53b2d7e5 100644
--- a/wger/__main__.py
+++ b/wger/__main__.py
@@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU Affero General Public License
+import os
import sys
from invoke import run
@@ -23,13 +24,18 @@ version of the application. It simply redirects all arguments to the invoke
command, which does all the work.
'''
+# Get the absolute path so we can pass it to invoke. This is only needed
+# for the packaged version.
+tasks_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wger')
+invoke_cmd = 'invoke --root {} '.format(tasks_path)
+
def main():
args = sys.argv[1:]
if len(args):
- run('invoke ' + ' '.join(args), pty=True)
+ run(invoke_cmd + ' '.join(args), pty=True)
else:
- run('invoke --list')
+ run(invoke_cmd + '--list')
if __name__ == '__main__':
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 03f1b4b6f..0d7a3e855 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -25,9 +25,12 @@ For a full list of options, visit:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
-BASE_DIR = os.path.dirname(os.path.dirname(__file__))
+BASE_DIR = os.path.abspath(os.path.dirname(__file__))
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
+print(BASE_DIR)
+print(SITE_ROOT)
+print('===========================')
#
# Application definition
@@ -314,6 +317,8 @@ if sys.platform.startswith('win32'):
else:
BOWER_PATH = os.path.join(BASE_DIR, 'node_modules', '.bin', 'bower')
+print(BOWER_PATH)
+
#
# Django Rest Framework
#
diff --git a/tasks.py b/wger/tasks.py
similarity index 68%
rename from tasks.py
rename to wger/tasks.py
index 497d6c28c..f83a3c0c3 100644
--- a/tasks.py
+++ b/wger/tasks.py
@@ -14,25 +14,35 @@
#
# You should have received a copy of the GNU Affero General Public License
-import inspect
-import os
-from invoke import task
+import sys
+#
+# This is an ugly and terrible hack, please don't do this!
+#
+# The reason we do this is that during django's setup later in this script, it
+# tries to load the standard library's "mail" module which collides with our
+# (perhaps unluckily named) app with the same name. Since this script is only
+# used for installation and does not depend on anything from wger proper, it
+# is kind of OK to change the system path.
+sys.path = sys.path[1:]
+
+import time
+import logging
+import threading
+import webbrowser
+import os
+import ctypes
+import socket
+from invoke import task, run
+import django
from django.utils.crypto import get_random_string
from django.core.management import (
call_command,
execute_from_command_line
)
-from wger.utils.main import (
- get_user_data_path,
- get_user_config_path,
- detect_listen_opts,
- setup_django_environment,
- database_exists,
- start_browser
-)
+logger = logging.getLogger(__name__)
@task(help={'address': 'Address to bind to. Default: localhost',
@@ -98,6 +108,8 @@ def bootstrap_wger(settings_path=None,
create_or_reset_admin(settings_path=settings_path)
# Download JS libraries with bower
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
+ run('npm install bower')
call_command('bower', 'install')
# Start the webserver
@@ -131,11 +143,10 @@ def create_settings(settings_path=None, database_path=None, url=None, database_t
url = 'http://localhost:8000'
# Fill in the config file template
-
- # os.chdir(os.path.dirname(inspect.stack()[0][1]))
- settings_template = os.path.join(os.getcwd(), 'wger', 'settings.tpl')
+ settings_template = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'settings.tpl')
with open(settings_template, 'r') as settings_file:
settings_content = settings_file.read()
+
# The environment variable is set by travis during testing
if database_type == 'postgresql':
dbengine = 'postgresql_psycopg2'
@@ -195,8 +206,10 @@ def create_or_reset_admin(settings_path=None):
except User.DoesNotExist:
print("*** Created default admin user")
- os.chdir(os.path.dirname(inspect.stack()[0][1]))
- current_dir = os.path.join(os.getcwd(), 'wger')
+ # os.chdir(os.path.dirname(inspect.stack()[0][1]))
+ # current_dir = os.path.join(os.getcwd(), 'wger')
+ current_dir = os.path.dirname(os.path.abspath(__file__))
+
path = os.path.join(current_dir, 'core', 'fixtures/')
call_command("loaddata", path + "users.json")
@@ -222,8 +235,10 @@ def load_fixtures(settings_path=None):
# Find the path to the settings and setup the django environment
setup_django_environment(settings_path)
- os.chdir(os.path.dirname(inspect.stack()[0][1]))
- current_dir = os.path.join(os.getcwd(), 'wger')
+
+ # os.chdir(os.path.dirname(inspect.stack()[0][1]))
+ # current_dir = os.path.join(os.getcwd(), 'wger')
+ current_dir = os.path.dirname(os.path.abspath(__file__))
# Gym
path = os.path.join(current_dir, 'gym', 'fixtures/')
@@ -274,3 +289,132 @@ def config_location():
print('* settings: {0}'.format(get_user_config_path('wger', 'settings.py')))
print('* media folder: {0}'.format(get_user_data_path('wger', 'media')))
print('* database path: {0}'.format(get_user_data_path('wger', 'database.sqlite')))
+
+
+#
+#
+# Helper functions
+#
+# Note: these functions were originally in wger/utils/main.py but were moved
+# here because of different import problems (the packaged pip-installed
+# packaged has a different sys path than the local one)
+#
+
+
+def get_user_data_path(*args):
+ if sys.platform == "win32":
+ return win32_get_app_data_path(*args)
+
+ data_home = os.environ.get(
+ 'XDG_DATA_HOME', os.path.join(
+ os.path.expanduser('~'), '.local', 'share'))
+
+ return os.path.join(data_home, *args)
+
+
+def get_user_config_path(*args):
+ if sys.platform == "win32":
+ return win32_get_app_data_path(*args)
+
+ config_home = os.environ.get(
+ 'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
+
+ return os.path.join(config_home, *args)
+
+
+def win32_get_app_data_path(*args):
+ shell32 = ctypes.WinDLL("shell32.dll")
+ SHGetFolderPath = shell32.SHGetFolderPathW
+ SHGetFolderPath.argtypes = (
+ ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_uint32,
+ ctypes.c_wchar_p)
+ SHGetFolderPath.restype = ctypes.c_uint32
+
+ CSIDL_LOCAL_APPDATA = 0x001c
+ MAX_PATH = 260
+
+ buf = ctypes.create_unicode_buffer(MAX_PATH)
+ res = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, buf)
+ if res != 0:
+ raise Exception("Could not deterime APPDATA path")
+
+ return os.path.join(buf.value, *args)
+
+
+def detect_listen_opts(address, port):
+ if address is None:
+ try:
+ address = socket.gethostbyname(socket.gethostname())
+ except socket.error:
+ address = "127.0.0.1"
+
+ if port is None:
+ # test if we can use port 80
+ s = socket.socket()
+ port = 80
+ try:
+ s.bind((address, port))
+ s.listen(-1)
+ except socket.error:
+ port = 8000
+ finally:
+ s.close()
+
+ return address, port
+
+
+def setup_django_environment(settings_path):
+ '''
+ Setup the django environment
+ '''
+
+ # Use default settings if the user didn't specify something else
+ if settings_path is None:
+ settings_path = get_user_config_path('wger', 'settings.py')
+ print('*** No settings given, using {0}'.format(settings_path))
+
+ # Find out file path and fine name of settings and setup django
+ settings_file = os.path.basename(settings_path)
+ settings_module_name = "".join(settings_file.split('.')[:-1])
+ if '.' in settings_module_name:
+ print("'.' is not an allowed character in the settings-file")
+ sys.exit(1)
+ settings_module_dir = os.path.dirname(settings_path)
+ sys.path.append(settings_module_dir)
+ os.environ[django.conf.ENVIRONMENT_VARIABLE] = '%s' % settings_module_name
+ django.setup()
+
+
+def database_exists():
+ """Detect if the database exists"""
+
+ # can't be imported in global scope as they already require
+ # the settings module during import
+ from django.db import DatabaseError
+ from django.core.exceptions import ImproperlyConfigured
+ from wger.manager.models import User
+
+ try:
+ # TODO: Use another model, the User could be deactivated
+ User.objects.count()
+ except DatabaseError:
+ return False
+ except ImproperlyConfigured:
+ print("Your settings file seems broken")
+ sys.exit(0)
+ else:
+ return True
+
+
+def start_browser(url):
+ '''
+ Start the web browser with the given URL
+ '''
+ browser = webbrowser.get()
+
+ def function():
+ time.sleep(1)
+ browser.open(url)
+
+ thread = threading.Thread(target=function)
+ thread.start()
diff --git a/wger/utils/main.py b/wger/utils/main.py
deleted file mode 100644
index 1674a7440..000000000
--- a/wger/utils/main.py
+++ /dev/null
@@ -1,145 +0,0 @@
-# This file is part of wger Workout Manager.
-#
-# wger Workout Manager is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# wger Workout Manager is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-
-import sys
-import time
-import logging
-import threading
-import webbrowser
-import os
-import ctypes
-import socket
-
-import django
-
-logger = logging.getLogger(__name__)
-
-
-def get_user_data_path(*args):
- if sys.platform == "win32":
- return win32_get_app_data_path(*args)
-
- data_home = os.environ.get(
- 'XDG_DATA_HOME', os.path.join(
- os.path.expanduser('~'), '.local', 'share'))
-
- return os.path.join(data_home, *args)
-
-
-def get_user_config_path(*args):
- if sys.platform == "win32":
- return win32_get_app_data_path(*args)
-
- config_home = os.environ.get(
- 'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
-
- return os.path.join(config_home, *args)
-
-
-def win32_get_app_data_path(*args):
- shell32 = ctypes.WinDLL("shell32.dll")
- SHGetFolderPath = shell32.SHGetFolderPathW
- SHGetFolderPath.argtypes = (
- ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_uint32,
- ctypes.c_wchar_p)
- SHGetFolderPath.restype = ctypes.c_uint32
-
- CSIDL_LOCAL_APPDATA = 0x001c
- MAX_PATH = 260
-
- buf = ctypes.create_unicode_buffer(MAX_PATH)
- res = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, buf)
- if res != 0:
- raise Exception("Could not deterime APPDATA path")
-
- return os.path.join(buf.value, *args)
-
-
-def detect_listen_opts(address, port):
- if address is None:
- try:
- address = socket.gethostbyname(socket.gethostname())
- except socket.error:
- address = "127.0.0.1"
-
- if port is None:
- # test if we can use port 80
- s = socket.socket()
- port = 80
- try:
- s.bind((address, port))
- s.listen(-1)
- except socket.error:
- port = 8000
- finally:
- s.close()
-
- return address, port
-
-
-def setup_django_environment(settings_path):
- '''
- Setup the django environment
- '''
-
- # Use default settings if the user didn't specify something else
- if settings_path is None:
- settings_path = get_user_config_path('wger', 'settings.py')
- print('*** No settings given, using {0}'.format(settings_path))
-
- # Find out file path and fine name of settings and setup django
- settings_file = os.path.basename(settings_path)
- settings_module_name = "".join(settings_file.split('.')[:-1])
- if '.' in settings_module_name:
- print("'.' is not an allowed character in the settings-file")
- sys.exit(1)
- settings_module_dir = os.path.dirname(settings_path)
- sys.path.append(settings_module_dir)
- os.environ[django.conf.ENVIRONMENT_VARIABLE] = '%s' % settings_module_name
- django.setup()
-
-
-def database_exists():
- """Detect if the database exists"""
-
- # can't be imported in global scope as they already require
- # the settings module during import
- from django.db import DatabaseError
- from django.core.exceptions import ImproperlyConfigured
- from wger.manager.models import User
-
- try:
- # TODO: Use another model, the User could be deactivated
- User.objects.count()
- except DatabaseError:
- return False
- except ImproperlyConfigured:
- print("Your settings file seems broken")
- sys.exit(0)
- else:
- return True
-
-
-def start_browser(url):
- '''
- Start the web browser with the given URL
- '''
- browser = webbrowser.get()
-
- def function():
- time.sleep(1)
- browser.open(url)
-
- thread = threading.Thread(target=function)
- thread.start()