def start(args): """ Starts OpenSlides: Runs migrations and runs runserver. """ settings_dir = args.settings_dir settings_filename = args.settings_filename local_installation = is_local_installation() if settings_dir is None: if local_installation: settings_dir = get_local_settings_dir() else: settings_dir = get_default_settings_dir() # Write django settings if it does not exists. settings_path = os.path.join(settings_dir, settings_filename) if not os.path.isfile(settings_path): createsettings(args) # Set the django setting module and run migrations # A manual given environment variable will be overwritten setup_django_settings_module(settings_path, local_installation=local_installation) django.setup() from django.conf import settings if args.debug_email: settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" # Migrate database call_command("migrate") # Open the browser if not args.no_browser: open_browser(args.host, args.port) startup() # Start the built-in webserver # # Use flag --noreload to tell Django not to reload the server. # Therefor we have to set the keyword noreload to False because Django # parses this directly to the use_reloader keyword. # # Use flag --insecure to serve static files even if DEBUG is False. call_command( "runserver", f"{args.host}:{args.port}", noreload=False, # Means True, see above. insecure=True, )
def createsettings(args): """ Creates settings for OpenSlides. """ settings_dir = args.settings_dir local_installation = is_local_installation() context = {} # type: Dict[str, str] if local_installation: if settings_dir is None: settings_dir = get_local_settings_dir() context = { 'openslides_user_data_dir': repr(os.path.join(os.getcwd(), 'personal_data', 'var')), 'debug': 'True'} settings_path = write_settings(settings_dir, args.settings_filename, **context) print('Settings created at %s' % settings_path)
def createsettings(args): """ Creates settings for OpenSlides. """ settings_dir = args.settings_dir local_installation = is_local_installation() context: Dict[str, str] = {} if local_installation: if settings_dir is None: settings_dir = get_local_settings_dir() context = { "openslides_user_data_dir": repr( os.path.join(os.getcwd(), "personal_data", "var") ), "debug": "True", } settings_path = write_settings(settings_dir, args.settings_filename, **context) print(f"Settings created at {settings_path}")
def createsettings(args): """ Creates settings for OpenSlides. """ settings_dir = args.settings_dir local_installation = is_local_installation() context: Dict[str, str] = {} if local_installation: if settings_dir is None: settings_dir = get_local_settings_dir() context = { "openslides_user_data_dir": repr(os.path.join(os.getcwd(), "personal_data", "var")), "debug": "True", } settings_path = write_settings(settings_dir, args.settings_filename, **context) print(f"Settings created at {settings_path}")
def createsettings(args): """ Creates settings for OpenSlides. """ settings_dir = args.settings_dir local_installation = is_local_installation() context = {} # type: Dict[str, str] if local_installation: if settings_dir is None: settings_dir = get_local_settings_dir() context = { 'openslides_user_data_dir': repr(os.path.join(os.getcwd(), 'personal_data', 'var')), 'debug': 'True' } settings_path = write_settings(settings_dir, args.settings_filename, **context) print('Settings created at %s' % settings_path)
def test_get_local_settings_dir(self): self.assertEqual(main.get_local_settings_dir(), os.sep.join(("personal_data", "var")))
def start(args): """ Starts OpenSlides: Runs migrations and runs runserver. """ settings_dir = args.settings_dir settings_filename = args.settings_filename local_installation = is_local_installation() if settings_dir is None: if local_installation: settings_dir = get_local_settings_dir() else: settings_dir = get_default_settings_dir() # Write django settings if it does not exists. settings_path = os.path.join(settings_dir, settings_filename) if not os.path.isfile(settings_path): createsettings(args) # Set the django setting module and run migrations # A manual given environment variable will be overwritten setup_django_settings_module(settings_path, local_installation=local_installation) django.setup() from django.conf import settings if args.debug_email: settings.EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Migrate database call_command('migrate') if args.use_geiss: # Make sure Redis is used. if settings.CHANNEL_LAYERS['default']['BACKEND'] != 'asgi_redis.RedisChannelLayer': raise RuntimeError("You have to use the ASGI Redis backend in the settings to use Geiss.") # Download Geiss and collect the static files. call_command('getgeiss') call_command('collectstatic', interactive=False) # Open the browser if not args.no_browser: open_browser(args.host, args.port) # Start Geiss in its own thread subprocess.Popen([ get_geiss_path(), '--host', args.host, '--port', args.port, '--static', '/static/:{}'.format(settings.STATIC_ROOT), '--static', '/media/:{}'.format(settings.MEDIA_ROOT), ]) # Start one worker in this thread. There can be only one worker as # long as SQLite3 is used. call_command('runworker') else: # Open the browser if not args.no_browser: open_browser(args.host, args.port) # Start Daphne and one worker # # Use flag --noreload to tell Django not to reload the server. # Therefor we have to set the keyword noreload to False because Django # parses this directly to the use_reloader keyword. # # Use flag --insecure to serve static files even if DEBUG is False. # # Use flag --nothreading to tell Django Channels to run in single # thread mode with one worker only. Therefor we have to set the keyword # nothreading to False because Django parses this directly to # use_threading keyword. call_command( 'runserver', '{}:{}'.format(args.host, args.port), noreload=False, # Means True, see above. insecure=True, nothreading=False, # Means True, see above. )
def test_get_local_settings_dir(self): self.assertEqual(main.get_local_settings_dir(), os.sep.join(('personal_data', 'var')))
def test_get_local_settings_dir(self): self.assertEqual( main.get_local_settings_dir(), os.sep.join(("personal_data", "var")) )
def start(args): """ Starts OpenSlides: Runs migrations and runs runserver. """ settings_dir = args.settings_dir settings_filename = args.settings_filename local_installation = is_local_installation() if settings_dir is None: if local_installation: settings_dir = get_local_settings_dir() else: settings_dir = get_default_settings_dir() # Write django settings if it does not exists. settings_path = os.path.join(settings_dir, settings_filename) if not os.path.isfile(settings_path): createsettings(args) # Set the django setting module and run migrations # A manual given environment variable will be overwritten setup_django_settings_module(settings_path, local_installation=local_installation) django.setup() from django.conf import settings if args.debug_email: settings.EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Migrate database call_command('migrate') if args.use_geiss: # Make sure Redis is used. if settings.CHANNEL_LAYERS['default'][ 'BACKEND'] != 'asgi_redis.RedisChannelLayer': raise RuntimeError( "You have to use the ASGI Redis backend in the settings to use Geiss." ) # Download Geiss and collect the static files. call_command('getgeiss') call_command('collectstatic', interactive=False) # Open the browser if not args.no_browser: open_browser(args.host, args.port) # Start Geiss in its own thread subprocess.Popen([ get_geiss_path(), '--host', args.host, '--port', args.port, '--static', '/static/:{}'.format(settings.STATIC_ROOT), '--static', '/media/:{}'.format(settings.MEDIA_ROOT), ]) # Start one worker in this thread. There can be only one worker as # long as SQLite3 is used. call_command('runworker') else: # Open the browser if not args.no_browser: open_browser(args.host, args.port) # Start Daphne and one worker # # Use flag --noreload to tell Django not to reload the server. # Therefor we have to set the keyword noreload to False because Django # parses this directly to the use_reloader keyword. # # Use flag --insecure to serve static files even if DEBUG is False. # # Use flag --nothreading to tell Django Channels to run in single # thread mode with one worker only. Therefor we have to set the keyword # nothreading to False because Django parses this directly to # use_threading keyword. call_command( 'runserver', '{}:{}'.format(args.host, args.port), noreload=False, # Means True, see above. insecure=True, nothreading=False, # Means True, see above. )