Skip to content

Commit 9476c79

Browse files
Some methods are classmethods
1 parent c19f726 commit 9476c79

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

lib/inputstreamhelper.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717

1818
class Helper(object):
19+
_addon = xbmcaddon.Addon('script.module.inputstreamhelper')
20+
_addon_profile = xbmc.translatePath(_addon.getAddonInfo('profile'))
21+
_language = _addon.getLocalizedString
22+
1923
def __init__(self, protocol, drm=None):
20-
self._addon = xbmcaddon.Addon('script.module.inputstreamhelper')
21-
self._addon_profile = xbmc.translatePath(self._addon.getAddonInfo('profile'))
22-
self._language = self._addon.getLocalizedString
2324
self._os = platform.system()
2425
self._log('Platform information: {0}'.format(platform.uname()))
2526

@@ -43,6 +44,7 @@ def __init__(self, protocol, drm=None):
4344
else:
4445
self.drm = config.DRM_SCHEMES[drm]
4546

47+
4648
class InputStreamException(Exception):
4749
pass
4850

@@ -62,50 +64,38 @@ def _cmd_exists(cmd):
6264
# https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
6365
return subprocess.call('type ' + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
6466

65-
def _arch(self):
66-
"""Map together and return the system architecture."""
67-
arch = platform.machine()
68-
if arch in config.X86_MAP:
69-
return config.X86_MAP[arch]
70-
elif 'armv' in arch:
71-
arm_arch = 'armv' + arch.split('v')[1][:-1]
72-
return arm_arch
73-
74-
return arch
75-
76-
def _log(self, string):
77-
"""InputStream Helper log method."""
78-
logging_prefix = '[{0}-{1}]'.format(self._addon.getAddonInfo('id'), self._addon.getAddonInfo('version'))
79-
msg = '{0}: {1}'.format(logging_prefix, string)
80-
xbmc.log(msg=msg, level=xbmc.LOGDEBUG)
81-
82-
def _diskspace(self):
67+
@classmethod
68+
def _diskspace(cls):
8369
"""Return the free disk space available (in bytes) in cdm_path."""
84-
statvfs = os.statvfs(self._cdm_path())
70+
statvfs = os.statvfs(cls._cdm_path())
8571
return statvfs.f_frsize * statvfs.f_bavail
8672

87-
def _temp_path(self):
88-
temp_path = os.path.join(self._addon_profile, 'tmp')
73+
@classmethod
74+
def _temp_path(cls):
75+
temp_path = os.path.join(cls._addon_profile, 'tmp')
8976
if not xbmcvfs.exists(temp_path):
9077
xbmcvfs.mkdir(temp_path)
9178

9279
return temp_path
9380

94-
def _mnt_path(self):
95-
mnt_path = os.path.join(self._temp_path(), 'mnt')
81+
@classmethod
82+
def _mnt_path(cls):
83+
mnt_path = os.path.join(cls._temp_path(), 'mnt')
9684
if not xbmcvfs.exists(mnt_path):
9785
xbmcvfs.mkdir(mnt_path)
9886

9987
return mnt_path
10088

101-
def _cdm_path(self):
102-
cdm_path = os.path.join(self._addon_profile, 'cdm')
89+
@classmethod
90+
def _cdm_path(cls):
91+
cdm_path = os.path.join(cls._addon_profile, 'cdm')
10392
if not xbmcvfs.exists(cdm_path):
10493
xbmcvfs.mkdir(cdm_path)
10594

10695
return cdm_path
10796

108-
def _ia_cdm_path(self):
97+
@classmethod
98+
def _ia_cdm_path(cls):
10999
"""Return the specified CDM path for inputstream.adaptive."""
110100
addon = xbmcaddon.Addon('inputstream.adaptive')
111101
cdm_path = xbmc.translatePath(addon.getSetting('DECRYPTERPATH'))
@@ -114,14 +104,32 @@ def _ia_cdm_path(self):
114104

115105
return cdm_path
116106

117-
def _kodi_version(self):
107+
@classmethod
108+
def _kodi_version(cls):
118109
version = xbmc.getInfoLabel('System.BuildVersion')
119110
return version.split(' ')[0]
120111

121112
def _inputstream_version(self):
122113
addon = xbmcaddon.Addon(self._inputstream_addon)
123114
return addon.getAddonInfo('version')
124115

116+
def _arch(self):
117+
"""Map together and return the system architecture."""
118+
arch = platform.machine()
119+
if arch in config.X86_MAP:
120+
return config.X86_MAP[arch]
121+
elif 'armv' in arch:
122+
arm_arch = 'armv' + arch.split('v')[1][:-1]
123+
return arm_arch
124+
125+
return arch
126+
127+
def _log(self, string):
128+
"""InputStream Helper log method."""
129+
logging_prefix = '[{0}-{1}]'.format(self._addon.getAddonInfo('id'), self._addon.getAddonInfo('version'))
130+
msg = '{0}: {1}'.format(logging_prefix, string)
131+
xbmc.log(msg=msg, level=xbmc.LOGDEBUG)
132+
125133
def _parse_chromeos_offset(self, bin_path):
126134
"""Calculate the Chrome OS losetup start offset using fdisk/parted."""
127135
if self._cmd_exists('fdisk'):

0 commit comments

Comments
 (0)