fixed crash on get_edid_data; fixed xml warnings

master 3.7.1.5
parent 27e7696692
commit b3190612bf

@ -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

@ -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:

@ -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)

@ -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):

@ -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)

@ -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):

@ -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

@ -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

@ -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 ""

Loading…
Cancel
Save