Exemplo n.º 1
0
 def test_detect_openslides_type_win_portable(self, mock_sys, mock_os):
     """
     Tests the return value on a windows portable system.
     """
     mock_sys.platform = 'win32'
     mock_os.return_value = 'openslides.exe'
     self.assertEqual(main.detect_openslides_type(), main.WINDOWS_PORTABLE_VERSION)
Exemplo n.º 2
0
 def test_detect_openslides_type_win(self, mock_sys, mock_os):
     """
     Tests the return value on a windows system.
     """
     mock_sys.platform = 'win32'
     mock_os.return_value = 'python'
     self.assertEqual(main.detect_openslides_type(), main.WINDOWS_VERSION)
Exemplo n.º 3
0
    def initialize_gui(self):
        if self.gui_initialized:
            return True

        # Set path for gui settings to default user data according to the
        # OpenSlides type. This does not depend on any argument the user might
        # type in.
        openslides_type = detect_openslides_type()
        try:
            default_user_data_path = get_default_user_data_dir(openslides_type)
        except PortableDirNotWritable:
            wx.MessageBox(
                _("The portable directory is not writable. Please copy the "
                  "openslides portable to a writeable location and start it "
                  "again from there"),
                _("Error: Portable directory not writable"),
                wx.OK | wx.ICON_ERROR)
            return False

        self.gui_settings_path = os.path.join(default_user_data_path,
                                              'openslides',
                                              'gui_settings.json')
        self.load_gui_settings()
        self.apply_backup_settings()

        self.gui_initialized = True
        return True
Exemplo n.º 4
0
    def initialize_gui(self):
        if self.gui_initialized:
            return True

        # Set path for gui settings to default user data according to the
        # OpenSlides type. This does not depend on any argument the user might
        # type in.
        openslides_type = detect_openslides_type()
        try:
            default_user_data_path = get_default_user_data_path(openslides_type)
        except PortableDirNotWritable:
            wx.MessageBox(
                _("The portable directory is not writable. Please copy the "
                "openslides portable to a writeable location and start it "
                "again from there"),
                _("Error: Portable directory not writable"),
                wx.OK | wx.ICON_ERROR)
            return False

        self.gui_settings_path = os.path.join(
            default_user_data_path, 'openslides', 'gui_settings.json')
        self.load_gui_settings()
        self.apply_backup_settings()

        self.gui_initialized = True
        return True
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def collect_plugins():
    """
    Collect all plugins that can be automatically discovered.
    """
    plugins = get_plugins_from_entry_points()
    # add all modules in plugins/ dir of portable automatically
    if detect_openslides_type() == WINDOWS_PORTABLE_VERSION:
        plugins_path = os.path.join(get_win32_portable_user_data_path(),
                                    "plugins")
        if plugins_path not in sys.path:
            sys.path.append(plugins_path)
        plugins += get_plugins_from_path(plugins_path)
    return plugins
Exemplo n.º 7
0
def collect_plugins():
    """
    Collect all plugins that can be automatically discovered.
    """
    plugins = get_plugins_from_entry_points()
    # add all modules in plugins/ dir of portable automatically
    if detect_openslides_type() == WINDOWS_PORTABLE_VERSION:
        plugins_path = os.path.join(
            get_win32_portable_user_data_path(), "plugins")
        if plugins_path not in sys.path:
            sys.path.append(plugins_path)
        plugins += get_plugins_from_path(plugins_path)
    return plugins
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
def collect_plugins() -> Tuple[str, ...]:
    """
    Collect all plugins that can be automatically discovered.
    """
    # Collect plugins from entry points.
    collected_plugins = collect_plugins_from_entry_points()

    # Collect plugins in plugins/ directory of portable.
    if detect_openslides_type() == WINDOWS_PORTABLE_VERSION:
        plugins_dir = os.path.join(get_win32_portable_user_data_dir(), "plugins")
        if plugins_dir not in sys.path:
            sys.path.append(plugins_dir)
        collected_plugins += collect_plugins_from_dir(plugins_dir)

    return collected_plugins
Exemplo n.º 10
0
def collect_plugins() -> Tuple[str, ...]:
    """
    Collect all plugins that can be automatically discovered.
    """
    # Collect plugins from entry points.
    collected_plugins = collect_plugins_from_entry_points()

    # Collect plugins in plugins/ directory of portable.
    if detect_openslides_type() == WINDOWS_PORTABLE_VERSION:
        plugins_path = os.path.join(
            get_win32_portable_user_data_path(), 'plugins')
        if plugins_path not in sys.path:
            sys.path.append(plugins_path)
        collected_plugins += collect_plugins_from_path(plugins_path)

    return collected_plugins
Exemplo n.º 11
0
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
 def test_detect_openslides_type_unix(self, mock_sys):
     """
     Tests the return value on a unix system.
     """
     mock_sys.platform = 'linux'
     self.assertEqual(main.detect_openslides_type(), main.UNIX_VERSION)