From d0d17648ef88aa06e6906fe621bab5f36e0e6815 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Tue, 20 Jul 2021 15:56:21 +0300 Subject: [PATCH] py3 changes --- data/setbg | 5 +- pym/desktop/desktop.py | 21 ++++---- pym/desktop/variables/desktop.py | 84 +++++++++++++++++--------------- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/data/setbg b/data/setbg index 65a0404..a09ad19 100755 --- a/data/setbg +++ b/data/setbg @@ -39,9 +39,8 @@ class ImageViewer(QtGui.QMainWindow): @staticmethod def select_color(): try: - #TODO change for any in list compr? - if list(filter(re.compile(r"(cld|cldx|cldg|cmc|cls)-themes-12").search, - os.listdir('/var/db/pkg/media-gfx'))): + if [x for x in os.listdir('/var/db/pkg/media-gfx') + if re.compile(r"(cld|cldx|cldg|cmc|cls)-themes-12").search(x)]: return "#73a363" except OSError: pass diff --git a/pym/desktop/desktop.py b/pym/desktop/desktop.py index 705cf82..354da6e 100644 --- a/pym/desktop/desktop.py +++ b/pym/desktop/desktop.py @@ -201,10 +201,10 @@ class Desktop(MethodsInterface): mountProfileDir = path.join(dirStart, ".%s" % dirEnd) mountRemoteProfileDir = path.join(dirStart, ".%s.remote" % dirEnd) with open("/proc/mounts") as f: - return list(filter(lambda x: x.startswith(homeDir) or - x.startswith(mountProfileDir) or - x.startswith(mountRemoteProfileDir), - map(lambda x: x.split(" ")[1], f))) + return [x for x in (y.split(" ")[1] for y in f) + if x.startswith(homeDir) + or x.startswith(mountProfileDir) + or x.startswith(mountRemoteProfileDir)] def umountSleepPath(self, rpath): """ @@ -216,7 +216,7 @@ class Desktop(MethodsInterface): fuser_cmd = getProgPath("/bin/fuser") loops = getLoopFromPath(rpath) if loops: - setLoops = set(map(lambda x: x.partition('/dev/')[2], loops)) + setLoops = set((x.partition('/dev/')[2] for x in loops)) mdInfo = getMdRaidDevices() for k, v in mdInfo.items(): if setLoops & set(v): @@ -335,17 +335,14 @@ class Desktop(MethodsInterface): if uid: uid = int(uid) for i in range(0, postWaitTime): - if not list(filter(lambda x: "ksmserver" in x, - getRunCommands(uid=uid))): + if not [x for x in getRunCommands(uid=uid) if "ksmserver" in x]: break time.sleep(1) time.sleep(1) - - if list(filter(lambda x: "xdm/xdm\x00--logout" in x, - getRunCommands())): + + if [x for x in getRunCommands() if "xdm/xdm\x00--logout" in x]: for i in range(0, waitTime): - if not list(filter(lambda x: "xdm/xdm\x00--logout" in x, - getRunCommands())): + if not [x for x in getRunCommands() if "xdm/xdm\x00--logout" in x]: return True time.sleep(1) else: diff --git a/pym/desktop/variables/desktop.py b/pym/desktop/variables/desktop.py index 4550afb..0b5b067 100644 --- a/pym/desktop/variables/desktop.py +++ b/pym/desktop/variables/desktop.py @@ -15,6 +15,7 @@ # limitations under the License. import os +from posixpath import split import sys import re from os import path @@ -59,9 +60,8 @@ class DomainInfoHelper(VariableInterface): """ def getUserDataInFile(self, login, filePasswd): - return list(filter(lambda x: x[0] == login, - map(lambda x: x.strip().split(':'), - readLinesFile(filePasswd)))) + return [x for x in (y.strip().split(':') for y + in readLinesFile(filePasswd)) if x[0] == login] def isDomainUser(self, userName): if userName: @@ -93,9 +93,8 @@ class VariableUrDomainSet(ReadonlyVariable, DomainInfoHelper): type = "bool" def getUserDataInFile(self, login, file_passwd): - return list(filter(lambda x: x[0] == login, - map(lambda x: x.strip().split(':'), - readLinesFile(file_passwd)))) + return [x for x in (y.strip().split(':') for y + in readLinesFile(file_passwd)) if x[0] == login] def get(self): return "on" if self.isDomainUser(self.Get('ur_login')) else "off" @@ -156,10 +155,9 @@ class VariableClDesktopGstData(ReadonlyVariable): if res == gst.STATE_CHANGE_SUCCESS: outdata['device_name'] = alsamixer.get_property("device-name") outdata['long_name'] = alsamixer.get_factory().get_longname() - outdata['internal_name'] = list(filter(str.isalnum, - "%s (%s)" % ( - outdata['device_name'], - outdata['long_name']))) + outdata['internal_name'] = [x for x + in "%s (%s)" % (outdata['device_name'],outdata['long_name']) + if str.isalnum(x)] outdata['channels'] = [] for t in alsamixer.list_tracks(): if t.flags & gst.interfaces.MIXER_TRACK_OUTPUT: @@ -200,9 +198,8 @@ class VariableClDesktopXfceMixer(ReadonlyVariable): """ def get(self): - return "\n".join( - map(lambda x: ' ' % x, - self.Get('cl_desktop_gst_data').get('channels', []))) + return "\n".join((' ' % x for x + in self.Get('cl_desktop_gst_data').get('channels', []))) class VariableClDesktopXfcePointers(ReadonlyVariable): @@ -257,25 +254,32 @@ class VariableClDesktopOnlineData(ReadonlyTableVariable, DomainInfoHelper): if resWho.success(): listProcessing = lambda x: (x[0], x[1], x[-1]) \ if len(x) >= 5 else [] + # xData = groupby( + # sorted( + # filter(lambda x: x[0] != "root", + # map(lambda x: (x[0], self._getDisplay(x[1], x[2])), + # filter(lambda x: x and \ + # (x[2].startswith("(:") or + # x[1].startswith(":")), + # map(lambda x: listProcessing( + # list(filter(lambda y: y, x.split()))), + # resWho)))), + # key=lambda x: x[0]), + # lambda x: x[0]) + xData = groupby( - sorted( - filter(lambda x: x[0] != "root", - map(lambda x: (x[0], self._getDisplay(x[1], x[2])), - filter(lambda x: x and \ - (x[2].startswith("(:") or - x[1].startswith(":")), - map(lambda x: listProcessing( - list(filter(lambda y: y, x.split()))), - resWho)))), - key=lambda x: x[0]), + sorted((x for x in ((y[0], self._getDisplay(y[1], y[2])) for y + in (listProcessing([o for o in z.split() if o]) for z + in resWho) + if y and (y[2].startswith("(:") or y[1].startswith(":"))) + if x[0] != "root"), + key=lambda x: x[0]), lambda x: x[0]) - xData = list(map(lambda x: (x[0][0], x[0][1], - self.get_user_uid(x[0][0]), - "on" if self.isDomainUser( - x[0][0]) else "off", - len(x)), - map(lambda x: list(x[1]), - xData))) + + + xData = [(x[0][0], x[0][1], self.get_user_uid(x[0][0]), "on" + if self.isDomainUser(x[0][0]) else "off", len(x)) for x + in (list(y[1]) for y in xData)] return xData setValue = Variable.setValue @@ -367,13 +371,14 @@ class VariableUrMountDirs(ReadonlyVariable): mountProfileDir = path.join(dirStart, ".%s" % dirEnd) mountRemoteProfileDir = path.join(dirStart, ".%s.remote" % dirEnd) - directories = filter(lambda x: x != homeDir, - filter(lambda x: (x.startswith(homeDir) or - x.startswith(mountProfileDir) or - x.startswith( - mountRemoteProfileDir)), - map(lambda x: x.split(" ")[1], - readLinesFile('/proc/mounts')))) + directories = (x for x + in (y for y + in (z.split(" ")[1] for z + in readLinesFile('/proc/mounts')) + if (y.startswith(homeDir) + or y.startswith(mountProfileDir) + or y.startswith(mountRemoteProfileDir))) + if x != homeDir) # if isMount(homeDir): # directories.append(homeDir) return sorted(directories, reverse=True) @@ -446,9 +451,8 @@ class VariableClDesktopFaceList(Variable): type = "list" def get(self): - return sorted( - filter(lambda x: x.endswith('.png'), - listDirectory(self.Get('cl_desktop_face_path')))) + return sorted((x for x in listDirectory(self.Get('cl_desktop_face_path')) + if x.endswith('.png'))) class VariableClDesktopHashFace(Variable):