From 6bac723da31e958e97114dca75adfdf659b2ee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 14 Jul 2019 19:33:27 +0200 Subject: [PATCH] Remove `__cache__`, `__pcache__` and related code. --- context.py | 4 --- context_play.py | 4 --- default.py | 4 --- resources/lib/database/__init__.py | 1 - resources/lib/downloader.py | 45 +---------------------------- resources/lib/entrypoint/service.py | 4 +-- resources/lib/helper/utils.py | 10 +++---- service.py | 11 ------- 8 files changed, 7 insertions(+), 76 deletions(-) diff --git a/context.py b/context.py index 5b3107f4..fb8ec9ee 100644 --- a/context.py +++ b/context.py @@ -14,11 +14,7 @@ import xbmcaddon __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') __libraries__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'libraries')).decode('utf-8') -__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'jellyfin')).decode('utf-8') -__cache__ = xbmc.translatePath('special://temp/jellyfin').decode('utf-8') -sys.path.insert(0, __cache__) -sys.path.insert(0, __pcache__) sys.path.insert(0, __libraries__) sys.path.append(__base__) diff --git a/context_play.py b/context_play.py index c59ce3dd..1c02d151 100644 --- a/context_play.py +++ b/context_play.py @@ -14,11 +14,7 @@ import xbmcaddon __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') __libraries__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'libraries')).decode('utf-8') -__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'jellyfin')).decode('utf-8') -__cache__ = xbmc.translatePath('special://temp/jellyfin').decode('utf-8') -sys.path.insert(0, __cache__) -sys.path.insert(0, __pcache__) sys.path.insert(0, __libraries__) sys.path.append(__base__) diff --git a/default.py b/default.py index d3ccbc89..2b592cc6 100644 --- a/default.py +++ b/default.py @@ -14,11 +14,7 @@ import xbmcaddon __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') __libraries__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'libraries')).decode('utf-8') -__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'jellyfin')).decode('utf-8') -__cache__ = xbmc.translatePath('special://temp/jellyfin').decode('utf-8') -sys.path.insert(0, __cache__) -sys.path.insert(0, __pcache__) sys.path.insert(0, __libraries__) sys.path.append(__base__) diff --git a/resources/lib/database/__init__.py b/resources/lib/database/__init__.py index 372318fd..a1ee9e6d 100644 --- a/resources/lib/database/__init__.py +++ b/resources/lib/database/__init__.py @@ -12,7 +12,6 @@ import xbmc import xbmcvfs import jellyfin_db -from helper.utils import delete_folder from helper import _, settings, window, dialog from objects import obj diff --git a/resources/lib/downloader.py b/resources/lib/downloader.py index 587cc57b..53efc1be 100644 --- a/resources/lib/downloader.py +++ b/resources/lib/downloader.py @@ -5,15 +5,10 @@ import logging import Queue import threading -import os import xbmc -import xbmcvfs -import xbmcaddon - import requests -from helper.utils import delete_folder -from helper import settings, stop, event, window, unzip, create_id +from helper import settings, stop, event, window, create_id from jellyfin import Jellyfin from jellyfin.core import api from jellyfin.core.exceptions import HTTPException @@ -22,7 +17,6 @@ from jellyfin.core.exceptions import HTTPException LOG = logging.getLogger("JELLYFIN."+__name__) LIMIT = min(int(settings('limitIndex') or 50), 50) -CACHE = xbmc.translatePath(os.path.join(xbmcaddon.Addon(id='plugin.video.jellyfin').getAddonInfo('profile').decode('utf-8'), 'jellyfin')).decode('utf-8') ################################################################################################# @@ -372,40 +366,3 @@ class TheVoid(object): xbmc.sleep(100) LOG.info("--[ void/%s ]", self.data['VoidName']) - - -def get_objects(src, filename): - - ''' Download objects dependency to temp cache folder. - ''' - temp = CACHE - restart = not xbmcvfs.exists(os.path.join(temp, "objects") + '/') - path = os.path.join(temp, filename).encode('utf-8') - - if restart and (settings('appliedPatch') or "") == filename: - - LOG.warn("Something went wrong applying this patch %s previously.", filename) - restart = False - - if not xbmcvfs.exists(path) or filename.startswith('DEV'): - delete_folder(CACHE) - - LOG.info("From %s to %s", src, path.decode('utf-8')) - try: - response = requests.get(src, stream=True, verify=True) - response.raise_for_status() - except requests.exceptions.SSLError as error: - - LOG.error(error) - response = requests.get(src, stream=True, verify=False) - - dl = xbmcvfs.File(path, 'w') - dl.write(response.content) - dl.close() - del response - - settings('appliedPatch', filename) - - unzip(path, temp, "objects") - - return restart diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index e393a59d..d2aa5dd1 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -17,10 +17,8 @@ import client import library import setup import monitor -import requests from views import Views, verify_kodi_defaults -from helper import _, window, settings, event, dialog, find, compare_version -from downloader import get_objects +from helper import _, window, settings, event, dialog, compare_version from jellyfin import Jellyfin from database import Database, jellyfin_db, reset diff --git a/resources/lib/helper/utils.py b/resources/lib/helper/utils.py index 546bdf01..18757878 100644 --- a/resources/lib/helper/utils.py +++ b/resources/lib/helper/utils.py @@ -277,13 +277,12 @@ def write_xml(content, file): content = content.replace('?>', ' standalone="yes" ?>', 1) infile.write(content) -def delete_folder(path=None): + +def delete_folder(path): ''' Delete objects from kodi cache ''' LOG.debug("--[ delete folder ]") - delete_path = path is not None - path = path or xbmc.translatePath('special://temp/jellyfin').decode('utf-8') dirs, files = xbmcvfs.listdir(path) delete_recursive(path, dirs) @@ -291,11 +290,11 @@ def delete_folder(path=None): for file in files: xbmcvfs.delete(os.path.join(path, file.decode('utf-8'))) - if delete_path: - xbmcvfs.delete(path) + xbmcvfs.delete(path) LOG.info("DELETE %s", path) + def delete_recursive(path, dirs): ''' Delete files and dirs recursively. @@ -309,6 +308,7 @@ def delete_recursive(path, dirs): delete_recursive(os.path.join(path, directory.decode('utf-8')), dirs2) xbmcvfs.rmdir(os.path.join(path, directory.decode('utf-8'))) + def unzip(path, dest, folder=None): ''' Unzip file. zipfile module seems to fail on android with badziperror. diff --git a/service.py b/service.py index 1176e314..95e28085 100644 --- a/service.py +++ b/service.py @@ -8,7 +8,6 @@ import threading import sys import xbmc -import xbmcvfs import xbmcaddon ################################################################################################# @@ -16,18 +15,8 @@ import xbmcaddon __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') __libraries__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'libraries')).decode('utf-8') -__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'jellyfin')).decode('utf-8') -__cache__ = xbmc.translatePath('special://temp/jellyfin').decode('utf-8') sys.path.insert(0, __libraries__) - -if not xbmcvfs.exists(__pcache__ + '/'): - from resources.lib.helper.utils import copytree - - copytree(os.path.join(__base__, 'objects'), os.path.join(__pcache__, 'objects')) - -sys.path.insert(0, __cache__) -sys.path.insert(0, __pcache__) sys.path.append(__base__) #################################################################################################