From b3190612bf01cd91f15bfed242751014e2860788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=94=D0=B7=D1=8E=D0=B1=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE?= Date: Thu, 9 Sep 2021 14:57:20 +0300 Subject: [PATCH] fixed crash on get_edid_data; fixed xml warnings --- pym/calculate/lib/cl_xml.py | 27 +++++++++++-------------- pym/calculate/lib/format/plasma.py | 3 ++- pym/calculate/lib/utils/device.py | 8 ++++---- pym/calculate/lib/utils/files.py | 12 +++++------ pym/calculate/lib/utils/partition.py | 4 ++-- pym/calculate/lib/utils/text.py | 4 ++-- pym/calculate/lib/utils/tools.py | 4 ++-- pym/calculate/lib/utils/video.py | 2 +- pym/calculate/lib/variables/hardware.py | 4 ++-- 9 files changed, 33 insertions(+), 35 deletions(-) diff --git a/pym/calculate/lib/cl_xml.py b/pym/calculate/lib/cl_xml.py index 30aef94..60a8eba 100644 --- a/pym/calculate/lib/cl_xml.py +++ b/pym/calculate/lib/cl_xml.py @@ -15,12 +15,9 @@ # limitations under the License. -# import lxml from lxml import etree as ET from copy import deepcopy -# def appendChild(*args, **kwargs): -# ET._Element.append(*args, **kwargs) def display_xml(xml): print(xml_to_str(xml)) @@ -377,7 +374,7 @@ class xmlDoc(): newInsNode = deepcopy(nodeSeplist) self.setActionField(newInsNode, "append") - if nextNode: + if nextNode is not None: appSplLst.append((newInsNode, nextNode, "insert")) @@ -389,7 +386,7 @@ class xmlDoc(): newInsNode = deepcopy(nodeSeplist) if self.getActionField(newInsNode) == "join": self.setActionField(newInsNode, "append") - if xmlOldField: + if xmlOldField is not None: insSplLst.append((newInsNode, xmlOldField, "insert")) @@ -417,7 +414,7 @@ class xmlDoc(): flagCompareSeplist = True break if not flagCompareSeplist: - if xmlOldField: + if xmlOldField is not None: insNodesRepl.append((newNode, nxtNode, app)) for newNode, nxtNode, app in insNodesRepl: @@ -425,9 +422,9 @@ class xmlDoc(): insertBefore(xmlArea, newNode, nxtNode) elif app == "append": xmlArea.append(newNode) - if xmlOldField: + if xmlOldField is not None: parentNode = xmlOldField.getparent() - if parentNode and newFieldsAction != "join": + if parentNode is not None and newFieldsAction != "join": parentNode.remove(xmlOldField) for newNode, nxtNode, app in appSplLst: @@ -452,7 +449,7 @@ class xmlDoc(): if actionOldNode == "insert" or actionOldNode == "append": pass else: - if nodeFieldOld.getnext() and \ + if nodeFieldOld.getnext() is not None and \ self.getTypeField( nodeFieldOld.getnext()) == "br": xmlArea.remove(nodeFieldOld.getnext()) @@ -469,7 +466,7 @@ class xmlDoc(): if not nameField: return [] parentNode = xmlField.getparent() - if parentNode: + if parentNode is not None: fieldsVal = xpath.Evaluate( "child::field[attribute::type='seplist'][child::name='%s'] " \ % nameField, parentNode) @@ -814,7 +811,7 @@ class xmlDoc(): def getNameArea(self, xmlArea): """Выдает имя области""" xmlNameAreas = xpath.Evaluate('child::caption/name', xmlArea) - if xmlNameAreas and firstChild(xmlNameAreas[0]): + if xmlNameAreas and firstChild(xmlNameAreas[0]) is not None: return firstChild(xmlNameAreas[0]).text else: return False @@ -997,19 +994,19 @@ class xmlDoc(): for xmlField in xmlFields: xmlNames = xpath.Evaluate('child::name', xmlField) xmlVals = xpath.Evaluate('child::value', xmlField) - # if xmlField.hasAttribute("type") and \ - # xmlField.getAttribute("type") == "br": + # if "type" in xmlField.keys() and \ + # xmlField.get("type") == "br": if xmlField.get("type") == "br": lenBrArea += 1 continue if not xmlNames and not xmlVals: flagListXml = False break - if xmlNames and firstChild(xmlNames[0]) and \ + if xmlNames and firstChild(xmlNames[0]) is not None and \ firstChild(xmlNames[0]).text: flagListXml = False break - if not (xmlVals and firstChild(xmlVals[0]) and + if not (xmlVals and firstChild(xmlVals[0]) is not None and firstChild(xmlVals[0]).text): flagListXml = False break diff --git a/pym/calculate/lib/format/plasma.py b/pym/calculate/lib/format/plasma.py index c1e761d..97d0524 100644 --- a/pym/calculate/lib/format/plasma.py +++ b/pym/calculate/lib/format/plasma.py @@ -135,7 +135,8 @@ class xmlDocPlasma(xmlDoc): if newAreaAction == "drop": prevNode = oName.getparent().getparent().getprevious() removePrevNodes = [] - while prevNode and self.getTypeField(prevNode) == "br": + while prevNode is not None\ + and self.getTypeField(prevNode) == "br": removePrevNodes.append(prevNode) prevNode = prevNode.getprevious() for removeNode in removePrevNodes: diff --git a/pym/calculate/lib/utils/device.py b/pym/calculate/lib/utils/device.py index 4daa5ca..c655507 100644 --- a/pym/calculate/lib/utils/device.py +++ b/pym/calculate/lib/utils/device.py @@ -649,16 +649,16 @@ class DeviceFs(): def exists(self, *dn): return self.fs.exists(self.pathjoin(*dn)) - def read(self, *fn): - return self.fs.read(self.pathjoin(*fn)) + def read(self, *fn, encoding="UTF-8", binary=False): + return self.fs.read(self.pathjoin(*fn), encoding=encoding, binary=binary) def realpath(self, *fn): return self.fs.realpath(self.pathjoin(*fn)) - def write(self, *args): + def write(self, *args, encoding="UTF-8", binary=False): fn = args[:-1] data = args[-1] - self.fs.write(self.pathjoin(*fn), data) + self.fs.write(self.pathjoin(*fn), data, encoding=encoding, binary=binary) def listdir(self, *dn, **kw): fullpath = kw.get("fullpath", False) diff --git a/pym/calculate/lib/utils/files.py b/pym/calculate/lib/utils/files.py index 4f34b0d..48e669f 100644 --- a/pym/calculate/lib/utils/files.py +++ b/pym/calculate/lib/utils/files.py @@ -827,7 +827,7 @@ def grepFile(filename, regexp, flags=0): return match.group() return "" -def readFile(filename, encoding='utf-8', binary=False): +def readFile(filename, *, encoding='utf-8', binary=False): """ Прочитать целый файл или вернуть пустую строку в случае ошибки """ @@ -878,7 +878,7 @@ def readFileEx(filename, tailbyte=None, headbyte=None, grab=False): return b"" -def writeFile(filename, encoding='utf-8', binary=False): +def writeFile(filename, *, encoding='utf-8', binary=False): """ Открыть файл на запись и создать необходимые каталоги """ @@ -1664,8 +1664,8 @@ class RealFs(tools.GenericFs): def exists(self, fn): return path.lexists(self._path(fn)) - def read(self, fn): - return readFile(self._path(fn)) + def read(self, fn, *, encoding="UTF-8", binary=False): + return readFile(self._path(fn), encoding=encoding, binary=binary) def glob(self, dn): for fn in glob(self._path(dn)): @@ -1674,8 +1674,8 @@ class RealFs(tools.GenericFs): def realpath(self, fn): return self.remove_prefix(path.realpath(fn)) - def write(self, fn, data): - with writeFile(fn) as f: + def write(self, fn, data, *, encoding="UTF-8", binary=False): + with writeFile(fn, encoding=encoding, binary=binary) as f: f.write(data) def listdir(self, dn, fullpath=False): diff --git a/pym/calculate/lib/utils/partition.py b/pym/calculate/lib/utils/partition.py index 23e4aac..7335994 100644 --- a/pym/calculate/lib/utils/partition.py +++ b/pym/calculate/lib/utils/partition.py @@ -1076,8 +1076,8 @@ class SchemeBuilder(): raise DeviceSchemeError( _("Please select devices for partitions changing")) if self.lvm: - lvm_devices, lvm_sizes = zip( - *self.create_lvm_devices(volumes_factory)) + lvm_devices, lvm_sizes = list(zip( + *self.create_lvm_devices(volumes_factory))) return volumes_factory.createLvmBuilder( list(lvm_devices), self.vgname, sum(lvm_sizes), extsize=self.extsize) diff --git a/pym/calculate/lib/utils/text.py b/pym/calculate/lib/utils/text.py index db2b901..53c8d80 100644 --- a/pym/calculate/lib/utils/text.py +++ b/pym/calculate/lib/utils/text.py @@ -348,7 +348,7 @@ def list2str(list): """ replaceSlash = MultiReplace({'\\': '\\\\', '\'': '\\\''}) return "[%s]" % ','.join(["'%s'" % replaceSlash(str(i)) - for i in list]) + for i in list]) def dict2str(dict): @@ -358,7 +358,7 @@ def dict2str(dict): """ replaceSlash = MultiReplace({'\\': '\\\\', '\'': '\\\''}) return '{%s}' % ','.join(["'%s':'%s'" % (str(k), replaceSlash(str(v))) \ - for (k, v) in dict.items()]) + for (k, v) in dict.items()]) def convertStrListDict(val): diff --git a/pym/calculate/lib/utils/tools.py b/pym/calculate/lib/utils/tools.py index 16ea7fa..6358331 100644 --- a/pym/calculate/lib/utils/tools.py +++ b/pym/calculate/lib/utils/tools.py @@ -574,7 +574,7 @@ class GenericFs(metaclass=ABCMeta): pass @abstractmethod - def read(self, fn): + def read(self, fn, encoding="UTF-8", binary=False): pass @abstractmethod @@ -586,7 +586,7 @@ class GenericFs(metaclass=ABCMeta): pass @abstractmethod - def write(self, fn, data): + def write(self, fn, data, encoding="UTF-8", binary=False): pass @abstractmethod diff --git a/pym/calculate/lib/utils/video.py b/pym/calculate/lib/utils/video.py index 7d81217..cb16d34 100644 --- a/pym/calculate/lib/utils/video.py +++ b/pym/calculate/lib/utils/video.py @@ -26,7 +26,7 @@ setLocalTranslate('cl_lib3', sys.modules[__name__]) def get_edid_data(): for fn in device.sysfs.glob(device.sysfs.Path.Drm,"*/edid"): - ediddata = device.sysfs.read(fn) + ediddata = device.sysfs.read(fn, binary=True) if ediddata: return ediddata return None diff --git a/pym/calculate/lib/variables/hardware.py b/pym/calculate/lib/variables/hardware.py index 459eeac..8ec759d 100644 --- a/pym/calculate/lib/variables/hardware.py +++ b/pym/calculate/lib/variables/hardware.py @@ -169,7 +169,7 @@ class VariableHrLaptop(ReadonlyVariable): ChassisType.Portable, ChassisType.Notebook): board_vendor = device.sysfs.read( - device.sysfs.Path.Dmi, "board_vendor").strip() + device.sysfs.Path.Dmi, "board_vendor").strip() vendor = (board_vendor.partition(" ")[0]).lower() return vendor or "unknown" return "" @@ -183,7 +183,7 @@ class VariableHrLaptopModel(ReadonlyVariable): def get(self): if self.Get('hr_laptop'): return device.sysfs.read( - device.sysfs.Path.Dmi, "board_name").strip() or "unknown" + device.sysfs.Path.Dmi, "board_name").strip() or "unknown" return ""