diff --git a/extras/openslides_gui/gui.py b/extras/openslides_gui/gui.py old mode 100644 new mode 100755 index 296ee2a8f..427c105c7 --- a/extras/openslides_gui/gui.py +++ b/extras/openslides_gui/gui.py @@ -21,10 +21,10 @@ import openslides from openslides.utils.main import ( detect_openslides_type, filesystem2unicode, + unicode2filesystem, get_default_user_data_path, get_port, - get_win32_portable_path, - PortableDirNotWritable + PortableDirNotWritable, ) @@ -97,11 +97,7 @@ class RunCommandControl(wx.Panel): # XXX: subprocess on windows only handles byte strings # with python3 this will hopefully no longer be the case - fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() - cmd = [ - x.encode(fs_encoding) if isinstance(x, unicode) else x - for x in cmd - ] + cmd = [unicode2filesystem(x) for x in cmd] creationflags = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0) self.child_process = subprocess.Popen( diff --git a/openslides/global_settings.py b/openslides/global_settings.py index e72824234..6de07d99b 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -5,7 +5,7 @@ import os from django.utils.translation import ugettext_lazy from openslides.utils.main import filesystem2unicode -from openslides.utils.plugins import get_plugins_from_entry_points +from openslides.utils.plugins import collect_plugins SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) @@ -129,4 +129,4 @@ HAYSTACK_CONNECTIONS = { HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' # Adds all automaticly collected plugins -INSTALLED_PLUGINS = get_plugins_from_entry_points() +INSTALLED_PLUGINS = collect_plugins() diff --git a/openslides/utils/plugins.py b/openslides/utils/plugins.py old mode 100644 new mode 100755 index d494de0f8..56efa564c --- a/openslides/utils/plugins.py +++ b/openslides/utils/plugins.py @@ -1,8 +1,18 @@ # -*- coding: utf-8 -*- +import pkgutil +import os +import sys + from django.utils.importlib import import_module from pkg_resources import iter_entry_points +from openslides.utils.main import ( + detect_openslides_type, + WINDOWS_PORTABLE_VERSION, + get_win32_portable_user_data_path, +) + plugins = {} @@ -15,6 +25,30 @@ def get_plugins_from_entry_points(): return tuple(entry_point.module_name for entry_point in iter_entry_points('openslides_plugins')) +def get_plugins_from_path(path): + """ + Collects all modules/packages in the given `path` + and returns a tuple of their names + """ + importer = pkgutil.get_importer(path) + return tuple(x[0] for x in importer.iter_modules()) + + +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 + + def get_plugin(plugin): """ Returns the imported module. The plugin argument must be a python dotted