Skip to content

Commit e5bc154

Browse files
authored
Remove the store function. http_download now returns the download path. (#562)
1 parent af6adc1 commit e5bc154

File tree

5 files changed

+20
-37
lines changed

5 files changed

+20
-37
lines changed

lib/inputstreamhelper/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .kodiutils import (addon_version, browsesingle, delete, exists, get_proxies, get_setting, get_setting_bool, get_setting_float, get_setting_int, jsonrpc,
1111
kodi_to_ascii, kodi_version, listdir, localize, log, notification, ok_dialog, progress_dialog, select_dialog,
1212
set_setting, set_setting_bool, textviewer, translate_path, yesno_dialog)
13-
from .utils import arch, download_path, http_download, parse_version, remove_tree, store, system_os, temp_path, unzip, userspace64
13+
from .utils import arch, download_path, http_download, parse_version, remove_tree, system_os, temp_path, unzip, userspace64
1414
from .widevine.arm import dl_extract_widevine_chromeos, extract_widevine_chromeos, install_widevine_arm
1515
from .widevine.arm_lacros import cdm_from_lacros, latest_lacros
1616
from .widevine.widevine import (backup_path, has_widevinecdm, ia_cdm_path,
@@ -189,16 +189,15 @@ def _install_widevine_from_repo(bpath, choose_version=False):
189189
return cdm
190190

191191
cdm_version = cdm.get('version')
192+
dl_path = download_path(cdm.get('url'))
192193

193-
if not exists(download_path(cdm.get('url'))):
194-
downloaded = http_download(cdm.get('url'))
195-
else:
196-
downloaded = True
194+
if not exists(dl_path):
195+
dl_path = http_download(cdm.get('url'))
197196

198-
if downloaded:
197+
if dl_path:
199198
progress = progress_dialog()
200199
progress.create(heading=localize(30043), message=localize(30044)) # Extracting Widevine CDM
201-
unzip(store('download_path'), os.path.join(bpath, cdm_version, ''))
200+
unzip(dl_path, os.path.join(bpath, cdm_version, ''))
202201

203202
return (progress, cdm_version)
204203

lib/inputstreamhelper/utils.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
211211
else:
212212
return False
213213

214-
store('download_path', dl_path)
215-
return True
214+
return dl_path
216215

217216

218217
def unzip(source, destination, file_to_unzip=None, result=[]): # pylint: disable=dangerous-default-value
@@ -256,19 +255,6 @@ def system_os():
256255
return sys_name
257256

258257

259-
def store(name, val=None):
260-
"""Store arbitrary value across functions"""
261-
262-
if val is not None:
263-
setattr(store, name, val)
264-
log(0, 'Stored {} in {}'.format(val, name))
265-
return val
266-
267-
if not hasattr(store, name):
268-
return None
269-
return getattr(store, name)
270-
271-
272258
def diskspace():
273259
"""Return the free disk space available (in bytes) in temp_path."""
274260
statvfs = os.statvfs(compat_path(temp_path()))

lib/inputstreamhelper/widevine/arm.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .. import config
1010
from ..kodiutils import browsesingle, localize, log, ok_dialog, open_file, progress_dialog, yesno_dialog
11-
from ..utils import diskspace, http_download, http_get, parse_version, sizeof_fmt, store, system_os, update_temp_path, userspace64
11+
from ..utils import diskspace, http_download, http_get, parse_version, sizeof_fmt, system_os, update_temp_path, userspace64
1212
from .arm_chromeos import ChromeOSImage
1313
from .arm_lacros import cdm_from_lacros, install_widevine_arm_lacros
1414

@@ -111,19 +111,17 @@ def install_widevine_arm_chromeos(backup_path):
111111
def dl_extract_widevine_chromeos(url, backup_path, arm_device=None):
112112
"""Download the ChromeOS image and extract Widevine from it"""
113113
if arm_device:
114-
downloaded = http_download(url, message=localize(30022), checksum=arm_device['sha1'], hash_alg='sha1',
114+
dl_path = http_download(url, message=localize(30022), checksum=arm_device['sha1'], hash_alg='sha1',
115115
dl_size=int(arm_device['zipfilesize'])) # Downloading the recovery image
116116
image_version = arm_device['version']
117117
else:
118-
downloaded = http_download(url, message=localize(30022))
118+
dl_path = http_download(url, message=localize(30022))
119119
image_version = os.path.basename(url).split('_')[1]
120120
# minimal info for config.json, "version" is definitely needed e.g. in load_widevine_config:
121121
arm_device = {"file": os.path.basename(url), "url": url, "version": image_version}
122122

123-
if downloaded:
124-
image_path = store('download_path')
125-
126-
progress = extract_widevine_chromeos(backup_path, image_path, image_version)
123+
if dl_path:
124+
progress = extract_widevine_chromeos(backup_path, dl_path, image_version)
127125
if not progress:
128126
return False
129127

lib/inputstreamhelper/widevine/arm_lacros.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .repo import cdm_from_repo
1010
from .. import config
1111
from ..kodiutils import exists, localize, log, mkdirs, open_file, progress_dialog
12-
from ..utils import http_download, http_get, store, system_os, userspace64
12+
from ..utils import http_download, http_get, system_os, userspace64
1313
from ..unsquash import SquashFs
1414

1515

@@ -67,10 +67,10 @@ def install_widevine_arm_lacros(backup_path, img_version=None):
6767

6868
url = config.LACROS_DOWNLOAD_URL.format(version=img_version, arch=("arm64" if userspace64() else "arm"))
6969

70-
downloaded = http_download(url, message=localize(30072))
70+
dl_path = http_download(url, message=localize(30072))
7171

72-
if downloaded:
73-
progress = extract_widevine_lacros(store("download_path"), backup_path, img_version)
72+
if dl_path:
73+
progress = extract_widevine_lacros(dl_path, backup_path, img_version)
7474
if progress:
7575
return (progress, img_version)
7676

lib/inputstreamhelper/widevine/widevine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .. import config
1010
from ..kodiutils import (addon_profile, exists, get_setting_int, listdir, localize, log, mkdirs,
1111
ok_dialog, open_file, set_setting, translate_path, yesno_dialog)
12-
from ..utils import arch, cmd_exists, hardlink, http_download, parse_version, remove_tree, run_cmd, store, system_os
12+
from ..utils import arch, cmd_exists, hardlink, http_download, parse_version, remove_tree, run_cmd, system_os
1313
from ..unicodes import compat_path, to_unicode
1414
from .arm_lacros import cdm_from_lacros, latest_lacros
1515
from .repo import cdm_from_repo, latest_widevine_available_from_repo
@@ -42,12 +42,12 @@ def widevine_eula():
4242
cdm_arch = 'x64'
4343

4444
url = config.WIDEVINE_DOWNLOAD_URL.format(version=cdm_version, os=cdm_os, arch=cdm_arch)
45-
downloaded = http_download(url, message=localize(30025), background=True) # Acquiring EULA
46-
if not downloaded:
45+
dl_path = http_download(url, message=localize(30025), background=True) # Acquiring EULA
46+
if not dl_path:
4747
return False
4848

4949
from zipfile import ZipFile
50-
with ZipFile(compat_path(store('download_path'))) as archive:
50+
with ZipFile(compat_path(dl_path)) as archive:
5151
with archive.open(config.WIDEVINE_LICENSE_FILE) as file_obj:
5252
eula = file_obj.read().decode().strip().replace('\n', ' ')
5353

0 commit comments

Comments
 (0)