def getDriverInstalledDate(): def extractDate(value): match = search('[0-9]{8}', value) if match: return match[0] else: return value filenames = glob("/var/lib/opkg/info/*dvb-modules*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return extractDate(line) filenames = glob("/var/lib/opkg/info/*dvb-proxy*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return extractDate(line) filenames = glob("/var/lib/opkg/info/*platform-util*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return extractDate(line) return _("Unknown")
def readSlotInfo(self, path): # Part of analyzeSlot() within getSlotImageList(). info = {} lines = fileReadLines(path, source=MODULE_NAME) if lines: if self.checkChecksum(lines): print( "[MultiBoot] WARNING: Enigma information file found but checksum is incorrect!" ) for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item: info[item] = self.processValue(value) lines = fileReadLines(path.replace(".info", ".conf"), source=MODULE_NAME) if lines: for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item: if item in info: print( "[MultiBoot] Note: Enigma information value '%s' with value '%s' being overridden to '%s'." % (item, info[item], value)) info[item] = self.processValue(value) return info
def getCPUBenchmark(): cpuCount = 0 lines = fileReadLines("/proc/cpuinfo", source=MODULE_NAME) if lines: for line in lines: line = [x.strip() for x in line.strip().split(":")] if line[0] == "processor": cpuCount += 1 if not isfile("/tmp/dhry.txt"): benchmarkCmd = "/usr/bin/dhry > /tmp/dhry.txt" Console().ePopen(benchmarkCmd) if isfile("/tmp/dhry.txt"): lines = fileReadLines("/tmp/dhry.txt", source=MODULE_NAME) cpuBenchmark = 0 cpuRating = "" if lines: for line in lines: if line.startswith("Open Vision DMIPS"): cpuBenchmark = int([x.strip() for x in line.split(":")][1]) if line.startswith("Open Vision CPU status"): cpuRating = [x.strip() for x in line.split(":")][1] if cpuCount > 1: cpuMaxBenchmark = cpuBenchmark * cpuCount return "%s DMIPS per core\n%s DMIPS for all (%s) cores (%s)" % ( cpuBenchmark, cpuMaxBenchmark, cpuCount, cpuRating) else: return "%s DMIPS (%s)" % (cpuBenchmark, cpuRating) return _("Unknown")
def prepare(self): try: dev = self.hdd.disk_path.split(sep)[-1] unlink("/dev/nomount.%s" % dev) except (IOError, OSError) as err: print( "[Harddisk] Error %d: MountTask failed to remove '/dev/nomount' file! (%s)" % (err.errno, err.strerror)) if self.hdd.mount_device is None: dev = self.hdd.partitionPath( "1") # Try mounting through fstab first. else: dev = self.hdd.mount_device # If previously mounted, use the same spot. lines = fileReadLines("/etc/fstab", []) for line in lines: parts = line.strip().split(" ") fspath = realpath(parts[0]) if realpath(fspath) == dev: self.setCmdline("mount -t auto " + fspath) self.postconditions.append(Task.ReturncodePostcondition()) return # device is not in fstab if BoxInfo.getItem("Udev"): # we can let udev do the job, re-read the partition table # Sorry for the sleep 2 hack... self.setCmdline("sleep 2; hdparm -z " + self.hdd.disk_path) self.postconditions.append(Task.ReturncodePostcondition())
def getProcMounts(): mounts = fileReadLines("/proc/mounts", []) result = [line.strip().split(" ") for line in mounts] for item in result: item[1] = item[1].replace("\\040", " ") # Spaces are encoded as \040 in mounts return result
def loadBootDevice(self): for device in ("/dev/block/by-name/bootoptions", "/dev/mmcblk0p1", "/dev/mmcblk1p1", "/dev/mmcblk0p3", "/dev/mmcblk0p4", "/dev/mtdblock2"): bootDevice = None startupCmdLine = None if exists(device): tempDir = mkdtemp(prefix=PREFIX) Console().ePopen([MOUNT, MOUNT, device, tempDir]) cmdFile = pathjoin(tempDir, COMMAND_FILE) startupFile = pathjoin(tempDir, STARTUP_FILE) if isfile(cmdFile) or isfile(startupFile): file = cmdFile if isfile(cmdFile) else startupFile startupCmdLine = " ".join(x.strip() for x in fileReadLines( file, default=[], source=MODULE_NAME) if x.strip()) bootDevice = device Console().ePopen([UMOUNT, UMOUNT, tempDir]) rmdir(tempDir) if bootDevice: print("[MultiBoot] Startup device identified as '%s'." % device) if startupCmdLine: print("[MultiBoot] Startup command line '%s'." % startupCmdLine) break return bootDevice, startupCmdLine
def enumFeeds(): for file in listdir("/etc/opkg"): if file.endswith("-feed.conf"): for line in fileReadLines(pathjoin("/etc/opkg", file), default=[], source=MODULE_NAME): line = line.strip().split() if len(line) >= 2: yield line[1]
def listsDirPath(): for line in fileReadLines("/etc/opkg/opkg.conf", default=[], source=MODULE_NAME): if line.startswith("option"): line = line.strip().split() if len(line) == 3 and line[1] == "lists_dir": return line[2] return "/var/lib/opkg/lists"
def getCPUSerial(): lines = fileReadLines("/proc/cpuinfo", source=MODULE_NAME) if lines: for line in lines: if line[0:6] == "Serial": return line[10:26] return _("Undefined")
def enumPlugins(filterStart=""): listsDir = listsDirPath() for feed in enumFeeds(): package = None for line in fileReadLines(pathjoin(listsDir, feed), default=[], source=MODULE_NAME): if line.startswith("Package: "): package = line.split(":", 1)[1].strip() version = "" description = "" if config.misc.extraopkgpackages.value: if package.startswith(filterStart) and not package.endswith("--pycache--"): continue else: if package.startswith(filterStart) and not (package.endswith("-dbg") or package.endswith("-dev") or package.endswith("-doc") or package.endswith("-meta") or package.endswith("-po") or package.endswith("-src") or package.endswith("-staticdev") or package.endswith("--pycache--")): continue package = None if package is None: continue if line.startswith("Version: "): version = line.split(":", 1)[1].strip() elif line.startswith("Description: "): description = line.split(":", 1)[1].strip() elif description and line.startswith(" "): description = "%s%s" % (description, line) elif len(line) <= 1: yield package, version, description package = None
def loadBcmWifiConfig(self, iface): wsconf = {} wsconf["ssid"] = "" wsconf["hiddenessid"] = False # Not used. wsconf["encryption"] = "WPA2" wsconf["wepkeytype"] = "ASCII" # Not used. wsconf["key"] = "" configFile = getWlanConfigName(iface) lines = fileReadLines(configFile, default=None, source=MODULE_NAME) if lines is None: print("[Wlan] Error: Unable to parse '%s'!" % configFile) wsconfig = { "hiddenessid": False, "ssid": "", "encryption": "WPA2", "wepkeytype": "ASCII", "key": "", } else: for line in lines: try: (key, value) = line.strip().split("=", 1) except ValueError: continue if key == "ssid": wsconf["ssid"] = value.strip() if key == "method": wsconf["encryption"] = value.strip() elif key == "key": wsconf["key"] = value.strip() else: continue for (key, value) in wsconf.items(): print("[Wlan] DEBUG: Entry wsconf [%s] = '%s'." % (key, value)) return wsconf
def updateList(self, ret=None): self.list = [] self.cihelper_ci0 = NoSave(ConfigYesNo(default=True)) self.cihelper_ci1 = NoSave(ConfigYesNo( default=True)) if access("/dev/ci1", R_OK) else ConfigNothing() if isfile(CI_HELPER_CONF): helperConfig = fileReadLines(CI_HELPER_CONF) if helperConfig: helperConfig = [ x.strip() for x in helperConfig if x.strip().startswith("ENABLE_CI") ] for line in helperConfig: if line.startswith("ENABLE_CI0="): self.cihelper_ci0.value = (line[11:] != "no") cihelper_ci0x = getConfigListEntry( _("Enable CIHelper for SLOT CI0") + ":", self.cihelper_ci0) self.list.append(cihelper_ci0x) elif line.startswith("ENABLE_CI1="): self.cihelper_ci1.value = (line[11:] != "no") if access("/dev/ci1", R_OK): cihelper_ci1x = getConfigListEntry( _("Enable CIHelper for SLOT CI1") + ":", self.cihelper_ci1) self.list.append(cihelper_ci1x) self["config"].list = self.list
def mount(self): if self.mount_device is None: # Try mounting through fstab first. dev = self.partitionPath("1") else: # if previously mounted, use the same spot dev = self.mount_device lines = fileReadLines("/etc/fstab") if lines is None: return -1 for line in lines: parts = line.strip().split(" ") fspath = realpath(parts[0]) if fspath == dev: print("[Harddisk] Mounting: '%s'." % fspath) cmd = "mount -t auto " + fspath res = system(cmd) return (res >> 8) # device is not in fstab res = -1 if BoxInfo.getItem("Udev"): # we can let udev do the job, re-read the partition table res = system("hdparm -z %s" % self.disk_path) # give udev some time to make the mount, which it will do asynchronously sleep(3) return (res >> 8)
def getopensslVersionString(): lines = fileReadLines("/var/lib/opkg/info/openssl.control", source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return line[9:].split("+")[0] return _("Not Installed")
def __init__(self): self.keyboardMaps = [] for keyboardMapInfo in sorted(listdir(resolveFilename(SCOPE_KEYMAPS))): if keyboardMapInfo.endswith(".info"): lines = [] lines = fileReadLines(resolveFilename(SCOPE_KEYMAPS, keyboardMapInfo), lines, source=MODULE_NAME) keyboardMapFile = None keyboardMapName = None for line in lines: key, val = [x.strip() for x in line.split("=", 1)] if key == "kmap": keyboardMapFile = val elif key == "name": keyboardMapName = val if keyboardMapFile and keyboardMapName: keyboardMapPath = resolveFilename(SCOPE_KEYMAPS, keyboardMapFile) if isfile(keyboardMapPath): if config.crash.debugKeyboards.value: print("[InputDevice] Adding keyboard keymap '%s' in '%s'." % (keyboardMapName, keyboardMapFile)) self.keyboardMaps.append((keyboardMapFile, keyboardMapName)) else: print("[InputDevice] Error: Keyboard keymap file '%s' doesn't exist!" % keyboardMapPath) else: print("[InputDevice] Error: Invalid keyboard keymap information file '%s'!" % keyboardMapInfo) config.inputDevices.keyboardMap = ConfigSelection(choices=self.keyboardMaps, default=self.getDefaultKeyboardMap())
def getIfTransferredData(ifname): lines = fileReadLines("/proc/net/dev", source=MODULE_NAME) if lines: for line in lines: if ifname in line: data = line.split("%s:" % ifname)[1].split() rx_bytes, tx_bytes = (data[0], data[8]) return rx_bytes, tx_bytes
def __init__(self): self.immutableList = [] self.procList = [] self.boxInfo = {} self.enigmaList = [] self.enigmaInfo = {} lines = fileReadLines(pathjoin(resolveFilename(SCOPE_LIBDIR), "enigma.info"), source=MODULE_NAME) if lines: modified = self.checkChecksum(lines) if modified: print("[SystemInfo] WARNING: Enigma information file checksum is incorrect! File appears to have been modified.") self.boxInfo["checksumerror"] = True else: print("[SystemInfo] Enigma information file checksum is correct.") self.boxInfo["checksumerror"] = False for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item: self.immutableList.append(item) self.procList.append(item) self.boxInfo[item] = self.processValue(value) self.procList = sorted(self.procList) print("[SystemInfo] Enigma information file data loaded into BoxInfo.") else: print("[SystemInfo] ERROR: Enigma information file is not available! The system is unlikely to boot or operate correctly.") lines = fileReadLines(pathjoin(resolveFilename(SCOPE_LIBDIR), "enigma.conf"), source=MODULE_NAME) if lines: print("[SystemInfo] Enigma config override file available and data loaded into BoxInfo.") self.boxInfo["overrideactive"] = True for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item: self.enigmaList.append(item) self.enigmaInfo[item] = self.processValue(value) if item in self.boxInfo: print("[SystemInfo] Note: Enigma information value '%s' with value '%s' being overridden to '%s'." % (item, self.boxInfo[item], value)) self.enigmaList = sorted(self.enigmaList) else: self.boxInfo["overrideactive"] = False
def matchCAId(self, caids): lines = [] for line in fileReadLines("/tmp/ecm.info", lines, source=MODULE_NAME): if line.startswith("caid: 0x"): for caid in caids: sName = self.condAccessIds.get(line[8:10]) if sName is not None: return sName return "NAG"
def loadTags(self): tags = [] filename = resolveFilename(SCOPE_CONFIG, "movietags") tags = fileReadLines(filename, tags, source=MODULE_NAME) tags = [self.formatTag(x) for x in tags] while "" in tags: tags.remove("") tags.sort() print("[TagEditor] %d tags read from '%s'." % (len(tags), filename)) return tags
def setMovieTags(self, serviceRef, tags): filename = serviceRef.getPath() filename = "%s.meta" % filename if filename.endswith( ".ts") else "%s.ts.meta" % filename if isfile(filename): lines = fileReadLines(filename, source=MODULE_NAME) idTags = iDVBMetaFile.idTags if len(lines) > idTags: tagList = " ".join(tags) if tagList != lines[idTags]: lines[idTags] = tagList fileWriteLines(filename, lines, source=MODULE_NAME)
def getWirelessInterfaces(self): device = compile("[a-z]{2,}[0-9]*:") ifNames = [] lines = fileReadLines("/proc/net/wireless", default=[], source=MODULE_NAME) for line in lines: try: ifNames.append(device.search(line).group()[:-1]) except AttributeError: pass return ifNames
def getGStreamerVersionString(): if isfile("/usr/bin/gst-launch-0.10"): return "0.10.36" else: filenames = glob("/var/lib/opkg/info/gstreamer?.[0-9].control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return line[9:].split("+")[0].split("-")[0] return _("Not Installed")
def getSlotImageData(imageDir): imageData = {} path = pathjoin(imageDir, "usr/lib/enigma.info") if isfile(path): lines = fileReadLines(path, source=MODULE_NAME) if lines: modified = BoxInfo.checkChecksum(lines) if modified: print( "[MultiBoot] WARNING: Enigma information file checksum is incorrect! File appears to have been modified." ) for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item: imageData[item] = BoxInfo.processValue(value) else: imageDateList = [ "usr/share/enigma2/bootlogo.mvi", "usr/share/bootlogo.mvi", "var/lib/opkg/status" ] fileDate = "" for file in imageDateList: path = pathjoin(imageDir, file) if isfile(path): fileDate = datetime.fromtimestamp( stat(path).st_mtime).strftime("%Y%m%d") if not fileDate.startswith("1970"): break enigmaDate = datetime.fromtimestamp( stat(pathjoin(imageDir, "usr/bin/enigma2")).st_mtime).strftime( "%Y%m%d") # Method not called if enigma2 does not exist! imageData["compiledate"] = max(fileDate, enigmaDate) or _("Unknown") lines = fileReadLines(pathjoin(imageDir, "etc/issue"), source=MODULE_NAME) imageData["displaydistro"] = lines[-2].capitalize().strip( )[:-6] if lines else _("Unknown") return imageData
def getRAMBenchmark(): if not isfile("/tmp/streambench.txt"): benchmarkCmd = "/usr/bin/streambench > /tmp/streambench.txt" Console().ePopen(benchmarkCmd) if isfile("/tmp/streambench.txt"): lines = fileReadLines("/tmp/streambench.txt", source=MODULE_NAME) ramBenchmark = 0 if lines: for line in lines: if line.startswith("Open Vision copy rate"): ramBenchmark = [x.strip() for x in line.split(":")][1] return "%s MB/s copy rate" % ramBenchmark return _("Unknown")
def getDriverInstalledDate(): filenames = glob("/var/lib/opkg/info/*dvb-modules*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": driver = line.split("-")[1] return "%s-%s-%s" % (driver[:4], driver[4:6], driver[6:]) filenames = glob("/var/lib/opkg/info/*dvb-proxy*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return line.split("-")[1] filenames = glob("/var/lib/opkg/info/*platform-util*.control") if filenames: lines = fileReadLines(filenames[0], source=MODULE_NAME) if lines: for line in lines: if line[0:8] == "Version:": return line.split("-")[1] return _("Unknown")
def deriveSlotInfo( self, path): # Part of analyzeSlot() within getSlotImageList(). info = {} try: date = datetime.fromtimestamp( stat(pathjoin( path, "var/lib/opkg/status")).st_mtime).strftime("%Y%m%d") if date.startswith("1970"): date = datetime.fromtimestamp( stat(pathjoin( path, "usr/share/bootlogo.mvi")).st_mtime).strftime("%Y%m%d") date = max( date, datetime.fromtimestamp( stat(pathjoin( path, "usr/bin/enigma2")).st_mtime).strftime("%Y%m%d")) except OSError as err: date = "00000000" info["compiledate"] = date lines = fileReadLines(pathjoin(path, "etc/issue"), source=MODULE_NAME) if lines: data = lines[-2].strip()[:-6].split() info["distro"] = " ".join(data[:-1]) info["displaydistro"] = { "beyonwiz": "Beyonwiz", "blackhole": "Black Hole", "egami": "EGAMI", "openatv": "openATV", "openbh": "OpenBH", "opendroid": "OpenDroid", "openeight": "OpenEight", "openhdf": "OpenHDF", "opennfr": "OpenNFR", "openpli": "OpenPLi", "openspa": "OpenSpa", "openvision": "Open Vision", "openvix": "OpenViX", "sif": "Sif", "teamblue": "teamBlue", "vti": "VTi" }.get(info["distro"].lower(), info["distro"].capitalize()) info["imgversion"] = data[-1] else: info["distro"] = "Enigma2" info["displaydistro"] = "Enigma2" info["imgversion"] = "???" return info
def getCpusInfo(self): results = [] lines = fileReadLines("/proc/stat", []) for line in lines: if line.startswith("cpu"): # data = [cpu, usr, nic, sys, idle, iowait, irq, softirq, steal] data = line.split() total = 0 for item in range(1, len(data)): data[item] = int(data[item]) total += data[item] # busy = total - idle - iowait busy = total - data[4] - data[5] # append [cpu, total, busy] results.append([data[0], total, busy]) return results
def saveCIHelper(self): if isfile(CI_HELPER_CONF): helperConfig = fileReadLines(CI_HELPER_CONF) newhelperConfig = [] for line in helperConfig: line = line.replace("\n", "") if line.startswith("ENABLE_CI0="): line = "ENABLE_CI0%s" % ("yes" if self.cihelper_ci0.value else "no") elif line.startswith("ENABLE_CI1="): line = "ENABLE_CI1%s" % ("yes" if self.cihelper_ci1.value else "no") newhelperConfig.append("%s\n" % line) fileWriteLines(CI_HELPER_CONF_TMP, newhelperConfig) else: errorText = _("Sorry CIHelper Config is Missing") with open("/tmp/CIHelper.log", "a") as fd: fd.write("%s\n" % errorText) self.session.open(MessageBox, errorText, MessageBox.TYPE_INFO) if isfile(CI_HELPER_CONF_TMP): rename(CI_HELPER_CONF_TMP, CI_HELPER_CONF) self.close()
def loadConfig(self, iface): config.plugins.wlan.hiddenessid.value = False config.plugins.wlan.wepkeytype.value = "ASCII" config.plugins.wlan.essid.value = "" config.plugins.wlan.encryption.value = "WPA2" config.plugins.wlan.psk.value = "" configFile = getWlanConfigName(iface) if exists(configFile): print("[Wlan] Parsing config file '%s'." % configFile) lines = fileReadLines(configFile, default=[], source=MODULE_NAME) for line in lines: try: (key, value) = line.strip().split("=", 1) except ValueError: continue if key == "ssid": config.plugins.wlan.essid.value = value.strip() if key == "method": method = value.strip() if method == "None": method = "Unencrypted" else: method = method.upper() config.plugins.wlan.encryption.value = method elif key == "key": config.plugins.wlan.psk.value = value.strip() else: continue wsconf = { "hiddenessid": config.plugins.wlan.hiddenessid.value, "ssid": config.plugins.wlan.essid.value, "encryption": config.plugins.wlan.encryption.value, "wepkeytype": config.plugins.wlan.wepkeytype.value, "key": config.plugins.wlan.psk.value, } return wsconf
profileData = {} profileStart = time() totalTime = 1 timeStamp = None profileFile = resolveFilename(SCOPE_CONFIG, "profile") profileFd = None # model = BoxInfo.get("model") # For when we can use BoxInfo. model = None # Workaround to get the model name. When SystemInfo can be loaded earlier in # the boot process we can use BoxInfo directly rather than using this code. # lines = [] lines = fileReadLines(pathjoin(resolveFilename(SCOPE_LIBDIR), "enigma.info"), lines, source=MODULE_NAME) for line in lines: if line.startswith("#") or line.strip() == "": continue if "=" in line: item, value = [x.strip() for x in line.split("=", 1)] if item == "model": model = value break profileOld = fileReadLines(profileFile, source=MODULE_NAME) if profileOld: for line in profileOld: if "\t" in line: (timeStamp, checkPoint) = line.strip().split("\t")