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'])
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'])
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'])
def add_general_arguments(subcommand, arguments): """ Adds the named arguments to the subcommand. """ general_arguments = {} openslides_type = detect_openslides_type() general_arguments['settings'] = ( ('-s', '--settings'), dict(help="Path to settings file. The file must be a python module. " "If if isn't provided, the %s environment variable will be " "used. If the environment variable isn't provided too, a " "default path according to the OpenSlides type will be " "used. At the moment it is %s" % (ENVIRONMENT_VARIABLE, get_default_settings_path(openslides_type)))) general_arguments['user_data_path'] = ( ('-d', '--user-data-path'), dict(help= 'Path to the directory for user specific data files like SQLite3 ' 'database, uploaded media and search index. It is only used, ' 'when a new settings file is created. The given path is only ' 'written into the new settings file. Default according to the ' 'OpenSlides type is at the moment %s' % get_default_user_data_path(openslides_type))) general_arguments['language'] = ( ('-l', '--language'), dict( help='Language code. All customizable strings will be translated ' 'during database setup. See https://www.transifex.com/projects/p/openslides/ ' 'for supported languages.')) general_arguments['address'] = ( ( '-a', '--address', ), dict(default='0.0.0.0', help='IP address to listen on. Default is %(default)s.')) general_arguments['port'] = ( ('-p', '--port'), dict( type=int, default=80, help= 'Port to listen on. Default as admin or root is %(default)d, else 8000.' )) for argument in arguments: try: args, kwargs = general_arguments[argument] except KeyError: raise TypeError( 'The argument %s is not a valid general argument.' % argument) subcommand.add_argument(*args, **kwargs)
def add_general_arguments(subcommand, arguments): """ Adds the named arguments to the subcommand. """ general_arguments = {} openslides_type = detect_openslides_type() general_arguments["settings"] = ( ("-s", "--settings"), dict( help="Path to settings file. If this isn't provided, the " "%s environment variable will be used. " "If this isn't provided too, a default path according to the " "OpenSlides type will be used. At the moment it is %s" % (ENVIRONMENT_VARIABLE, get_default_settings_path(openslides_type)) ), ) general_arguments["user_data_path"] = ( ("-d", "--user-data-path"), dict( help="Path to the directory for user specific data files like SQLite3 " "database, uploaded media and search index. This is only used, " "when a new settings file is created. The given path is only " "written into the new settings file. Default according to the " "OpenSlides is at the moment %s" % get_default_user_data_path(openslides_type) ), ) general_arguments["language"] = ( ("-l", "--language"), dict( help="Language code. All customizable strings will be translated " "during database setup. See https://www.transifex.com/projects/p/openslides/ " "for supported languages." ), ) general_arguments["address"] = ( ("-a", "--address"), dict(default="0.0.0.0", help="IP address to listen on. Default is %(default)s."), ) general_arguments["port"] = ( ("-p", "--port"), dict(type=int, default=80, help="Port to listen on. Default as admin or root is %(default)d, else 8000."), ) for argument in arguments: try: args, kwargs = general_arguments[argument] except KeyError: raise TypeError("The argument %s is not a valid general argument." % argument) subcommand.add_argument(*args, **kwargs)
def add_general_arguments(subcommand, arguments): """ Adds the named arguments to the subcommand. """ general_arguments = {} openslides_type = detect_openslides_type() general_arguments['settings'] = ( ('-s', '--settings'), dict(help="Path to settings file. The file must be a python module. " "If if isn't provided, the %s environment variable will be " "used. If the environment variable isn't provided too, a " "default path according to the OpenSlides type will be " "used. At the moment it is %s" % ( ENVIRONMENT_VARIABLE, get_default_settings_path(openslides_type)))) general_arguments['user_data_path'] = ( ('-d', '--user-data-path'), dict(help='Path to the directory for user specific data files like SQLite3 ' 'database, uploaded media and search index. It is only used, ' 'when a new settings file is created. The given path is only ' 'written into the new settings file. Default according to the ' 'OpenSlides type is at the moment %s' % get_default_user_data_path(openslides_type))) general_arguments['language'] = ( ('-l', '--language'), dict(help='Language code. All customizable strings will be translated ' 'during database setup. See https://www.transifex.com/projects/p/openslides/ ' 'for supported languages.')) general_arguments['address'] = ( ('-a', '--address',), dict(default='0.0.0.0', help='IP address to listen on. Default is %(default)s.')) general_arguments['port'] = ( ('-p', '--port'), dict(type=int, default=80, help='Port to listen on. Default as admin or root is %(default)d, else 8000.')) for argument in arguments: try: args, kwargs = general_arguments[argument] except KeyError: raise TypeError('The argument %s is not a valid general argument.' % argument) subcommand.add_argument(*args, **kwargs)
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', ])
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' ])
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' ])
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)
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)
def add_general_arguments(subcommand, arguments): """ Adds the named arguments to the subcommand. """ general_arguments = {} openslides_type = detect_openslides_type() general_arguments['settings'] = ( ('-s', '--settings'), dict(help="Path to settings file. If this isn't provided, the " "%s environment variable will be used. " "If this isn't provided too, a default path according to the " "OpenSlides type will be used. At the moment it is %s" % ( ENVIRONMENT_VARIABLE, get_default_settings_path(openslides_type)))) general_arguments['user_data_path'] = ( ('-d', '--user-data-path'), dict(help='Path to the directory for user specific data files like SQLite3 ' 'database, uploaded media and search index. This is only used, ' 'when a new settings file is created. The given path is only ' 'written into the new settings file. Default according to the ' 'OpenSlides is at the moment %s' % get_default_user_data_path(openslides_type))) general_arguments['address'] = ( ('-a', '--address',), dict(default='0.0.0.0', help='IP address to listen on. Default is %(default)s.')) general_arguments['port'] = ( ('-p', '--port'), dict(type=int, default=80, help='Port to listen on. Default as admin or root is %(default)d, else 8000.')) for argument in arguments: try: args, kwargs = general_arguments[argument] except KeyError: raise TypeError('The argument %s is not a valid general argument.' % argument) subcommand.add_argument(*args, **kwargs)
def test_get_default_settings_path(self): self.assertIn( os.path.join('.config', 'openslides', 'settings.py'), get_default_settings_path(UNIX_VERSION))
def test_get_default_settings_path(self): self.assertIn(os.path.join('.config', 'openslides', 'settings.py'), get_default_settings_path(UNIX_VERSION))
def test_get_default_settings_path_portable(self, mock_portable): mock_portable.return_value = 'portable' self.assertEqual(main.get_default_settings_path(main.WINDOWS_PORTABLE_VERSION), 'portable/openslides/settings.py')
def test_get_default_settings_path_win(self, mock_win): mock_win.return_value = 'win32' self.assertEqual(main.get_default_settings_path(main.WINDOWS_VERSION), 'win32/openslides/settings.py')
def test_get_default_settings_path_unix(self, mock_expanduser, mock_detect): mock_expanduser.return_value = '/home/test/.config' self.assertEqual(main.get_default_settings_path(main.UNIX_VERSION), '/home/test/.config/openslides/settings.py')
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. )