Skip to content
Snippets Groups Projects
Commit ad5f59ba authored by Philipp Hörist's avatar Philipp Hörist
Browse files

configpaths: Add get_plugin_dirs() method

This helps with mypy because otherwise get() has multiple return types

This reduces our usage of cast()
parent 5db0178a
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,6 @@ from typing import List ...@@ -24,7 +24,6 @@ from typing import List
from typing import Generator from typing import Generator
from typing import Optional # pylint: disable=unused-import from typing import Optional # pylint: disable=unused-import
from typing import Tuple from typing import Tuple
from typing import Union
import os import os
import sys import sys
...@@ -37,16 +36,18 @@ from gajim.common.const import PathType, PathLocation ...@@ -37,16 +36,18 @@ from gajim.common.const import PathType, PathLocation
from gajim.common.types import PathTuple from gajim.common.types import PathTuple
def get(key: str) -> Union[str, List[str]]: def get(key: str) -> str:
if key == 'PLUGINS_DIRS':
if gajim.IS_FLATPAK:
return ['/app/plugins',
_paths['PLUGINS_BASE']]
return [_paths['PLUGINS_BASE'],
_paths['PLUGINS_USER']]
return _paths[key] return _paths[key]
def get_plugin_dirs() -> List[str]:
if gajim.IS_FLATPAK:
return ['/app/plugins',
_paths['PLUGINS_BASE']]
return [_paths['PLUGINS_BASE'],
_paths['PLUGINS_USER']]
def get_paths(type_: PathType) -> Generator[str, None, None]: def get_paths(type_: PathType) -> Generator[str, None, None]:
for key, value in _paths.items(): for key, value in _paths.items():
path_type = value[2] path_type = value[2]
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>. # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from typing import cast
import sys import sys
import os import os
import traceback import traceback
...@@ -42,7 +40,7 @@ if __name__ == '__main__': ...@@ -42,7 +40,7 @@ if __name__ == '__main__':
glade_file = os.path.join('data', 'gui', 'exception_dialog.ui') glade_file = os.path.join('data', 'gui', 'exception_dialog.ui')
else: else:
from gajim.common import configpaths from gajim.common import configpaths
gui_path = cast(str, configpaths.get('GUI')) gui_path = configpaths.get('GUI')
glade_file = os.path.join(gui_path, 'exception_dialog.ui') glade_file = os.path.join(gui_path, 'exception_dialog.ui')
......
...@@ -107,7 +107,7 @@ class PluginManager(metaclass=Singleton): ...@@ -107,7 +107,7 @@ class PluginManager(metaclass=Singleton):
Registered names with instances of encryption Plugins. Registered names with instances of encryption Plugins.
''' '''
for path in reversed(configpaths.get('PLUGINS_DIRS')): for path in reversed(configpaths.get_plugin_dirs()):
pc = PluginManager.scan_dir_for_plugins(path) pc = PluginManager.scan_dir_for_plugins(path)
self.add_plugins(pc) self.add_plugins(pc)
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>. # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from typing import cast
import os import os
import locale import locale
import gettext import gettext
...@@ -23,7 +21,7 @@ import gettext ...@@ -23,7 +21,7 @@ import gettext
from gajim.common import configpaths from gajim.common import configpaths
APP = 'gajim_plugins' APP = 'gajim_plugins'
plugin_user_dir = cast(str, configpaths.get('PLUGINS_USER')) plugin_user_dir = configpaths.get('PLUGINS_USER')
plugins_locale_dir = os.path.join(plugin_user_dir, 'locale') plugins_locale_dir = os.path.join(plugin_user_dir, 'locale')
if os.name != 'nt': if os.name != 'nt':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment