Skip to content

Commit

Permalink
Possibility to change temporary path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
horstle committed Sep 9, 2019
1 parent c174bf2 commit f318760
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/inputstreamhelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -297,3 +300,6 @@ msgctxt "#30907"
msgid "Remove Widevine CDM library..."
msgstr ""

msgctxt "#30909"
msgid "Custom Path"
msgstr ""
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<setting label="30904" type="text" enable="false"/> <!-- disabled_warning -->
<setting label="30905" help="30906" type="action" id="install_widevine" action="RunScript(script.module.inputstreamhelper, widevine_install)" enable="eq(-2,false)" visible="!system.platform.android"/>
<setting label="30907" help="30908" type="action" id="remove_widevine" action="RunScript(script.module.inputstreamhelper, widevine_remove)" enable="eq(-3,false)" visible="!system.platform.android"/>
<setting label="30909" type="folder" id="custom_temp_dir" source="" option="writeable"/>
</category>
</settings>
5 changes: 5 additions & 0 deletions test/xbmcgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '''
Expand Down

0 comments on commit f318760

Please # to comment.