コード例 #1
0
def main():
    """
    Main entrance to OpenSlides.
    """
    parser = get_parser()
    try:
        known_args, unknown_args = parser.parse_known_args()
    except UnknownCommand:
        unknown_command = True
    else:
        unknown_command = False

    if unknown_command:
        # Run a command, that is defined by the django management api
        local_installation = is_local_installation()
        setup_django_settings_module(local_installation=local_installation)
        execute_from_command_line(sys.argv)
    else:
        # Check for unknown_args.
        if unknown_args:
            joined_unknown_args = " ".join(unknown_args)
            parser.error(f"Unknown arguments {joined_unknown_args}")

        # Save arguments, if one wants to access them later.
        arguments.set_arguments(known_args)

        # Run a command that is defined here
        # These are commands that can not rely on an existing settings
        known_args.callback(known_args)
コード例 #2
0
ファイル: __main__.py プロジェクト: chyka-dev/OpenSlides
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    development = is_development()

    if settings_path is None:
        if development:
            settings_path = get_development_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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, development=development)

    execute_from_command_line(['manage.py', 'migrate'])

    if not args.no_browser:
        start_browser('http://localhost:8000')

    # Start the webserver
    # Tell django not to reload. OpenSlides uses the reload method from tornado
    execute_from_command_line(['manage.py', 'runserver', '0.0.0.0:8000', '--noreload'])
コード例 #3
0
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    development = is_development()

    if settings_path is None:
        if development:
            settings_path = get_development_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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, development=development)

    execute_from_command_line(['manage.py', 'migrate'])

    if not args.no_browser:
        start_browser('http://0.0.0.0:8000')

    # Start the webserver
    execute_from_command_line(['manage.py', 'runserver', '0.0.0.0:8000'])
コード例 #4
0
ファイル: __main__.py プロジェクト: Intevation/OpenSlides
def main():
    """
    Main entrance to OpenSlides.
    """
    parser = get_parser()
    try:
        known_args, unknown_args = parser.parse_known_args()
    except UnknownCommand:
        unknown_command = True
    else:
        unknown_command = False

    if unknown_command:
        # Run a command, that is defined by the django management api
        local_installation = is_local_installation()
        setup_django_settings_module(local_installation=local_installation)
        execute_from_command_line(sys.argv)
    else:
        # Check for unknown_args.
        if unknown_args:
            parser.error('Unknown arguments {}'.format(' '.join(unknown_args)))

        # Save arguments, if one wants to access them later.
        arguments.set_arguments(known_args)

        # Run a command that is defined here
        # These are commands that can not rely on an existing settings
        known_args.callback(known_args)
コード例 #5
0
ファイル: __main__.py プロジェクト: Ramoonus/OpenSlides
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    local_installation = is_local_installation()

    if settings_path is None:
        if local_installation:
            settings_path = get_local_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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)

    execute_from_command_line(['manage.py', 'migrate'])

    # Open the browser
    if not args.no_browser:
        if args.host == '0.0.0.0':
            # Windows does not support 0.0.0.0, so use 'localhost' instead
            start_browser('http://localhost:%s' % args.port)
        else:
            start_browser('http://%s:%s' % (args.host, args.port))

    # Start the webserver
    # Tell django not to reload. OpenSlides uses the reload method from tornado
    execute_from_command_line(['manage.py', 'runserver', '%s:%s' % (args.host, args.port), '--noreload'])
コード例 #6
0
ファイル: test_main.py プロジェクト: td00/OpenSlides
    def test_setup_django_settings_module(self):
        main.setup_django_settings_module(
            "test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py")

        self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"],
                         "test_path_bngjdhc756dzwncshdfnx")
        self.assertEqual(sys.path[0],
                         os.path.abspath("test_dir_dhvnghfjdh456fzheg2f"))
コード例 #7
0
def main():
    sys.path.insert(
        0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    setup_django_settings_module(
        os.path.join(os.path.dirname(__file__), 'settings.py'))
    sys.argv.insert(1, 'django')
    sys.argv.insert(2, 'test')
    return openslides_main()
コード例 #8
0
ファイル: test_main.py プロジェクト: CatoTH/OpenSlides
    def test_setup_django_settings_module(self):
        main.setup_django_settings_module(
            "test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py"
        )

        self.assertEqual(
            os.environ["DJANGO_SETTINGS_MODULE"], "test_path_bngjdhc756dzwncshdfnx"
        )
        self.assertEqual(sys.path[0], os.path.abspath("test_dir_dhvnghfjdh456fzheg2f"))
コード例 #9
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,
    )
コード例 #10
0
ファイル: __main__.py プロジェクト: CatoTH/OpenSlides
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,
    )
コード例 #11
0
ファイル: __main__.py プロジェクト: flanagan/OpenSlides
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    local_installation = is_local_installation()

    if settings_path is None:
        if local_installation:
            settings_path = get_local_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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)

    execute_from_command_line(['manage.py', 'migrate'])

    # Open the browser
    if not args.no_browser:
        if args.host == '0.0.0.0':
            # Windows does not support 0.0.0.0, so use 'localhost' instead
            start_browser('http://localhost:%s' % args.port)
        else:
            start_browser('http://%s:%s' % (args.host, args.port))

    # Start the webserver
    # Use flag --noreload to tell Django not to reload the server.
    # 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.
    execute_from_command_line([
        'manage.py',
        'runserver',
        '{}:{}'.format(args.host, args.port),
        '--noreload',
        '--insecure',
        '--nothreading',
    ])
コード例 #12
0
def main():
    """
    Main entrance to OpenSlides.
    """
    parser = get_parser()
    try:
        known_args, unknown_args = parser.parse_known_args()
    except UnknownCommand:
        unknown_command = True
    else:
        unknown_command = False

    if unknown_command:
        # Run a command, that is defined by the django management api
        local_installation = is_local_installation()
        setup_django_settings_module(local_installation=local_installation)
        execute_from_command_line(sys.argv)
    else:
        # Run a command that is defined here
        # These are commands that can not rely on an existing settings
        known_args.callback(known_args)
コード例 #13
0
ファイル: __main__.py プロジェクト: flanagan/OpenSlides
def main():
    """
    Main entrance to OpenSlides.
    """
    parser = get_parser()
    try:
        known_args, unknown_args = parser.parse_known_args()
    except UnknownCommand:
        unknown_command = True
    else:
        unknown_command = False

    if unknown_command:
        # Run a command, that is defined by the django management api
        local_installation = is_local_installation()
        setup_django_settings_module(local_installation=local_installation)
        execute_from_command_line(sys.argv)
    else:
        # Run a command that is defined here
        # These are commands that can not rely on an existing settings
        known_args.callback(known_args)
コード例 #14
0
ファイル: __main__.py プロジェクト: lostwarrior404/OpenSlides
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    local_installation = is_local_installation()

    if settings_path is None:
        if local_installation:
            settings_path = get_local_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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)

    execute_from_command_line(['manage.py', 'migrate'])

    # Open the browser
    if not args.no_browser:
        if args.host == '0.0.0.0':
            # Windows does not support 0.0.0.0, so use 'localhost' instead
            start_browser('http://localhost:%s' % args.port)
        else:
            start_browser('http://%s:%s' % (args.host, args.port))

    # Start the webserver
    # Use flag --noreload to tell Django not to reload the server.
    # 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.
    execute_from_command_line([
        'manage.py', 'runserver', '{}:{}'.format(args.host, args.port),
        '--noreload', '--insecure', '--nothreading'
    ])
コード例 #15
0
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    local_installation = is_local_installation()

    if settings_path is None:
        if local_installation:
            settings_path = get_local_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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)

    execute_from_command_line(['manage.py', 'migrate'])

    # Open the browser
    if not args.no_browser:
        if args.host == '0.0.0.0':
            # Windows does not support 0.0.0.0, so use 'localhost' instead
            start_browser('http://localhost:%s' % args.port)
        else:
            start_browser('http://%s:%s' % (args.host, args.port))

    # Start the webserver
    # Tell django not to reload. OpenSlides uses the reload method from tornado
    execute_from_command_line([
        'manage.py', 'runserver',
        '%s:%s' % (args.host, args.port), '--noreload'
    ])
コード例 #16
0
def main():
    """
    Main entrance to OpenSlides.
    """
    # Parse all command line args.
    args = parse_args()

    # Setup settings path: Take it either from command line or get default path
    if hasattr(args, 'settings') and args.settings:
        settings = args.settings
        setup_django_settings_module(settings)
    else:
        if ENVIRONMENT_VARIABLE not in os.environ:
            openslides_type = detect_openslides_type()
            settings = get_default_settings_path(openslides_type)
            setup_django_settings_module(settings)
        else:
            # The environment variable is set, so we do not need to process
            # anything more here.
            settings = None

    # Process the subcommand's callback
    return args.callback(settings, args)
コード例 #17
0
ファイル: __main__.py プロジェクト: fesp21/OpenSlides
def main():
    """
    Main entrance to OpenSlides.
    """
    # Parse all command line args.
    args = parse_args()

    # Setup settings path: Take it either from command line or get default path
    if hasattr(args, 'settings') and args.settings:
        settings = args.settings
        setup_django_settings_module(settings)
    else:
        if ENVIRONMENT_VARIABLE not in os.environ:
            openslides_type = detect_openslides_type()
            settings = get_default_settings_path(openslides_type)
            setup_django_settings_module(settings)
        else:
            # The environment variable is set, so we do not need to process
            # anything more here.
            settings = None

    # Process the subcommand's callback
    return args.callback(settings, args)
コード例 #18
0
ファイル: test_main.py プロジェクト: DerPate/OpenSlides
 def test_setup_django_settings_module(self):
     setup_django_settings_module('test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py')
     self.assertEqual(os.environ['DJANGO_SETTINGS_MODULE'], 'test_path_bngjdhc756dzwncshdfnx')
     self.assertEqual(sys.path[0], 'test_dir_dhvnghfjdh456fzheg2f')
コード例 #19
0
ファイル: test_main.py プロジェクト: DerPate/OpenSlides
 def test_setup_django_settings_module(self):
     setup_django_settings_module(
         'test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py')
     self.assertEqual(os.environ['DJANGO_SETTINGS_MODULE'],
                      'test_path_bngjdhc756dzwncshdfnx')
     self.assertEqual(sys.path[0], 'test_dir_dhvnghfjdh456fzheg2f')
コード例 #20
0
ファイル: __main__.py プロジェクト: Intevation/OpenSlides
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.
        )
コード例 #21
0
ファイル: __main__.py プロジェクト: MohamedFarhat5/OpenSlides
def start(args):
    """
    Starts OpenSlides: Runs migrations and runs runserver.
    """
    settings_path = args.settings_path
    local_installation = is_local_installation()

    if settings_path is None:
        if local_installation:
            settings_path = get_local_settings_path()
        else:
            settings_path = get_default_settings_path()

    # Write settings if it does not exists.
    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

    # 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.
        )
コード例 #22
0
def main():
    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    setup_django_settings_module(os.path.join(os.path.dirname(__file__), 'settings.py'))
    sys.argv.insert(1, 'django')
    sys.argv.insert(2, 'test')
    return openslides_main()