Philipp Hörist pushed to branch master at gajim / gajim

Commits:

7 changed files:

Changes:

  • gajim/common/helpers.py
    ... ... @@ -913,7 +913,7 @@ def get_sync_threshold(jid, archive_info):
    913 913
     
    
    914 914
     def load_json(path, key=None, default=None):
    
    915 915
         try:
    
    916
    -        with open(path, 'r') as file:
    
    916
    +        with path.open('r') as file:
    
    917 917
                 json_dict = json.loads(file.read())
    
    918 918
         except Exception:
    
    919 919
             log.exception('Parsing error')
    

  • gajim/gtk/account_wizard.py
    ... ... @@ -12,8 +12,8 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    -import os
    
    16 15
     import logging
    
    16
    +from pathlib import Path
    
    17 17
     
    
    18 18
     from gi.repository import Gdk
    
    19 19
     from gi.repository import GLib
    
    ... ... @@ -553,9 +553,8 @@ class Login(Page):
    553 553
     
    
    554 554
         def _create_server_completion(self):
    
    555 555
             # Parse servers.json
    
    556
    -        server_file_path = os.path.join(
    
    557
    -            configpaths.get('DATA'), 'other', 'servers.json')
    
    558
    -        self._servers = helpers.load_json(server_file_path, 'servers', [])
    
    556
    +        file_path = Path(configpaths.get('DATA')) / 'other' / 'servers.json'
    
    557
    +        self._servers = helpers.load_json(file_path, 'servers', [])
    
    559 558
     
    
    560 559
             # Create a separate model for the address entry, because it will
    
    561 560
             # be updated with our localpart@
    
    ... ... @@ -631,11 +630,6 @@ class Signup(Page):
    631 630
             self.complete = False
    
    632 631
             self.title = _('Create New Account')
    
    633 632
     
    
    634
    -        # Parse servers.json
    
    635
    -        server_file_path = os.path.join(
    
    636
    -            configpaths.get('DATA'), 'other', 'servers.json')
    
    637
    -        self._servers = helpers.load_json(server_file_path, 'servers', [])
    
    638
    -
    
    639 633
             self._ui = get_builder('account_wizard.ui')
    
    640 634
             self._ui.server_comboboxtext_sign_up_entry.set_activates_default(True)
    
    641 635
             self._create_server_completion()
    
    ... ... @@ -658,13 +652,12 @@ class Signup(Page):
    658 652
     
    
    659 653
         def _create_server_completion(self):
    
    660 654
             # Parse servers.json
    
    661
    -        server_file_path = os.path.join(
    
    662
    -            configpaths.get('DATA'), 'other', 'servers.json')
    
    663
    -        self._servers = helpers.load_json(server_file_path, 'servers', [])
    
    655
    +        file_path = Path(configpaths.get('DATA')) / 'other' / 'servers.json'
    
    656
    +        servers = helpers.load_json(file_path, 'servers', [])
    
    664 657
     
    
    665 658
             # Create servers_model for comboboxes and entries
    
    666 659
             servers_model = Gtk.ListStore(str)
    
    667
    -        for server in self._servers:
    
    660
    +        for server in servers:
    
    668 661
                 servers_model.append((server,))
    
    669 662
     
    
    670 663
             # Sign up combobox and entry
    

  • gajim/gtk/emoji_chooser.py
    ... ... @@ -12,10 +12,10 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    -import os
    
    16 15
     import sys
    
    17 16
     import logging
    
    18 17
     import weakref
    
    18
    +from pathlib import Path
    
    19 19
     from collections import OrderedDict
    
    20 20
     
    
    21 21
     from gi.repository import Gtk
    
    ... ... @@ -317,15 +317,14 @@ class EmojiChooser(Gtk.Popover):
    317 317
         def _get_emoji_theme_path(theme):
    
    318 318
             if theme == 'font':
    
    319 319
                 return 'font'
    
    320
    -        emoticons_data_path = os.path.join(configpaths.get('EMOTICONS'),
    
    321
    -                                           theme,
    
    322
    -                                           '%s.png' % theme)
    
    323
    -        if os.path.exists(emoticons_data_path):
    
    320
    +
    
    321
    +        base_path = Path(configpaths.get('EMOTICONS'))
    
    322
    +        emoticons_data_path = base_path / theme / f'{theme}.png'
    
    323
    +        if emoticons_data_path.exists():
    
    324 324
                 return emoticons_data_path
    
    325 325
     
    
    326
    -        emoticons_user_path = os.path.join(configpaths.get('MY_EMOTS'),
    
    327
    -                                           '%s.png' % theme)
    
    328
    -        if os.path.exists(emoticons_user_path):
    
    326
    +        emoticons_user_path = Path(configpaths.get('MY_EMOTS')) / f'{theme}.png'
    
    327
    +        if emoticons_user_path.exists():
    
    329 328
                 return emoticons_user_path
    
    330 329
     
    
    331 330
             log.warning('Could not find emoji theme: %s', theme)
    
    ... ... @@ -385,7 +384,7 @@ class EmojiChooser(Gtk.Popover):
    385 384
         @staticmethod
    
    386 385
         def _get_next_pixbuf(path):
    
    387 386
             src_x = src_y = cur_column = 0
    
    388
    -        atlas = GdkPixbuf.Pixbuf.new_from_file(path)
    
    387
    +        atlas = GdkPixbuf.Pixbuf.new_from_file(str(path))
    
    389 388
     
    
    390 389
             while True:
    
    391 390
                 src_x = cur_column * Emoji.PARSE_WIDTH
    

  • gajim/gtk/util.py
    ... ... @@ -20,7 +20,6 @@ from typing import List
    20 20
     from typing import Tuple
    
    21 21
     from typing import Optional
    
    22 22
     
    
    23
    -import os
    
    24 23
     import sys
    
    25 24
     import logging
    
    26 25
     import textwrap
    
    ... ... @@ -60,7 +59,7 @@ from gajim.gtk.const import WINDOW_MODULES
    60 59
     
    
    61 60
     _icon_theme = Gtk.IconTheme.get_default()
    
    62 61
     if _icon_theme is not None:
    
    63
    -    _icon_theme.append_search_path(configpaths.get('ICONS'))
    
    62
    +    _icon_theme.append_search_path(str(configpaths.get('ICONS')))
    
    64 63
     
    
    65 64
     log = logging.getLogger('gajim.gtk.util')
    
    66 65
     
    
    ... ... @@ -164,7 +163,7 @@ class Builder:
    164 163
             if gettext_ is None:
    
    165 164
                 gettext_ = _
    
    166 165
     
    
    167
    -        file_path = os.path.join(configpaths.get('GUI'), filename)
    
    166
    +        file_path = str(Path(configpaths.get('GUI')) / filename)
    
    168 167
     
    
    169 168
             if sys.platform == "win32":
    
    170 169
                 # This is a workaround for non working translation on Windows
    

  • gajim/gui_interface.py
    ... ... @@ -115,7 +115,7 @@ from gajim.gtk.util import get_color_for_account
    115 115
     from gajim.gtk.const import ControlType
    
    116 116
     
    
    117 117
     
    
    118
    -parser = optparser.OptionsParser(configpaths.get('CONFIG_FILE'))
    
    118
    +parser = optparser.OptionsParser(str(configpaths.get('CONFIG_FILE')))
    
    119 119
     log = logging.getLogger('gajim.interface')
    
    120 120
     
    
    121 121
     class Interface:
    

  • gajim/history_manager.py
    ... ... @@ -30,6 +30,7 @@ import sys
    30 30
     import time
    
    31 31
     import getopt
    
    32 32
     import sqlite3
    
    33
    +from pathlib import Path
    
    33 34
     from enum import IntEnum, unique
    
    34 35
     
    
    35 36
     import gi
    
    ... ... @@ -108,8 +109,8 @@ class Column(IntEnum):
    108 109
     
    
    109 110
     class HistoryManager:
    
    110 111
         def __init__(self):
    
    111
    -        log_db_path = configpaths.get('LOG_DB')
    
    112
    -        if not os.path.exists(log_db_path):
    
    112
    +        log_db_path = Path(configpaths.get('LOG_DB'))
    
    113
    +        if not log_db_path.exists():
    
    113 114
                 ErrorDialog(_('Cannot find history logs database'),
    
    114 115
                             _('%s does not exist.') % log_db_path)
    
    115 116
                 sys.exit()
    

  • gajim/plugins/plugins_i18n.py
    ... ... @@ -14,21 +14,23 @@
    14 14
     # You should have received a copy of the GNU General Public License
    
    15 15
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    16 16
     
    
    17
    -import os
    
    18 17
     import locale
    
    19 18
     import gettext
    
    19
    +from pathlib import Path
    
    20 20
     
    
    21 21
     from gajim.common import configpaths
    
    22 22
     
    
    23 23
     DOMAIN = 'gajim_plugins'
    
    24 24
     try:
    
    25
    -    plugin_user_dir = configpaths.get('PLUGINS_USER')
    
    25
    +    plugin_user_dir = Path(configpaths.get('PLUGINS_USER'))
    
    26 26
     except KeyError:
    
    27 27
         # This allows to import the module for tests
    
    28 28
         print('No plugin translation path available')
    
    29
    -    plugin_user_dir = ''
    
    29
    +    plugin_user_dir = Path.cwd()
    
    30 30
     
    
    31
    -plugins_locale_dir = os.path.join(plugin_user_dir, 'locale')
    
    31
    +
    
    32
    +# python 3.7 gettext module does not support Path objects
    
    33
    +plugins_locale_dir = str(plugin_user_dir / 'locale')
    
    32 34
     
    
    33 35
     try:
    
    34 36
         t = gettext.translation(DOMAIN, plugins_locale_dir)