def bootstrap_wger(settings_path=None, database_path=None, address='localhost', port=8000, browser=False): ''' Performs all steps necessary to bootstrap the application ''' # Find url to wger address, port = detect_listen_opts(address, port) if port == 80: url = "http://{0}".format(address) else: url = "http://{0}:{1}".format(address, port) # Create settings if necessary if settings_path is None: settings_path = get_user_config_path('wger', 'settings.py') if not os.path.exists(settings_path): create_settings(settings_path=settings_path, database_path=database_path, url=url) # Find the path to the settings and setup the django environment setup_django_environment(settings_path) # Create Database if necessary if not database_exists(): print('*** Database does not exist, creating one now') migrate_db(settings_path=settings_path) load_fixtures(settings_path=settings_path) create_or_reset_admin(settings_path=settings_path) # Download JS libraries with bower call_command('bower', 'install') # Start the webserver print('*** Bootstraping complete, starting application') start_wger(address=address, port=port, browser=browser, settings_path=settings_path)
def config_location(): ''' Returns the default location for the settings file and the data folder ''' print('Default locations:') 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')))
#!/usr/bin/env python import sys from django.core.management import execute_from_command_line from wger.utils.main import setup_django_environment, get_user_config_path if __name__ == "__main__": # If user passed the settings flag ignore the default wger settings if not any("--settings" in s for s in sys.argv): setup_django_environment(get_user_config_path("wger", "settings.py")) # Alternative to above # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") execute_from_command_line(sys.argv)
def create_settings(settings_path=None, database_path=None, url=None, database_type='sqlite3', key_length=50): ''' Creates a local settings file ''' if settings_path is None: settings_path = get_user_config_path('wger', 'settings.py') settings_module = os.path.dirname(settings_path) print("*** Creating settings file at {0}".format(settings_module)) if database_path is None: database_path = get_user_data_path('wger', 'database.sqlite') dbpath_value = repr(database_path) media_folder_path = repr(get_user_data_path('wger', 'media')) # Use localhost with default django port if no URL given if url is None: url = 'http://*****:*****@#$%^&*(-_=+)') settings_content = settings_content.format( dbname=dbname, dbpath=dbpath_value, dbengine=dbengine, dbuser=dbuser, dbpassword=dbpassword, dbhost=dbhost, dbport=dbport, default_key=secret_key, siteurl=url, media_folder_path=media_folder_path) if not os.path.exists(settings_module): os.makedirs(settings_module) if not os.path.exists(os.path.dirname(database_path)): os.makedirs(os.path.dirname(database_path)) with open(settings_path, 'w') as settings_file: settings_file.write(settings_content)
def create_settings(settings_path=None, database_path=None, url=None, database_type='sqlite3', key_length=50): ''' Creates a local settings file ''' if settings_path is None: settings_path = get_user_config_path('wger', 'settings.py') settings_module = os.path.dirname(settings_path) print("*** Creating settings file at {0}".format(settings_module)) if database_path is None: database_path = get_user_data_path('wger', 'database.sqlite') dbpath_value = repr(database_path) media_folder_path = repr(get_user_data_path('wger', 'media')) # Use localhost with default django port if no URL given if url is None: url = 'http://*****:*****@#$%^&*(-_=+)') settings_content = settings_content.format(dbname=dbname, dbpath=dbpath_value, dbengine=dbengine, dbuser=dbuser, dbpassword=dbpassword, dbhost=dbhost, dbport=dbport, default_key=secret_key, siteurl=url, media_folder_path=media_folder_path) if not os.path.exists(settings_module): os.makedirs(settings_module) if not os.path.exists(os.path.dirname(database_path)): os.makedirs(os.path.dirname(database_path)) with open(settings_path, 'w') as settings_file: settings_file.write(settings_content)
#!/usr/bin/env python import sys from django.core.management import execute_from_command_line from wger.utils.main import (setup_django_environment, get_user_config_path) if __name__ == "__main__": # If user passed the settings flag ignore the default wger settings if not any('--settings' in s for s in sys.argv): setup_django_environment(get_user_config_path('wger', 'settings.py')) # Alternative to above # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") execute_from_command_line(sys.argv)
#!/usr/bin/env python import sys from django.core.management import execute_from_command_line from wger.utils.main import ( setup_django_environment, get_user_config_path ) if __name__ == "__main__": setup_django_environment( get_user_config_path('wger', 'settings.py')) #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wger.workout_manager.settings") execute_from_command_line(sys.argv)