From 105427b8fdf6af213e73aacca48cda7ada7fd5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Wed, 25 Apr 2018 20:49:37 +0200 Subject: [PATCH] Use consistent way to get paths This lets us now import the app module without setting paths --- gajim/common/app.py | 15 ------ gajim/common/configpaths.py | 7 +++ gajim/common/connection.py | 2 +- gajim/common/connection_handlers.py | 5 +- gajim/common/connection_handlers_events.py | 4 +- gajim/common/helpers.py | 54 +++++++++++----------- gajim/common/jingle_content.py | 5 +- gajim/common/jingle_xtls.py | 15 +++--- gajim/config.py | 24 ++++++---- gajim/gtkgui_helpers.py | 4 +- gajim/gui_interface.py | 23 +++++---- gajim/history_manager.py | 7 +-- gajim/plugins/gajimplugin.py | 4 +- gajim/plugins/gui.py | 5 +- gajim/plugins/pluginmanager.py | 7 +-- gajim/plugins/plugins_i18n.py | 3 +- gajim/vcard.py | 3 +- test/lib/__init__.py | 2 +- test/test_pluginmanager.py | 3 +- 19 files changed, 99 insertions(+), 93 deletions(-) diff --git a/gajim/common/app.py b/gajim/common/app.py index 69938fb65..6a39c1a8e 100644 --- a/gajim/common/app.py +++ b/gajim/common/app.py @@ -31,7 +31,6 @@ import os import sys import logging -import locale import uuid from distutils.version import LooseVersion as V from collections import namedtuple @@ -63,20 +62,6 @@ logger = None # some plugins use that gajimpaths = configpaths.gajimpaths -AVATAR_PATH = configpaths.get('AVATAR') -MY_EMOTS_PATH = configpaths.get('MY_EMOTS') -MY_ICONSETS_PATH = configpaths.get('MY_ICONSETS') -MY_MOOD_ICONSETS_PATH = configpaths.get('MY_MOOD_ICONSETS') -MY_ACTIVITY_ICONSETS_PATH = configpaths.get('MY_ACTIVITY_ICONSETS') -MY_CACERTS = configpaths.get('MY_CACERTS') -MY_PEER_CERTS_PATH = configpaths.get('MY_PEER_CERTS') -DATA_DIR = configpaths.get('DATA') -ICONS_DIR = configpaths.get('ICONS') -HOME_DIR = configpaths.get('HOME') -PLUGINS_DIRS = [configpaths.get('PLUGINS_BASE'), - configpaths.get('PLUGINS_USER')] -PLUGINS_CONFIG_DIR = configpaths.get('PLUGINS_CONFIG_DIR') -MY_CERT_DIR = configpaths.get('MY_CERT') RecentGroupchat = namedtuple('RecentGroupchat', ['room', 'server', 'nickname']) diff --git a/gajim/common/configpaths.py b/gajim/common/configpaths.py index 6613f9b90..1a1e601de 100644 --- a/gajim/common/configpaths.py +++ b/gajim/common/configpaths.py @@ -32,6 +32,9 @@ from gajim.common.const import PathType, PathLocation def get(key): + if key == 'PLUGINS_DIRS': + return [_paths['PLUGINS_BASE'], + _paths['PLUGINS_USER']] return _paths[key] @@ -43,6 +46,10 @@ def get_paths(type_): yield _paths[key] +def override_path(*args, **kwargs): + _paths._add(*args, **kwargs) + + def set_separation(active: bool): _paths.profile_separation = active diff --git a/gajim/common/connection.py b/gajim/common/connection.py index 926da1e6b..b6378e4ca 100644 --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -1217,7 +1217,7 @@ class Connection(CommonConnection, ConnectionHandlers): cacerts = '' if os.name == 'nt': cacerts = certifi.where() - mycerts = common.app.MY_CACERTS + mycerts = common.configpaths.get('MY_CACERTS') tls_version = app.config.get_per('accounts', self.name, 'tls_version') cipher_list = app.config.get_per('accounts', self.name, 'cipher_list') diff --git a/gajim/common/connection_handlers.py b/gajim/common/connection_handlers.py index b475ce1e1..883b6aa61 100644 --- a/gajim/common/connection_handlers.py +++ b/gajim/common/connection_handlers.py @@ -47,6 +47,7 @@ from gajim.common import helpers from gajim.common import app from gajim.common import dataforms from gajim.common import jingle_xtls +from gajim.common import configpaths from gajim.common.caps_cache import muc_caps_cache from gajim.common.commands import ConnectionCommands from gajim.common.pubsub import ConnectionPubSub @@ -391,7 +392,7 @@ class ConnectionVcard: else: app.log('avatar').info( 'Update (vCard): %s %s', obj.nick, obj.avatar_sha) - path = os.path.join(app.AVATAR_PATH, obj.avatar_sha) + path = os.path.join(configpaths.get('AVATAR'), obj.avatar_sha) if not os.path.isfile(path): app.log('avatar').info( 'Request (vCard): %s', obj.nick) @@ -572,7 +573,7 @@ class ConnectionVcard: current_sha = app.config.get_per('accounts', self.name, 'avatar_sha') if current_sha == avatar_sha: - path = os.path.join(app.AVATAR_PATH, current_sha) + path = os.path.join(configpaths.get('AVATAR'), current_sha) if not os.path.isfile(path): app.log('avatar').info( 'Caching (vCard): %s', current_sha) diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index a93f750ce..b44d6604a 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -40,6 +40,7 @@ from gajim.common import helpers from gajim.common import app from gajim.common import i18n from gajim.common import dataforms +from gajim.common import configpaths from gajim.common.zeroconf.zeroconf import Constant from gajim.common.const import KindConstant from gajim.common.pep import SUPPORTED_PERSONAL_USER_EVENTS @@ -2738,7 +2739,8 @@ class NotificationEvent(nec.NetworkIncomingEvent): if jid: # we want an avatar puny_jid = helpers.sanitize_filename(jid) - path_to_file = os.path.join(app.AVATAR_PATH, puny_jid) + suffix + path_to_file = os.path.join( + configpaths.get('AVATAR'), puny_jid) + suffix path_to_local_file = path_to_file + '_local' for extension in ('.png', '.jpeg'): path_to_local_file_full = path_to_local_file + extension diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py index 80736b2f4..0ff4dcbe5 100644 --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -53,6 +53,7 @@ import nbxmpp from gajim.common.i18n import Q_ from gajim.common.i18n import ngettext +from gajim.common import configpaths try: import precis_i18n.codec @@ -863,8 +864,8 @@ def check_soundfile_path(file_, dirs=None): :return the path to file or None if it doesn't exists. """ if dirs is None: - dirs = [app.configpaths.get('MY_DATA'), - app.DATA_DIR] + dirs = [configpaths.get('MY_DATA'), + configpaths.get('DATA')] if not file_: return None @@ -891,8 +892,8 @@ def strip_soundfile_path(file_, dirs=None, abs=True): return None if dirs is None: - dirs = [app.configpaths.get('MY_DATA'), - app.DATA_DIR] + dirs = [configpaths.get('MY_DATA'), + configpaths.get('DATA')] name = os.path.basename(file_) for d in dirs: @@ -1257,31 +1258,32 @@ def get_current_show(account): return app.SHOW_LIST[status] def get_iconset_path(iconset): - if os.path.isdir(os.path.join(app.DATA_DIR, 'iconsets', iconset)): - return os.path.join(app.DATA_DIR, 'iconsets', iconset) - elif os.path.isdir(os.path.join(app.MY_ICONSETS_PATH, iconset)): - return os.path.join(app.MY_ICONSETS_PATH, iconset) + if os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', iconset)): + return os.path.join(configpaths.get('DATA'), 'iconsets', iconset) + elif os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), iconset)): + return os.path.join(configpaths.get('MY_ICONSETS'), iconset) def get_mood_iconset_path(iconset): - if os.path.isdir(os.path.join(app.DATA_DIR, 'moods', iconset)): - return os.path.join(app.DATA_DIR, 'moods', iconset) - elif os.path.isdir(os.path.join(app.MY_MOOD_ICONSETS_PATH, iconset)): - return os.path.join(app.MY_MOOD_ICONSETS_PATH, iconset) + if os.path.isdir(os.path.join(configpaths.get('DATA'), 'moods', iconset)): + return os.path.join(configpaths.get('DATA'), 'moods', iconset) + elif os.path.isdir( + os.path.join(configpaths.get('MY_MOOD_ICONSETS'), iconset)): + return os.path.join(configpaths.get('MY_MOOD_ICONSETS'), iconset) def get_activity_iconset_path(iconset): - if os.path.isdir(os.path.join(app.DATA_DIR, 'activities', iconset)): - return os.path.join(app.DATA_DIR, 'activities', iconset) - elif os.path.isdir(os.path.join(app.MY_ACTIVITY_ICONSETS_PATH, + if os.path.isdir(os.path.join(configpaths.get('DATA'), 'activities', iconset)): + return os.path.join(configpaths.get('DATA'), 'activities', iconset) + elif os.path.isdir(os.path.join(configpaths.get('MY_ACTIVITY_ICONSETS'), iconset)): - return os.path.join(app.MY_ACTIVITY_ICONSETS_PATH, iconset) + return os.path.join(configpaths.get('MY_ACTIVITY_ICONSETS'), iconset) def get_transport_path(transport): - if os.path.isdir(os.path.join(app.DATA_DIR, 'iconsets', 'transports', + if os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', 'transports', transport)): - return os.path.join(app.DATA_DIR, 'iconsets', 'transports', transport) - elif os.path.isdir(os.path.join(app.MY_ICONSETS_PATH, 'transports', + return os.path.join(configpaths.get('DATA'), 'iconsets', 'transports', transport) + elif os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), 'transports', transport)): - return os.path.join(app.MY_ICONSETS_PATH, 'transports', transport) + return os.path.join(configpaths.get('MY_ICONSETS'), 'transports', transport) # No transport folder found, use default jabber one return get_iconset_path(app.config.get('iconset')) @@ -1606,13 +1608,13 @@ def version_condition(current_version, required_version): def get_available_emoticon_themes(): emoticons_themes = [] - emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons') + emoticons_data_path = os.path.join(configpaths.get('DATA'), 'emoticons') font_theme_path = os.path.join( - app.DATA_DIR, 'emoticons', 'font-emoticons', 'emoticons_theme.py') + configpaths.get('DATA'), 'emoticons', 'font-emoticons', 'emoticons_theme.py') folders = os.listdir(emoticons_data_path) - if os.path.isdir(app.MY_EMOTS_PATH): - folders += os.listdir(app.MY_EMOTS_PATH) + if os.path.isdir(configpaths.get('MY_EMOTS')): + folders += os.listdir(configpaths.get('MY_EMOTS')) file = 'emoticons_theme.py' if os.name == 'nt' and not os.path.exists(font_theme_path): @@ -1628,11 +1630,11 @@ def get_available_emoticon_themes(): return emoticons_themes def get_emoticon_theme_path(theme): - emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons', theme) + emoticons_data_path = os.path.join(configpaths.get('DATA'), 'emoticons', theme) if os.path.exists(emoticons_data_path): return emoticons_data_path - emoticons_user_path = os.path.join(app.MY_EMOTS_PATH, theme) + emoticons_user_path = os.path.join(configpaths.get('MY_EMOTS'), theme) if os.path.exists(emoticons_user_path): return emoticons_user_path diff --git a/gajim/common/jingle_content.py b/gajim/common/jingle_content.py index 0d4835606..bcc14f057 100644 --- a/gajim/common/jingle_content.py +++ b/gajim/common/jingle_content.py @@ -19,6 +19,7 @@ Handles Jingle contents (XEP 0166) import os from gajim.common import app +from gajim.common import configpaths import nbxmpp from gajim.common.jingle_xtls import SELF_SIGNED_CERTIFICATE from gajim.common.jingle_xtls import load_cert_file @@ -221,8 +222,8 @@ class JingleContent: if self.use_security: security = nbxmpp.simplexml.Node( tag=nbxmpp.NS_JINGLE_XTLS + ' security') - certpath = os.path.join(app.MY_CERT_DIR, SELF_SIGNED_CERTIFICATE)\ - + '.cert' + certpath = os.path.join( + configpaths.get('MY_CERT'), SELF_SIGNED_CERTIFICATE) + '.cert' cert = load_cert_file(certpath) if cert: try: diff --git a/gajim/common/jingle_xtls.py b/gajim/common/jingle_xtls.py index 7744df133..487e6aa00 100644 --- a/gajim/common/jingle_xtls.py +++ b/gajim/common/jingle_xtls.py @@ -21,6 +21,7 @@ import os import nbxmpp from gajim.common import app +from gajim.common import configpaths log = logging.getLogger('gajim.c.jingle_xtls') @@ -111,18 +112,18 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None): elif fingerprint == 'client': ctx.set_verify(SSL.VERIFY_PEER, verify_cb or default_callback) - cert_name = os.path.join(app.MY_CERT_DIR, SELF_SIGNED_CERTIFICATE) + cert_name = os.path.join(configpaths.get('MY_CERT'), SELF_SIGNED_CERTIFICATE) ctx.use_privatekey_file((cert_name + '.pkey').encode('utf-8')) ctx.use_certificate_file((cert_name + '.cert').encode('utf-8')) # Try to load Diffie-Hellman parameters. # First try user DH parameters, if this fails load the default DH parameters - dh_params_name = os.path.join(app.MY_CERT_DIR, DH_PARAMS) + dh_params_name = os.path.join(configpaths.get('MY_CERT'), DH_PARAMS) try: with open(dh_params_name, "r") as dh_params_file: ctx.load_tmp_dh(dh_params_name.encode('utf-8')) except FileNotFoundError as err: - default_dh_params_name = os.path.join(app.DATA_DIR, + default_dh_params_name = os.path.join(configpaths.get('DATA'), 'other', DEFAULT_DH_PARAMS) try: with open(default_dh_params_name, "r") as default_dh_params_file: @@ -134,7 +135,7 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None): if remote_jid: store = ctx.get_cert_store() - path = os.path.join(os.path.expanduser(app.MY_PEER_CERTS_PATH), + path = os.path.join(os.path.expanduser(configpaths.get('MY_PEER_CERTS')), remote_jid) + '.cert' if os.path.exists(path): load_cert_file(path, cert_store=store) @@ -151,7 +152,7 @@ def read_cert(certpath): return certificate def send_cert(con, jid_from, sid): - certpath = os.path.join(app.MY_CERT_DIR, SELF_SIGNED_CERTIFICATE) + \ + certpath = os.path.join(configpaths.get('MY_CERT'), SELF_SIGNED_CERTIFICATE) + \ '.cert' certificate = read_cert(certpath) iq = nbxmpp.Iq('result', to=jid_from) @@ -170,7 +171,7 @@ def send_cert(con, jid_from, sid): def handle_new_cert(con, obj, jid_from): jid = app.get_jid_without_resource(jid_from) - certpath = os.path.join(os.path.expanduser(app.MY_PEER_CERTS_PATH), jid) + certpath = os.path.join(os.path.expanduser(configpaths.get('MY_PEER_CERTS')), jid) certpath += '.cert' id_ = obj.getAttr('id') @@ -188,7 +189,7 @@ def handle_new_cert(con, obj, jid_from): approve_pending_content(id_) def check_cert(jid, fingerprint): - certpath = os.path.join(os.path.expanduser(app.MY_PEER_CERTS_PATH), jid) + certpath = os.path.join(os.path.expanduser(configpaths.get('MY_PEER_CERTS')), jid) certpath += '.cert' if os.path.exists(certpath): cert = load_cert_file(certpath) diff --git a/gajim/config.py b/gajim/config.py index 751861b45..a77416cec 100644 --- a/gajim/config.py +++ b/gajim/config.py @@ -58,6 +58,7 @@ from gajim.common import app from gajim.common import connection from gajim.common import dataforms from gajim.common import ged +from gajim.common import configpaths from gajim.accounts_window import AccountsWindow try: @@ -202,9 +203,10 @@ class PreferencesWindow: self.update_theme_list() # iconset - iconsets_list = os.listdir(os.path.join(app.DATA_DIR, 'iconsets')) - if os.path.isdir(app.MY_ICONSETS_PATH): - iconsets_list += os.listdir(app.MY_ICONSETS_PATH) + iconsets_list = os.listdir( + os.path.join(configpaths.get('DATA'), 'iconsets')) + if os.path.isdir(configpaths.get('MY_ICONSETS')): + iconsets_list += os.listdir(configpaths.get('MY_ICONSETS')) # new model, image in 0, string in 1 model = Gtk.ListStore(Gtk.Image, str) renderer_image = cell_renderer_image.CellRendererImage(0, 0) @@ -217,8 +219,8 @@ class PreferencesWindow: self.iconset_combobox.set_model(model) l = [] for dir in iconsets_list: - if not os.path.isdir(os.path.join(app.DATA_DIR, 'iconsets', dir)) \ - and not os.path.isdir(os.path.join(app.MY_ICONSETS_PATH, dir)): + if not os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', dir)) \ + and not os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), dir)): continue if dir != '.svn' and dir != 'transports': l.append(dir) @@ -2292,7 +2294,8 @@ class AccountCreationWizardWindow: self.update_proxy_list() # parse servers.xml - servers_xml = os.path.join(app.DATA_DIR, 'other', 'servers.xml') + servers_xml = os.path.join( + configpaths.get('DATA'), 'other', 'servers.xml') servers = gtkgui_helpers.parse_server_xml(servers_xml) servers_model = self.xml.get_object('server_liststore') for server in servers: @@ -2532,16 +2535,17 @@ class AccountCreationWizardWindow: 'hostname'] # Check if cert is already in file certs = '' - if os.path.isfile(app.MY_CACERTS): - f = open(app.MY_CACERTS) + my_ca_certs = configpaths.get('MY_CACERTS') + if os.path.isfile(my_ca_certs): + f = open(my_ca_certs) certs = f.read() f.close() if self.ssl_cert in certs: dialogs.ErrorDialog(_('Certificate Already in File'), _('This certificate is already in file %s, so it\'s ' - 'not added again.') % app.MY_CACERTS) + 'not added again.') % my_ca_certs) else: - f = open(app.MY_CACERTS, 'a') + f = open(my_ca_certs, 'a') f.write(hostname + '\n') f.write(self.ssl_cert + '\n\n') f.close() diff --git a/gajim/gtkgui_helpers.py b/gajim/gtkgui_helpers.py index 7289f7a6e..4c95af1b3 100644 --- a/gajim/gtkgui_helpers.py +++ b/gajim/gtkgui_helpers.py @@ -52,7 +52,7 @@ from gajim.common import pep from gajim.common import configpaths gtk_icon_theme = Gtk.IconTheme.get_default() -gtk_icon_theme.append_search_path(app.ICONS_DIR) +gtk_icon_theme.append_search_path(configpaths.get('ICONS')) class Color: BLACK = Gdk.RGBA(red=0, green=0, blue=0, alpha=1) @@ -610,7 +610,7 @@ def get_pep_as_pixbuf(pep_class): elif isinstance(pep_class, pep.UserTunePEP): icon = get_icon_pixmap('audio-x-generic', quiet=True) if not icon: - path = os.path.join(app.DATA_DIR, 'emoticons', 'static', + path = os.path.join(configpaths.get('DATA'), 'emoticons', 'static', 'music.png') return GdkPixbuf.Pixbuf.new_from_file(path) return icon diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index 42401521c..3f07983e4 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -1352,16 +1352,17 @@ class Interface: if is_checked[0]: # Check if cert is already in file certs = '' - if os.path.isfile(app.MY_CACERTS): - f = open(app.MY_CACERTS) + my_ca_certs = configpaths.get('MY_CACERTS') + if os.path.isfile(my_ca_certs): + f = open(my_ca_certs) certs = f.read() f.close() if obj.cert in certs: dialogs.ErrorDialog(_('Certificate Already in File'), _('This certificate is already in file %s, so it\'s ' - 'not added again.') % app.MY_CACERTS) + 'not added again.') % my_ca_certs) else: - f = open(app.MY_CACERTS, 'a') + f = open(my_ca_certs, 'a') f.write(server + '\n') f.write(obj.cert + '\n\n') f.close() @@ -2446,14 +2447,15 @@ class Interface: pixbuf = pixbuf.scale_simple(AvatarSize.PROFILE, AvatarSize.PROFILE, GdkPixbuf.InterpType.BILINEAR) - publish_path = os.path.join(app.AVATAR_PATH, 'temp_publish') + publish_path = os.path.join( + configpaths.get('AVATAR'), 'temp_publish') pixbuf.savev(publish_path, 'png', [], []) with open(publish_path, 'rb') as file: data = file.read() return self.save_avatar(data) sha = hashlib.sha1(data).hexdigest() - path = os.path.join(app.AVATAR_PATH, sha) + path = os.path.join(configpaths.get('AVATAR'), sha) try: with open(path, "wb") as output_file: output_file.write(data) @@ -2475,7 +2477,7 @@ class Interface: size = size * scale if publish: - path = os.path.join(app.AVATAR_PATH, filename) + path = os.path.join(configpaths.get('AVATAR'), filename) with open(path, 'rb') as file: data = file.read() return data @@ -2488,7 +2490,7 @@ class Interface: except KeyError: pass - path = os.path.join(app.AVATAR_PATH, filename) + path = os.path.join(configpaths.get('AVATAR'), filename) if not os.path.isfile(path): return @@ -2532,7 +2534,7 @@ class Interface: @staticmethod def avatar_exists(filename): - path = os.path.join(app.AVATAR_PATH, filename) + path = os.path.join(configpaths.get('AVATAR'), filename) if not os.path.isfile(path): return False return True @@ -2601,7 +2603,8 @@ class Interface: mood = received_mood if received_mood in pep.MOODS else 'unknown' return gtkgui_helpers.load_mood_icon(mood).get_pixbuf() elif isinstance(pep_obj, pep.UserTunePEP): - path = os.path.join(app.DATA_DIR, 'emoticons', 'static', 'music.png') + path = os.path.join( + configpaths.get('DATA'), 'emoticons', 'static', 'music.png') return GdkPixbuf.Pixbuf.new_from_file(path) elif isinstance(pep_obj, pep.UserActivityPEP): pep_ = pep_obj._pep_specific_data diff --git a/gajim/history_manager.py b/gajim/history_manager.py index 076fee1a7..946a69393 100644 --- a/gajim/history_manager.py +++ b/gajim/history_manager.py @@ -47,6 +47,7 @@ from gi.repository import GLib from gi.repository import Gio from gajim.common import i18n +from gajim.common import configpaths def is_standalone(): @@ -59,10 +60,6 @@ def is_standalone(): if is_standalone(): - # Standalone Mode - # Must be done before importing app - from gajim.common import configpaths - try: shortargs = 'hvsc:l:p:' longargs = 'help verbose separate config-path= loglevel= profile=' @@ -474,7 +471,7 @@ class HistoryManager: dlg = xml.get_object('filechooserdialog') dlg.set_title(_('Exporting History Logsā€¦')) - dlg.set_current_folder(app.HOME_DIR) + dlg.set_current_folder(configpaths.get('HOME')) dlg.props.do_overwrite_confirmation = True response = dlg.run() diff --git a/gajim/plugins/gajimplugin.py b/gajim/plugins/gajimplugin.py index c9fd28229..44db38bee 100644 --- a/gajim/plugins/gajimplugin.py +++ b/gajim/plugins/gajimplugin.py @@ -27,7 +27,7 @@ Base class for implementing plugin. import os import locale -from gajim.common import app +from gajim.common import configpaths from gajim.plugins.helpers import log_calls, log from gajim.plugins.gui import GajimPluginConfigDialog @@ -213,7 +213,7 @@ class GajimPluginConfig(): def __init__(self, plugin): self.plugin = plugin self.FILE_PATH = os.path.join( - app.PLUGINS_CONFIG_DIR, self.plugin.short_name) + configpaths.get('PLUGINS_CONFIG_DIR'), self.plugin.short_name) self.data = {} @log_calls('GajimPluginConfig') diff --git a/gajim/plugins/gui.py b/gajim/plugins/gui.py index 454352ea3..98786b25a 100644 --- a/gajim/plugins/gui.py +++ b/gajim/plugins/gui.py @@ -38,6 +38,7 @@ from gajim import gtkgui_helpers from gajim.dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog from gajim.htmltextview import HtmlTextView from gajim.common import app +from gajim.common import configpaths from gajim.plugins.helpers import log_calls from gajim.plugins.helpers import GajimPluginActivateException from gajim.plugins.plugins_i18n import _ @@ -161,8 +162,8 @@ class PluginsWindow(object): self.plugin_description_textview, None) self.plugin_description_textview.set_property('sensitive', True) - self.uninstall_plugin_button.set_property('sensitive', - app.PLUGINS_DIRS[1] in plugin.__path__) + self.uninstall_plugin_button.set_property( + 'sensitive', configpaths.get('PLUGINS_USER') in plugin.__path__) self.configure_plugin_button.set_property( 'sensitive', plugin.config_dialog is not None) diff --git a/gajim/plugins/pluginmanager.py b/gajim/plugins/pluginmanager.py index 15972955b..d4bab752e 100644 --- a/gajim/plugins/pluginmanager.py +++ b/gajim/plugins/pluginmanager.py @@ -36,6 +36,7 @@ from pkg_resources import parse_version from gajim.common import app from gajim.common import nec +from gajim.common import configpaths from gajim.common.exceptions import PluginsystemError from gajim.plugins.helpers import log, log_calls, Singleton @@ -107,7 +108,7 @@ class PluginManager(metaclass=Singleton): Registered names with instances of encryption Plugins. ''' - for path in [app.PLUGINS_DIRS[1], app.PLUGINS_DIRS[0]]: + for path in reversed(configpaths.get('PLUGINS_DIRS')): pc = PluginManager.scan_dir_for_plugins(path) self.add_plugins(pc) @@ -534,7 +535,7 @@ class PluginManager(metaclass=Singleton): try: if module_name in sys.modules: - if path == app.PLUGINS_DIRS[0]: + if path == configpaths.get('PLUGINS_BASE'): # Only reload plugins from Gajim base dir when they # dont exist. This means plugins in the user path are # always preferred. @@ -632,7 +633,7 @@ class PluginManager(metaclass=Singleton): if len(dirs) > 1: raise PluginsystemError(_('Archive is malformed')) - base_dir, user_dir = app.PLUGINS_DIRS + base_dir, user_dir = configpaths.get('PLUGINS_DIRS') plugin_dir = os.path.join(user_dir, dirs[0]) if os.path.isdir(plugin_dir): diff --git a/gajim/plugins/plugins_i18n.py b/gajim/plugins/plugins_i18n.py index e33050f7f..59b27f9c4 100644 --- a/gajim/plugins/plugins_i18n.py +++ b/gajim/plugins/plugins_i18n.py @@ -23,9 +23,10 @@ import gettext from os import path as os_path import os from gajim.common import app +from gajim.common import configpaths APP = 'gajim_plugins' -plugins_locale_dir = os_path.join(app.PLUGINS_DIRS[1], 'locale') +plugins_locale_dir = os_path.join(configpaths.get('PLUGINS_USER'), 'locale') if os.name != 'nt': locale.setlocale(locale.LC_ALL, '') diff --git a/gajim/vcard.py b/gajim/vcard.py index d62c1a47b..0e5b81e05 100644 --- a/gajim/vcard.py +++ b/gajim/vcard.py @@ -44,6 +44,7 @@ from gajim import gtkgui_helpers from gajim.common import helpers from gajim.common import app from gajim.common import ged +from gajim.common import configpaths from gajim.common.i18n import Q_ from gajim.common.const import AvatarSize @@ -84,7 +85,7 @@ class VcardWindow: self.real_resource = contact.resource puny_jid = helpers.sanitize_filename(contact.jid) - local_avatar_basepath = os.path.join(app.AVATAR_PATH, puny_jid) + \ + local_avatar_basepath = os.path.join(configpaths.get('AVATAR'), puny_jid) + \ '_local' for extension in ('.png', '.jpeg'): local_avatar_path = local_avatar_basepath + extension diff --git a/test/lib/__init__.py b/test/lib/__init__.py index 7ddd20216..90c9a0d05 100644 --- a/test/lib/__init__.py +++ b/test/lib/__init__.py @@ -47,7 +47,7 @@ def setup_env(): import logging logging.basicConfig() - app.DATA_DIR = gajim_root + '/gajim/data' + configpaths.override_path('DATA', gajim_root + '/gajim/data') app.use_x = use_x app.contacts = LegacyContactsAPI() app.connections = {} diff --git a/test/test_pluginmanager.py b/test/test_pluginmanager.py index ee0c59f59..d2565ef4f 100644 --- a/test/test_pluginmanager.py +++ b/test/test_pluginmanager.py @@ -54,9 +54,8 @@ configpaths.set_config_root(configdir) configpaths.init() # for some reason common.app needs to be imported before xmpppy? -from gajim.common import app -app.DATA_DIR = gajim_root + '/gajim/data' +configpaths.override_path('DATA', gajim_root + '/gajim/data') from common.stanza_session import StanzaSession