Example #1
0
 def test_get_default_settings_dir_unix(self, mock_expanduser, mock_detect):
     os.environ.pop("XDG_CONFIG_HOME", None)
     mock_expanduser.return_value = "/home/test/.config"
     self.assertEqual(
         main.get_default_settings_dir(main.UNIX_VERSION),
         "/home/test/.config/openslides",
     )
Example #2
0
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,
    )
Example #3
0
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,
    )
Example #4
0
 def test_get_default_settings_dir_portable(self, mock_portable):
     mock_portable.return_value = "portable"
     self.assertEqual(
         main.get_default_settings_dir(main.WINDOWS_PORTABLE_VERSION),
         "portable/openslides",
     )
Example #5
0
 def test_get_default_settings_dir_win(self, mock_win):
     mock_win.return_value = "win32"
     self.assertEqual(main.get_default_settings_dir(main.WINDOWS_VERSION),
                      "win32/openslides")
Example #6
0
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.
        )
Example #7
0
 def test_get_default_settings_dir_unix(self, mock_expanduser, mock_detect):
     mock_expanduser.return_value = "/home/test/.config"
     self.assertEqual(
         main.get_default_settings_dir(main.UNIX_VERSION),
         "/home/test/.config/openslides",
     )
Example #8
0
 def test_get_default_settings_dir_portable(self, mock_portable):
     mock_portable.return_value = 'portable'
     self.assertEqual(main.get_default_settings_dir(main.WINDOWS_PORTABLE_VERSION),
                      'portable/openslides')
Example #9
0
 def test_get_default_settings_dir_win(self, mock_win):
     mock_win.return_value = 'win32'
     self.assertEqual(main.get_default_settings_dir(main.WINDOWS_VERSION),
                      'win32/openslides')
Example #10
0
 def test_get_default_settings_dir_unix(self, mock_expanduser, mock_detect):
     mock_expanduser.return_value = '/home/test/.config'
     self.assertEqual(main.get_default_settings_dir(main.UNIX_VERSION),
                      '/home/test/.config/openslides')
Example #11
0
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.
        )