def iptv_execute(self, cmd): printDBG("iptv_execute cmd_exec [%s]" % cmd) ret = iptv_execute(1)(cmd) printDBG( "iptv_execute cmd_ret sts[%s] code[%s] data[%s]" % (ret.get('sts', ''), ret.get('code', ''), ret.get('data', ''))) return ret
def _getPageWget(self, url, params={}, post_data=None): cmd = DMHelper.getBaseWgetCmd(params.get('header', {})) + (" '%s' " % url) if post_data != None: if params.get('raw_post_data', False): post_data_str = post_data else: post_data_str = urllib.urlencode(post_data) cmd += " --post-data '{0}' ".format(post_data_str) if params.get('use_cookie', False): cmd += " --keep-session-cookies " cookieFile = str(params.get('cookiefile', '')) if params.get('load_cookie', False) and fileExists(cookieFile): cmd += " --load-cookies '%s' " % cookieFile if params.get('save_cookie', False): cmd += " --save-cookies '%s' " % cookieFile cmd += ' -O - 2> /dev/null' printDBG('_getPageWget request: [%s]' % cmd) data = iptv_execute()( cmd ) if not data['sts'] or 0 != data['code']: return False, None else: return True, data['data']
def duktape_execute(cmd_params): ret = {'sts': False, 'code': -12, 'data': ''} noDuk = False cmd = GetDukPath() if cmd != '': cmd += ' ' + cmd_params + ' 2> /dev/null' printDBG("duktape_execute cmd[%s]" % cmd) ret = iptv_execute()(cmd) if ret['code'] == 127: noDuk = True else: noDuk = True ret['code'] = 127 if noDuk: messages = [ _('The %s utility is necessary here but it was not detected.') % ('duktape') ] messages.append( _('Please consider restarting your Engima2 and agree to install the %s utlity when %s asks.' ) % ('duktape', 'E2iStream')) GetIPTVNotify().push('\n'.join(messages), 'error', 40, 'no_duktape', 40) printDBG('duktape_execute cmd ret[%s]' % ret) return ret
def iptv_execute_wrapper(cmd): printDBG("LocalMedia.iptv_execute_wrapper cmd[%r]" % cmd) obj = iptv_execute() ret = obj(cmd) obj = None printDBG("LocalMedia.iptv_execute_wrapper ret[%r]" % ret) return ret
def listDir(self, cItem): printDBG("LocalMedia.listDir [%s]" % cItem) page = cItem.get('page', 0) start = cItem.get('start', 0) end = start + config.plugins.iptvplayer.local_maxitems.value cItem = dict(cItem) cItem['start'] = 0 path = cItem['path'] cmd = self.prepareCmd(path, start, end + 1) + ' 2>&1' printDBG("cmd [%s]" % cmd) ret = iptv_execute()(cmd) printDBG(ret) if ret['sts'] and 0 == ret['code']: self.setCurrDir(path) data = ret['data'].split('\n') dirTab = [] m3uTab = [] vidTab = [] audTab = [] picTab = [] for item in data: start += 1 if start > end: break item = item.split('//') if 4 != len(item): continue if 'd' == item[1]: dirTab.append(item[0]) elif 'r': ext = self.getExtension(item[0]) if ext in self.M3U_FILES_EXTENSIONS: m3uTab.append(item[0]) elif ext in self.VIDEO_FILE_EXTENSIONS: vidTab.append(item[0]) elif ext in self.AUDIO_FILES_EXTENSIONS: audTab.append(item[0]) elif ext in self.PICTURE_FILES_EXTENSIONS: picTab.append(item[0]) self.addFromTab(cItem, dirTab, path, 'dir') self.addFromTab(cItem, m3uTab, path, 'm3u', 1) self.addFromTab(cItem, vidTab, path, 'video') self.addFromTab(cItem, audTab, path, 'audio') self.addFromTab(cItem, picTab, path, 'picture') if start > end: params = dict(cItem) params.update({ 'category': 'more', 'title': _('More'), 'start': end }) self.addMore(params)
def listIso(self, cItem): printDBG("LocalMedia.listIso [%s]" % cItem) # check if iso file is mounted path = cItem['path'] defaultMountPoint = GetTmpDir(self.ISO_MOUNT_POINT_NAME) defaultMountPoint = defaultMountPoint.replace('//', '/') mountPoint = self.getMountPoint(path) if '' == mountPoint: # umount if different image already mounted if self.isMountPoint(defaultMountPoint): cmd = 'umount "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts'] and 0 != ret['code']: # normal umount failed, so detach filesystem only cmd = 'umount -l "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) # now mount the iso file if not mkdirs(defaultMountPoint): message = _('Make directory [%s]') % (defaultMountPoint) self.showErrorMessage(message) return else: cmd = 'mount -r "{0}" "{1}"'.format(path, defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts']: if 0 != ret['code']: message = _('Mount ISO file [%s] on [%s] failed.\nReturn code[%s].\nReturn data[%s].') % (path, defaultMountPoint, ret['code'], ret['data']) self.showErrorMessage(message) return else: mountPoint = defaultMountPoint if '' != mountPoint: params = dict(cItem) params.update( {'path':mountPoint, 'category':'dir'} ) self.listDir(params)
def listIso(self, cItem): printDBG("LocalMedia.listIso [%s]" % cItem) # check if iso file is mounted path = cItem['path'] defaultMountPoint = GetTmpDir(self.ISO_MOUNT_POINT_NAME) defaultMountPoint = defaultMountPoint.replace('//', '/') mountPoint = self.getMountPoint(path) if '' == mountPoint: # umount if different image already mounted if self.isMountPoint(defaultMountPoint): cmd = 'umount "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts'] and 0 != ret['code']: # normal umount failed, so detach filesystem only cmd = 'umount -l "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) # now mount the iso file if not mkdirs(defaultMountPoint): message = _('Make directory [%s]') % (defaultMountPoint) self.showErrorMessage(message) return else: cmd = 'mount -r "{0}" "{1}"'.format(path, defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts']: if 0 != ret['code']: message = _('Mount ISO file [%s] on [%s] failed.\nReturn code[%s].\nReturn data[%s].') % (path, defaultMountPoint, ret['code'], ret['data']) self.showErrorMessage(message) return else: mountPoint = defaultMountPoint if '' != mountPoint: params = dict(cItem) params.update( {'path':mountPoint, 'category':'dir'} ) self.listDir(params)
def listDir(self, cItem): printDBG("LocalMedia.listDir [%s]" % cItem) page = cItem.get('page', 0) start = cItem.get('start', 0) end = start + config.plugins.iptvplayer.local_maxitems.value cItem = dict(cItem) cItem['start'] = 0 path = cItem['path'] cmd = self.prepareCmd(path, start, end+1) + ' 2>&1' printDBG("cmd [%s]" % cmd) ret = iptv_execute()(cmd) printDBG(ret) if ret['sts'] and 0 == ret['code']: self.setCurrDir(path) data = ret['data'].split('\n') dirTab = [] m3uTab = [] vidTab = [] audTab = [] picTab = [] for item in data: start += 1 if start > end: break item = item.split('//') if 4 != len(item): continue if 'd' == item[1]: dirTab.append(item[0]) elif 'r': ext = self.getExtension(item[0]) if ext in self.M3U_FILES_EXTENSIONS: m3uTab.append(item[0]) elif ext in self.VIDEO_FILE_EXTENSIONS: vidTab.append(item[0]) elif ext in self.AUDIO_FILES_EXTENSIONS: audTab.append(item[0]) elif ext in self.PICTURE_FILES_EXTENSIONS: picTab.append(item[0]) self.addFromTab(cItem, dirTab, path, 'dir') self.addFromTab(cItem, m3uTab, path, 'm3u', 1) self.addFromTab(cItem, vidTab, path, 'video') self.addFromTab(cItem, audTab, path, 'audio') self.addFromTab(cItem, picTab, path, 'picture') if start > end: params = dict(cItem) params.update({'category':'more', 'title':_('More'), 'start':end}) self.addMore(params)
def getPageWithWget(self, url, params={}, post_data=None): from Plugins.Extensions.IPTVPlayer.iptvdm.iptvdh import DMHelper cmd = DMHelper.getBaseWgetCmd(params.get('header', {})) + (" '%s' " % url) if post_data != None: if params.get('raw_post_data', False): post_data_str = post_data else: post_data_str = urllib.urlencode(post_data) cmd += " --post-data '{0}' ".format(post_data_str) if params.get('use_cookie', False): cmd += " --keep-session-cookies " cookieFile = str(params.get('cookiefile', '')) if params.get('load_cookie', False) and fileExists(cookieFile): cmd += " --load-cookies '%s' " % cookieFile if params.get('save_cookie', False): cmd += " --save-cookies '%s' " % cookieFile cmd += ' -O - 2> /dev/null' printDBG('_getPageWget request: [%s]' % cmd) from Plugins.Extensions.IPTVPlayer.components.asynccall import iptv_execute data = iptv_execute()(cmd) if params.get('use_cookie', False) and params.get( 'save_cookie', False) and fileExists(cookieFile): # fix cookie try: f = open(cookieFile, "r") cookieStr = f.read() f.close() marker = '# HTTP cookie file.' if cookieStr.startswith(marker): cookieStr = cookieStr.replace(marker, '# HTTP Cookie File.') f = open(cookieFile, "w") f.write(cookieStr) f.close() except Exception: printExc() if not data['sts'] or 0 != data['code']: return False, None else: return True, data['data']
def getMountsTable(self, silen=False): table = [] cmd = 'mount 2>&1' ret = iptv_execute()(cmd) if ret['sts']: data = ret.get('data', '') if 0 == ret['code']: data = data.split('\n') for line in data: item = self.cm.ph.getSearchGroups(line, '(.+?) on (.+?) type ([^ ]+?) ', 3) if len(item) < 3: continue table.append({'device':item[0], 'node':item[1], 'filesystem':item[2]}) else: message = _('Can not get mount points - cmd mount failed.\nReturn code[%s].\nReturn data[%s].') % (ret['code'], data) return table
def getMountsTable(self, silen=False): table = [] cmd = 'mount 2>&1' ret = iptv_execute()(cmd) if ret['sts']: data = ret.get('data', '') if 0 == ret['code']: data = data.split('\n') for line in data: item = self.cm.ph.getSearchGroups(line, '(.+?) on (.+?) type ([^ ]+?) ', 3) if len(item) < 3: continue table.append({'device':item[0], 'node':item[1], 'filesystem':item[2]}) else: message = _('Can not get mount points - cmd mount failed.\nReturn code[%s].\nReturn data[%s].') % (ret['code'], data) return table
def performCustomAction(self, privateData): retCode = RetHost.ERROR retlist = [] if privateData['action'] == 'remove_file': try: ret = self.host.sessionEx.waitForFinishOpen( MessageBox, text=_('Are you sure you want to remove file "%s"?') % privateData['file_path'], type=MessageBox.TYPE_YESNO, default=False) if ret[0]: os_remove(privateData['file_path']) retlist = ['refresh'] retCode = RetHost.OK except: printExc() if privateData['action'] == 'rename_file': try: path, fileName = os_path.split(privateData['file_path']) name, ext = os_path.splitext(fileName) ret = self.host.sessionEx.waitForFinishOpen( VirtualKeyBoard, title=_('Set file name'), text=name) printDBG('rename_file new name[%s]' % ret) if isinstance(ret[0], basestring): newPath = os_path.join(path, ret[0] + ext) printDBG('rename_file new path[%s]' % newPath) if not os_path.isfile(newPath) and not os_path.islink( newPath): os_rename(privateData['file_path'], newPath) retlist = ['refresh'] retCode = RetHost.OK else: retlist = [_('File "%s" already exists!') % newPath] except: printExc() elif privateData['action'] == 'cut_file': self.cFilePath = privateData['file_path'] self.cType = 'cut' retCode = RetHost.OK elif privateData['action'] == 'copy_file': self.cFilePath = privateData['file_path'] self.cType = 'copy' retCode = RetHost.OK elif privateData['action'] == 'paste_file': try: ok = True cutPath, cutFileName = os_path.split(self.cFilePath) newPath = os_path.join(privateData['path'], cutFileName) if os_path.isfile(newPath): retlist = [_('File "%s" already exists') % newPath] ok = False else: if self.cType == 'cut': os_rename(self.cFilePath, newPath) self.needRefresh = cutPath elif self.cType == 'copy': cmd = 'cp "%s" "%s"' % (self.cFilePath, newPath) ret = iptv_execute()(cmd) if ok: self.cType = '' self.cFilePath = '' retlist = ['refresh'] retCode = RetHost.OK except: printExc() return RetHost(retCode, value=retlist)
def iptv_execute(self, cmd): return iptv_execute(1)(cmd)
def performCustomAction(self, privateData): retCode = RetHost.ERROR retlist = [] if privateData['action'] == 'remove_file': try: ret = self.host.sessionEx.waitForFinishOpen(MessageBox, text=_('Are you sure you want to remove file "%s"?') % privateData['file_path'], type=MessageBox.TYPE_YESNO, default=False) if ret[0]: os_remove(privateData['file_path']) retlist = ['refresh'] retCode = RetHost.OK except: printExc() if privateData['action'] == 'rename_file': try: path, fileName = os_path.split(privateData['file_path']) name, ext = os_path.splitext(fileName) ret = self.host.sessionEx.waitForFinishOpen(VirtualKeyBoard, title=_('Set file name'), text=name) printDBG('rename_file new name[%s]' % ret) if isinstance(ret[0], basestring): newPath = os_path.join(path, ret[0] + ext) printDBG('rename_file new path[%s]' % newPath) if not os_path.isfile(newPath) and not os_path.islink(newPath): os_rename(privateData['file_path'], newPath) retlist = ['refresh'] retCode = RetHost.OK else: retlist = [_('File "%s" already exists!') % newPath] except: printExc() elif privateData['action'] == 'cut_file': self.cFilePath = privateData['file_path'] self.cType = 'cut' retCode = RetHost.OK elif privateData['action'] == 'copy_file': self.cFilePath = privateData['file_path'] self.cType = 'copy' retCode = RetHost.OK elif privateData['action'] == 'paste_file': try: ok = True cutPath, cutFileName = os_path.split(self.cFilePath) newPath = os_path.join(privateData['path'], cutFileName) if os_path.isfile(newPath): retlist = [_('File "%s" already exists') % newPath] ok = False else: if self.cType == 'cut': os_rename(self.cFilePath, newPath) self.needRefresh = cutPath elif self.cType == 'copy': cmd = 'cp "%s" "%s"' % (self.cFilePath, newPath) ret = iptv_execute()(cmd) if ok: self.cType = '' self.cFilePath = '' retlist = ['refresh'] retCode = RetHost.OK except: printExc() elif privateData['action'] == 'umount_iso_file': cmd = 'umount "{0}"'.format(privateData['iso_mount_path']) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts'] and 0 != ret['code']: # normal umount failed, so detach filesystem only cmd = 'umount -l "{0}"'.format(privateData['iso_mount_path']) + ' 2>&1' ret = iptv_execute()(cmd) return RetHost(retCode, value=retlist)