Skip to content

Commit

Permalink
Optimize file operations (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Jun 21, 2020
1 parent f235fd5 commit b0120b4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/inputstreamhelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _install_widevine_x86(bpath):
if downloaded:
progress = progress_dialog()
progress.create(heading=localize(30043), message=localize(30044)) # Extracting Widevine CDM
unzip(store('download_path'), os.path.join(bpath, cdm_version))
unzip(store('download_path'), os.path.join(bpath, cdm_version, ''))

return (progress, cdm_version)

Expand Down
1 change: 1 addition & 0 deletions lib/inputstreamhelper/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def delete(path):

def exists(path):
"""Whether the path exists (using xbmcvfs)"""
# File or folder (folder must end with slash or backslash)
from xbmcvfs import exists as vfsexists
return vfsexists(from_unicode(path))

Expand Down
4 changes: 2 additions & 2 deletions lib/inputstreamhelper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


def temp_path():
"""Return temporary path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp"""
tmp_path = translate_path(os.path.join(get_setting('temp_path', 'special://masterprofile/addon_data/script.module.inputstreamhelper'), 'temp'))
"""Return temporary path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/"""
tmp_path = translate_path(os.path.join(get_setting('temp_path', 'special://masterprofile/addon_data/script.module.inputstreamhelper'), 'temp', ''))
if not exists(tmp_path):
mkdirs(tmp_path)

Expand Down
10 changes: 5 additions & 5 deletions lib/inputstreamhelper/widevine/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from .arm_chromeos import ChromeOSImage


def mnt_path():
"""Return mount path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/mnt"""
mount_path = os.path.join(temp_path(), 'mnt')
if not exists(mount_path):
def mnt_path(make=True):
"""Return mount path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/mnt/"""
mount_path = os.path.join(temp_path(), 'mnt', '')
if make and not exists(mount_path):
mkdir(mount_path)

return mount_path
Expand Down Expand Up @@ -294,7 +294,7 @@ def extract_widevine_from_img(backup_path):

def unmount():
"""Unmount mountpoint if mounted"""
while os.path.ismount(compat_path(mnt_path())):
while os.path.ismount(compat_path(mnt_path(make=False))):
log(0, 'Unmount {mountpoint}', mountpoint=mnt_path())
umount_output = run_cmd(['umount', compat_path(mnt_path())], sudo=True)
if not umount_output['success']:
Expand Down
5 changes: 3 additions & 2 deletions lib/inputstreamhelper/widevine/arm_chromeos.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ def write_file(self, inode_dict, filepath):
block_ids_sorted.sort()
block_dict = self.read_file(block_ids_sorted)

if not exists(os.path.dirname(filepath)):
mkdirs(os.path.dirname(filepath))
write_dir = os.path.join(os.path.dirname(filepath), '')
if not exists(write_dir):
mkdirs(write_dir)

with open(compat_path(filepath), 'wb') as opened_file:
for block_id in block_ids:
Expand Down
4 changes: 2 additions & 2 deletions lib/inputstreamhelper/widevine/widevine.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def widevine_eula():

def backup_path():
"""Return the path to the cdm backups"""
path = os.path.join(addon_profile(), 'backup')
path = os.path.join(addon_profile(), 'backup', '')
if not exists(path):
mkdirs(path)
return path
Expand Down Expand Up @@ -111,7 +111,7 @@ def ia_cdm_path():
except RuntimeError:
return None

cdm_path = translate_path(to_unicode(addon.getSetting('DECRYPTERPATH')))
cdm_path = translate_path(os.path.join(to_unicode(addon.getSetting('DECRYPTERPATH')), ''))
if not exists(cdm_path):
mkdirs(cdm_path)

Expand Down

0 comments on commit b0120b4

Please sign in to comment.