[plugins_translations] Type annotations, linting

This commit is contained in:
wurstsalat
2022-11-29 19:34:20 +01:00
parent e97f055f69
commit ff9cedf90a
2 changed files with 25 additions and 7 deletions

View File

@@ -1 +1 @@
from .plugins_translations import PluginsTranslationsPlugin from .plugins_translations import PluginsTranslationsPlugin # type: ignore

View File

@@ -1,3 +1,21 @@
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import cast
import logging import logging
import os import os
import shutil import shutil
@@ -13,17 +31,17 @@ log = logging.getLogger('gajim.p.plugins_translations')
class PluginsTranslationsPlugin(GajimPlugin): class PluginsTranslationsPlugin(GajimPlugin):
def init(self): def init(self) -> None:
self.description = _('This plugin contains translations for other ' self.description = _('This plugin contains translations for other '
'Gajim plugins. Please restart Gajim after ' 'Gajim plugins. Please restart Gajim after '
'enabling this plugin.') 'enabling this plugin.')
self.config_dialog = None self.config_dialog = None
self.config_default_values = {'last_version': '0'} self.config_default_values = {'last_version': ('0', '')}
self.locale_dir = Path(configpaths.get('PLUGINS_USER')) / 'locale' self.locale_dir = Path(configpaths.get('PLUGINS_USER')) / 'locale'
def activate(self): def activate(self) -> None:
current_version = str(self.manifest.version) current_version = str(self.manifest.version)
if self.config['last_version'] == current_version: if cast(str, self.config['last_version']) == current_version:
return return
files = glob(self.__path__ + '/*.mo') files = glob(self.__path__ + '/*.mo')
@@ -43,11 +61,11 @@ class PluginsTranslationsPlugin(GajimPlugin):
self.config['last_version'] = current_version self.config['last_version'] = current_version
def _remove_translations(self): def _remove_translations(self) -> None:
log.info('Removing old translations...') log.info('Removing old translations...')
if self.locale_dir.exists(): if self.locale_dir.exists():
shutil.rmtree(str(self.locale_dir)) shutil.rmtree(str(self.locale_dir))
def deactivate(self): def deactivate(self) -> None:
self._remove_translations() self._remove_translations()
self.config['last_version'] = '0' self.config['last_version'] = '0'