From a9666ba7350b71f1ac9b657f566ca82d82f79fd1 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Tue, 18 May 2021 20:38:25 +0300 Subject: [PATCH] picons extraction fix --- app/settings.py | 29 +++++++++++++++++++++++++++++ app/tools/picons.py | 7 ++++--- app/ui/uicommons.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/app/settings.py b/app/settings.py index 56b1532f..2e8142de 100644 --- a/app/settings.py +++ b/app/settings.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 Dmitriy Yefremov +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Dmitriy Yefremov +# + + import copy import json import locale @@ -13,6 +41,7 @@ HOME_PATH = str(Path.home()) CONFIG_PATH = HOME_PATH + "/.config/demon-editor/" CONFIG_FILE = CONFIG_PATH + "config.json" DATA_PATH = HOME_PATH + "/DemonEditor/data/" +GTK_PATH = os.environ.get("GTK_PATH", None) IS_DARWIN = sys.platform == "darwin" diff --git a/app/tools/picons.py b/app/tools/picons.py index 4cfe55b7..442a1010 100644 --- a/app/tools/picons.py +++ b/app/tools/picons.py @@ -37,7 +37,7 @@ from html.parser import HTMLParser import requests from app.commons import run_task, log -from app.settings import SettingsType +from app.settings import SettingsType, GTK_PATH from .satellites import _HEADERS _ENIGMA2_PICON_KEY = "{:X}:{:X}:{}" @@ -124,7 +124,8 @@ class PiconsCzDownloader: def extract(self, src, dest, picon_ids=None): """ Extracts 7z archives. """ # TODO: think about https://github.com/miurahr/py7zr - cmd = ["7zr", "l", src] + exe = "./7zr" if GTK_PATH else "7zr" + cmd = [exe, "l", src] try: out, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() if err: @@ -148,7 +149,7 @@ class PiconsCzDownloader: os.remove(src) raise PiconsError("No matching picons found!") - cmd = ["7zr", "e", src, "-o{}".format(dest), "-y", "-r"] + cmd = [exe, "e", src, "-o{}".format(dest), "-y", "-r"] cmd.extend(to_extract) try: out, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() diff --git a/app/ui/uicommons.py b/app/ui/uicommons.py index 5e7d22d1..6524f24b 100644 --- a/app/ui/uicommons.py +++ b/app/ui/uicommons.py @@ -1,7 +1,35 @@ +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 Dmitriy Yefremov +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Dmitriy Yefremov +# + + import os from enum import Enum, IntEnum from functools import lru_cache -from app.settings import Settings, SettingsException, IS_DARWIN +from app.settings import Settings, SettingsException, IS_DARWIN, GTK_PATH import gi @@ -14,7 +42,6 @@ MOD_MASK = Gdk.ModifierType.MOD2_MASK if IS_DARWIN else Gdk.ModifierType.CONTROL # Path to *.glade files UI_RESOURCES_PATH = "app/ui/" if os.path.exists("app/ui/") else "ui/" LANG_PATH = UI_RESOURCES_PATH + "lang" -GTK_PATH = os.environ.get("GTK_PATH", None) NOTIFY_IS_INIT = False IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) # Translation.