Philipp Hörist pushed to branch master at gajim / gajim
Commits: e0b67eb6 by André Apitzsch at 2020-08-22T20:57:24+02:00 css_config: Port to pathlib
- - - - -
1 changed file:
- gajim/gtk/css_config.py
Changes:
===================================== gajim/gtk/css_config.py ===================================== @@ -15,9 +15,9 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
-import os import math import logging +from pathlib import Path
from gi.repository import Gtk from gi.repository import Gdk @@ -148,7 +148,7 @@ class CSSConfig(): CSSPriority.DEFAULT_THEME_DARK)
def _load_css_from_file(self, filename, priority): - path = os.path.join(configpaths.get('STYLE'), filename) + path = Path(configpaths.get('STYLE')) / filename try: with open(path, "r") as file_: css = file_.read() @@ -180,8 +180,8 @@ class CSSConfig(): return int(math.ceil(number / 100.0)) * 100
def _gather_available_themes(self): - files = os.listdir(configpaths.get('MY_THEME')) - self.themes = [file[:-4] for file in files if file.endswith('.css')] + files = Path(configpaths.get('MY_THEME')).iterdir() + self.themes = [file.stem for file in files if file.suffix == '.css'] if 'default' in self.themes: # Ignore user created themes that are named 'default' self.themes.remove('default') @@ -191,8 +191,8 @@ class CSSConfig(): theme = 'default-dark'
if user: - return os.path.join(configpaths.get('MY_THEME'), '%s.css' % theme) - return os.path.join(configpaths.get('STYLE'), '%s.css' % theme) + return Path(configpaths.get('MY_THEME')) / f'{theme}.css' + return Path(configpaths.get('STYLE')) / f'{theme}.css'
def _determine_theme_path(self): # Gets the path of the currently active theme. @@ -202,7 +202,7 @@ class CSSConfig(): return self.get_theme_path(theme, user=False)
theme_path = self.get_theme_path(theme) - if not theme or not os.path.exists(theme_path): + if not theme or not theme_path.exists(): log.warning('Theme %s not found, fallback to default', theme) app.config.set('roster_theme', 'default') log.info('Use Theme: default') @@ -462,7 +462,7 @@ class CSSConfig(): def change_theme(self, theme): user = not theme == 'default' theme_path = self.get_theme_path(theme, user=user) - if not os.path.exists(theme_path): + if not theme_path.exists(): log.error('Change Theme: Theme %s does not exist', theme_path) return False self._load_selected(theme_path) @@ -473,7 +473,7 @@ class CSSConfig():
def change_preload_theme(self, theme): theme_path = self.get_theme_path(theme) - if not os.path.exists(theme_path): + if not theme_path.exists(): log.error('Change Preload Theme: Theme %s does not exist', theme_path) return False @@ -492,7 +492,7 @@ class CSSConfig():
old_theme_path = self.get_theme_path(old_theme) new_theme_path = self.get_theme_path(new_theme) - os.rename(old_theme_path, new_theme_path) + old_theme_path.rename(new_theme_path) self.themes.remove(old_theme) self.themes.append(new_theme) self._load_pre(new_theme) @@ -507,7 +507,7 @@ class CSSConfig():
def add_new_theme(self, theme): theme_path = self.get_theme_path(theme) - if os.path.exists(theme_path): + if theme_path.exists(): log.error('Add Theme: %s exists already', theme_path) return False with open(theme_path, 'w', encoding='utf8'): @@ -518,8 +518,8 @@ class CSSConfig():
def remove_theme(self, theme): theme_path = self.get_theme_path(theme) - if os.path.exists(theme_path): - os.remove(theme_path) + if theme_path.exists(): + theme_path.unlink() self.themes.remove(theme) log.info('Remove Theme: Successful removed theme %s', theme)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e0b67eb6ed250e653eba9964337720b43...