mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-12 19:32:16 -04:00
Replace use of pkg_resources.resource_filename with importlib.resources
This commit is contained in:
parent
795f63f7d6
commit
1e2be5f204
2 changed files with 10 additions and 7 deletions
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import importlib.resources as importlib_resources
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
|
@ -29,7 +30,6 @@ import threading
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import re
|
import re
|
||||||
from pkg_resources import resource_filename
|
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
|
@ -313,9 +313,10 @@ class Common:
|
||||||
"""
|
"""
|
||||||
Returns the absolute path of a resource
|
Returns the absolute path of a resource
|
||||||
"""
|
"""
|
||||||
path = resource_filename("onionshare_cli", os.path.join("resources", filename))
|
ref = importlib_resources.files("onionshare_cli.resources") / filename
|
||||||
self.log("Common", "get_resource_path", f"filename={filename}, path={path}")
|
with importlib_resources.as_file(ref) as path:
|
||||||
return path
|
self.log("Common", "get_resource_path", f"filename={filename}, path={str(path)}")
|
||||||
|
return str(path)
|
||||||
|
|
||||||
def get_tor_paths(self):
|
def get_tor_paths(self):
|
||||||
if self.platform == "Linux":
|
if self.platform == "Linux":
|
||||||
|
|
|
@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import importlib.resources as importlib_resources
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pkg_resources import resource_filename
|
|
||||||
from PySide6 import QtCore, QtWidgets, QtGui
|
from PySide6 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
|
@ -548,8 +548,10 @@ class GuiCommon:
|
||||||
Returns the absolute path of a resource
|
Returns the absolute path of a resource
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return resource_filename("onionshare", os.path.join("resources", filename))
|
ref = importlib_resources.files("onionshare.resources") / filename
|
||||||
except KeyError:
|
with importlib_resources.as_file(ref) as path:
|
||||||
|
return str(path)
|
||||||
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue