From f318760257c00a453af2d7270a52c1531cf2aea1 Mon Sep 17 00:00:00 2001 From: horstle Date: Tue, 17 Apr 2018 20:38:33 +0200 Subject: [PATCH] Possibility to change temporary path. Add possibility to change temporary path on ARM devices if the ChromeOS image is too big. Remember custom path (as setting), check specified custom path whether there is enough space. --- lib/inputstreamhelper/__init__.py | 25 +++++++++++++++---- .../resource.language.en_gb/strings.po | 6 +++++ resources/settings.xml | 1 + test/xbmcgui.py | 5 ++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/inputstreamhelper/__init__.py b/lib/inputstreamhelper/__init__.py index 4a74d0df..2cd55bfe 100644 --- a/lib/inputstreamhelper/__init__.py +++ b/lib/inputstreamhelper/__init__.py @@ -133,7 +133,11 @@ def _diskspace(cls): @classmethod def _temp_path(cls): ''' Return temporary path, usually ~/.kodi/userdata/addon_data/tmp ''' - temp_path = os.path.join(ADDON_PROFILE, 'tmp') + cust_temp_dir = ADDON.getSetting('custom_temp_dir') + if xbmcvfs.exists(cust_temp_dir): + temp_path = os.path.join(cust_temp_dir, 'tmp') + else: + temp_path = os.path.join(ADDON_PROFILE, 'tmp') if not xbmcvfs.exists(temp_path): xbmcvfs.mkdir(temp_path) @@ -226,6 +230,13 @@ def _cmd_exists(cmd): # https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python return subprocess.call('type ' + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 + def _update_temp_path(self, new_temp_path): + """"Updates temp_path and merges files.""" + old_temp_path = self._temp_path() + + ADDON.setSetting('custom_temp_dir', new_temp_path) + shutil.move(old_temp_path, new_temp_path) + def _helper_disabled(self): """Return if inputstreamhelper has been disabled in settings.xml.""" disabled = ADDON.getSetting('disabled') @@ -637,10 +648,14 @@ def _install_widevine_arm(self): # pylint: disable=too-many-statements xbmcgui.Dialog().ok(localize(30004), localize(30019, os=system_os())) return False - if required_diskspace >= self._diskspace(): - xbmcgui.Dialog().ok(localize(30004), # Not enough free disk space - localize(30018, diskspace=self._sizeof_fmt(required_diskspace))) - return False + while required_diskspace >= self._diskspace(): + if xbmcgui.Dialog().yesno(localize(30004), localize(30055)): # not enough space, alternative path? + self._update_temp_path(xbmcgui.Dialog().browseSingle(3, localize(30909), 'files')) # temporary path + continue + else: + xbmcgui.Dialog().ok(localize(30004), # Not enough free disk space + localize(30018, diskspace=self._sizeof_fmt(required_diskspace))) + return False if not self._cmd_exists('fdisk') and not self._cmd_exists('parted'): xbmcgui.Dialog().ok(localize(30004), localize(30020, command1='fdisk', command2='parted')) # Commands are missing diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 8c1e6922..c45d7634 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -225,6 +225,9 @@ msgctxt "#30054" msgid "disabled" msgstr "" +msgctxt "#30055" +msgid "You do not have enough free disk space to install [B]Widevine CDM[/B] or your specified custom path does not exist anymore or hasn't got enough disk space either. Would you like to specify a (different) custom path to temporarily use for the Chrome OS Recovery Image (e.g. on a USB)?" +msgstr "" ### INFORMATION DIALOG msgctxt "#30800" @@ -297,3 +300,6 @@ msgctxt "#30907" msgid "Remove Widevine CDM library..." msgstr "" +msgctxt "#30909" +msgid "Custom Path" +msgstr "" diff --git a/resources/settings.xml b/resources/settings.xml index 43337a0e..33ff89da 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -9,5 +9,6 @@ + diff --git a/test/xbmcgui.py b/test/xbmcgui.py index b1838693..37591789 100644 --- a/test/xbmcgui.py +++ b/test/xbmcgui.py @@ -44,6 +44,11 @@ def textviewer(heading, text=None, usemono=None): text = kodi_to_ansi(text) print('\033[37;100mTEXTVIEWER:\033[35;0m [%s]\n\033[35;0m%s\033[39;0m' % (heading, text)) + @staticmethod + def browseSingle(atype, heading, shares, mask=None, useThumbs=None, treatAsFolder=None, default=None): + ''' A stub implementation for the xbmcgui Dialog class browseSingle() method ''' + print('BROWSESINGLE: [%s] %s' % (atype, heading)) + return '~/.kodi/userdata/addon_data/script.module.inputstreamhelper' class DialogProgress: ''' A reimplementation of the xbmcgui DialogProgress '''