diff --git a/pym/client/client.py b/pym/client/client.py index e86a9f1..74edecd 100644 --- a/pym/client/client.py +++ b/pym/client/client.py @@ -363,17 +363,13 @@ class Client(commandServer, encrypt, Desktop): deletePaths = self.clVars.Get("cl_sync_del_path") if not deletePaths: deletePaths = [] - excludePaths = " ".join(map( - lambda x: '--exclude="/%s"' % x.replace('"', "").replace( - "'", ""), - skipPaths + deletePaths + list(skipList))) + excludePaths = " ".join(('--exclude="/%s"' % x.replace('"', "").replace("'", "") for x + in skipPaths + deletePaths + list(skipList))) if sync == "login": if os.path.exists(userHome) and \ os.path.exists(remoteProfile): - filterPath = " ".join(map( - lambda x: '--filter="P /%s"' % x.replace( - '"', "").replace("'", ""), - skipPaths)) + filterPath = " ".join(('--filter="P /%s"' % x.replace( + '"', "").replace("'", "") for x in skipPaths)) execStr = ('/usr/bin/rsync --delete-excluded --delete %s %s ' '-rlptgo -x -v -v -v %s/ %s/' % (excludePaths, filterPath, @@ -786,11 +782,15 @@ class Client(commandServer, encrypt, Desktop): filesDir.append(fd) # find files in Desktop pathDesktop = path.join(userHome, desktopDir) - filesDirDesk = filter(lambda x: (not path.islink(x) and - not path.split(x)[1].startswith( - '.') and - not x.rpartition('.')[2] == 'desktop'), - listDirectory(pathDesktop, fullPath=True)) + # filesDirDesk = filter(lambda x: (not path.islink(x) and + # not path.split(x)[1].startswith( + # '.') and + # not x.rpartition('.')[2] == 'desktop'), + # listDirectory(pathDesktop, fullPath=True)) + filesDirDesk = [x for x in listDirectory(pathDesktop, fullPath=True) + if (not path.islink(x) and + not path.split(x)[1].startswith('.') and + not x.rpartition('.')[2] == 'desktop')] filesDir += filesDirDesk if not filesDir or not path.exists(resourcePath): # remove empty Moved folder @@ -838,12 +838,8 @@ class Client(commandServer, encrypt, Desktop): for privateHomeDir in self.privateDirs: privateDir = os.path.join(userHome, privateHomeDir) if os.path.isdir(privateDir): - # .ssh files relative user home directory - privateFiles += map(lambda x: os.path.join(privateHomeDir, x), - filter(lambda x: \ - os.path.isfile( - os.path.join(privateDir, x)), - os.listdir(privateDir))) + privateFiles += [os.path.join(privateHomeDir, x) for x in os.listdir(privateDir) + if os.path.isfile(os.path.join(privateDir, x))] return self.privateFiles + privateFiles def removePrivateFiles(self, userHome): @@ -890,8 +886,7 @@ class Client(commandServer, encrypt, Desktop): Generation file list in user home directory, exclude mount dirs """ lHomeDir = len(homeDir) + 1 - return map(lambda x: x[lHomeDir:], - find(homeDir, onefilesystem=True)) + return [x[lHomeDir:] for x in find(homeDir, onefilesystem=True)] def removeFilesInProfile(self, homeDir, pathListFile): """ @@ -945,19 +940,19 @@ class Client(commandServer, encrypt, Desktop): if not os.access('/proc', os.R_OK): return [] - return map(getCmd, - filter(lambda x: x.isdigit(), - os.listdir('/proc'))) + return [getCmd(x) for x in os.listdir('/proc') if x.isdigit()] def clearUserKey(self, userName): """ Clear user key from kernel """ # find user key in kernel and check on relogout - if getKey(userName) and not \ - filter(lambda x: "xdm/xdm\x00--login" in x[0] and - ("USER=%s" % userName) in x[1], - self.getRunCommandsWithEnv()): + # if getKey(userName) and not \ + # filter(lambda x: "xdm/xdm\x00--login" in x[0] and + # ("USER=%s" % userName) in x[1], + # self.getRunCommandsWithEnv()): + if getKey(userName) and not any([x for x in self.getRunCommandsWithEnv() + if "xdm/xdm\x00--login" in x[0] and ("USER=%s" % userName) in x[1]]): # clean ret = clearKey(userName) if ret == 0: @@ -1020,14 +1015,19 @@ class Client(commandServer, encrypt, Desktop): p = process(rcUpdateCmd, "show") if p.success(): # получить список названии служб default уровня - return map(lambda x: x[0].strip(), - # [\s*<название_службы>\s*,\s*default\s*] - filter(lambda x: len(x) > 1 and "default" in x[1], - # [\s*<название_службы>\s*,\s*уровень запуска\s*] - map(lambda x: x.split('|'), - # \s*<название_службы>\s*| - # \s*<уроверь запуска>?\s* - p.readlines()))) + # [\s*<название_службы>\s*,\s*default\s*] + # [\s*<название_службы>\s*,\s*уровень запуска\s*] + # \s*<название_службы>\s*| + # \s*<уроверь запуска>?\s* + # return map(lambda x: x[0].strip(), + # # [\s*<название_службы>\s*,\s*default\s*] + # filter(lambda x: len(x) > 1 and "default" in x[1], + # # [\s*<название_службы>\s*,\s*уровень запуска\s*] + # map(lambda x: x.split('|'), + # # \s*<название_службы>\s*| + # # \s*<уроверь запуска>?\s* + # p.readlines()))) + return [x[0].strip() for x in [z.split('|') for z in p.readlines()] if len(x) > 1 and "default" in x[1]] else: raise ClientError(_("ERROR") + _(": ") + p.read()) @@ -1292,7 +1292,8 @@ class Client(commandServer, encrypt, Desktop): "samba_nt_hash": self.getHashPasswd(password, "nt"), "samba_nt_hash_old": self.getHashPasswd(curPassword, "nt")} - if filter(lambda x: not x, varsConfig.values()): + # if filter(lambda x: not x, varsConfig.values()): + if [x for x in varsConfig.values() if not x]: return False # ~/.calculate/server.env fileConfig = os.path.join(homeDir, self.configFileServer) diff --git a/pym/client/client_cache.py b/pym/client/client_cache.py index 8b14c08..aa64911 100644 --- a/pym/client/client_cache.py +++ b/pym/client/client_cache.py @@ -27,7 +27,7 @@ _ = lambda x: x setLocalTranslate('cl_client3', sys.modules[__name__]) -class Printable(object): +class Printable(): def __init__(self, parent): if isinstance(parent, Printable): self.parent = parent.parent @@ -46,8 +46,7 @@ class _shareData(Printable): def getDataInFile(self, fileName='', lenData=0): """Get data list from file""" - return filter(lambda x: len(x) == lenData, - map(lambda x: x.rstrip().split(":"), open(fileName))) + return [z for z in [x.rstrip().split(":") for x in open(fileName)] if len(z) == lenData] def getFileAccess(self, perm="READ"): if perm == "READ": @@ -79,7 +78,7 @@ class _shareData(Printable): def save(self): if self.getFileAccess(perm="WRITE"): - buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n" + buff = "\n".join((":".join(x) for x in self.data)) + "\n" FD = open(self.fileName, "w+") FD.write(buff) FD.close() @@ -91,7 +90,8 @@ class _shareData(Printable): if self.getData() is False: return False else: - self.data = filter(lambda x: x[0] != name, self.data) + # self.data = filter(lambda x: x[0] != name, self.data) + self.data = [x for x in self.data if x[0] != name] return True def replace(self, name, listData): @@ -119,7 +119,8 @@ class _shareData(Printable): if self.getData() is False: return False else: - listData = filter(lambda x: x[0] == name, self.data) + # listData = filter(lambda x: x[0] == name, self.data) + listData = [x for x in self.data if x[0] == name] if listData: return listData[0] else: @@ -174,7 +175,8 @@ class group(_shareData): if self.getData() is False: return False else: - delEmpty = lambda y: filter(lambda x: x.strip(), y) + # delEmpty = lambda y: filter(lambda x: x.strip(), y) + delEmpty = lambda y: [x for x in y if x.strip()] flagFound = False for index, listDataOld in enumerate(self.data): if name == listDataOld[0]: @@ -219,8 +221,7 @@ class group(_shareData): if self.getData() is False: return False else: - dataGroup = map(lambda x: x[3].split(","), - filter(lambda x: x[0] == name, self.data)) + dataGroup = [x[3].split(",") for x in self.data if x[0] == name] if dataGroup: return dataGroup[0] else: @@ -234,8 +235,9 @@ class group(_shareData): for dataList in self.data: groupName, x, gid, userList = dataList if groupName in groups: - usersList = ",".join(filter(lambda x: x != userName, - userList.split(","))) + # usersList = ",".join(filter(lambda x: x != userName, + # userList.split(","))) + usersList = ",".join([x for x in userList.split(",") if x != userName]) dataList[3] = usersList data.append(dataList) self.data = data @@ -293,7 +295,7 @@ class _shareCache(_shareData): modeFile = 0o600 if getModeFile(self.fileName, mode="mode") != modeFile: os.chmod(self.fileName, modeFile) - buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n" + buff = "\n".join((":".join(x) for x in self.data)) + "\n" FD = open(self.fileName, "w+") FD.write(buff) FD.close() @@ -421,10 +423,8 @@ class userCache(Printable): if not cacheCreatePasswdObj.save(): return False # delete groups - usersGids = map(lambda x: x[3], cacheCreatePasswdObj.data) - deleteGroups = map(lambda x: x[0], - filter(lambda x: not x[2] in usersGids and not x[3], - cacheCreateGroupObj.data)) + usersGids = [x[3] for x in cacheCreatePasswdObj.data] + deleteGroups = [x[0] for x in cacheCreateGroupObj.data if not x[2] in usersGids and not x[3]] for delGroupName in deleteGroups: if not cacheCreateGroupObj.delete(delGroupName): return False @@ -454,10 +454,8 @@ class userCache(Printable): if not cachePasswdObj.save(): return False # delete groups - usersGids = map(lambda x: x[3], cachePasswdObj.data) - deleteGroups = map(lambda x: x[0], - filter(lambda x: not x[2] in usersGids and not x[3], - cacheGroupObj.data)) + usersGids = [x[3] for x in cachePasswdObj.data] + deleteGroups = [x[0] for x in cacheGroupObj.data if not x[2] in usersGids and not x[3]] for delGroupName in deleteGroups: if not cacheGroupObj.delete(delGroupName): return False @@ -497,11 +495,11 @@ class userCache(Printable): return False cacheCreateGroupObj = cacheCreateGroup(self) secondUsersGroups = groupObj.getSecondUserGroups(userName) - usersGids = map(lambda x: x[3], passwdObj.data) + usersGids = [x[3] for x in passwdObj.data] listGroupDataWork = [] for index, groupData in enumerate(listGroupData): groupName, x, gid, listUsers = groupData - listUsers = filter(lambda x: x.strip(), listUsers.split(',')) + listUsers = [x.strip() for x in listUsers.split(',')] listUsers = ",".join(filter(lambda x: x != userName, listUsers)) cacheCreateGroupData = cacheCreateGroupObj.get(groupName) if cacheCreateGroupData is False: @@ -546,7 +544,7 @@ class userCache(Printable): cacheCreateListPasswdData = cacheCreatePasswdObj.getData() if cacheCreateListPasswdData is False: return False - delUsersPasswd = map(lambda x: x[0], cacheCreateListPasswdData) + delUsersPasswd = [x[0] for x in cacheCreateListPasswdData] for delUser in delUsersPasswd: if not self.delUserFromSystem(delUser): return False @@ -573,8 +571,8 @@ class userCache(Printable): if cacheListCreatePasswdData is False: return False # remove deleted users - cacheUsers = map(lambda x: x[0], cacheListPasswdData) - createUsers = map(lambda x: x[0], cacheListCreatePasswdData) + cacheUsers = [x[0] for x in cacheListPasswdData] + createUsers = [x[0] for x in cacheListCreatePasswdData] deletedUsers = list(set(createUsers) - set(cacheUsers)) for delUser in deletedUsers: if not self.delUserFromSystem(delUser): @@ -645,9 +643,11 @@ class userCache(Printable): retGroup = groupObj.get(groupName) if retGroup is False: return False - listUsers = filter(lambda x: x.strip(), listUsers.split(',')) + # listUsers = filter(lambda x: x.strip(), listUsers.split(',')) + listUsers = [x for x in listUsers.split(',') if x.strip()] if setAddUsers & set(listUsers) or gid in addUsersGid: - listUsers = filter(lambda x: not x in notAddUsers, listUsers) + # listUsers = filter(lambda x: not x in notAddUsers, listUsers) + listUsers = [x for x in listUsers if not x in notAddUsers] if not retGroup: if not cacheCreateGroupObj.add(groupName, gid, listUsers): return False @@ -687,8 +687,7 @@ class userCache(Printable): if not ldapData: deletedCacheUsers.append(userName) continue - cacheGroupData = map(lambda x: x[0], filter(lambda x: x[2] == gid, - cacheListGroupData)) + cacheGroupData = [x[0] for x in cacheListGroupData if x[2] == gid] if not cacheGroupData: deletedCacheUsers.append(userName) continue @@ -702,9 +701,7 @@ class userCache(Printable): x, x, shadowLastChange, shadowMin, shadowMax, shadowWarning, \ x, x, x = cacheShadowData groups = cacheGroupObj.getSecondUserGroups(userName) - gidsGroups = map(lambda x: x[2], - filter(lambda x: x[0] in groups, - cacheGroupObj.data)) + gidsGroups = [x[2] for x in cacheGroupObj.data if x[0] in groups] userShadowDict = {'uid': uid, 'gid': gid, 'fullName': gecos, @@ -720,8 +717,7 @@ class userCache(Printable): for attr, value in userShadowDict.items(): if attr == "groups": for index, val in enumerate(value): - if set(map(lambda x: x[index], - ldapData[attr])) != set(val): + if set([x[index] for x in ldapData[attr]]) != set(val): flagDeleteUser = True break else: diff --git a/pym/client/rsync.py b/pym/client/rsync.py index dd7cbd1..cba2bc2 100644 --- a/pym/client/rsync.py +++ b/pym/client/rsync.py @@ -24,7 +24,7 @@ from calculate.lib.utils.files import readFile class ProfileSyncerError(Exception): pass -class ProfileSyncer(object): +class ProfileSyncer(): def __init__(self, hostname, port, username, passwd): self.hostname = hostname self.port = port diff --git a/pym/client/variables/client.py b/pym/client/variables/client.py index 2e027c8..dc86793 100644 --- a/pym/client/variables/client.py +++ b/pym/client/variables/client.py @@ -293,7 +293,7 @@ class VariableClClientLogin(user.VariableUrLogin): def choice(self): loginChoice = user.VariableUrLogin.choice(self) if self.Get('cl_action') == 'passwd': - return filter(lambda x: x != "root", loginChoice) + return [x for x in loginChoice if x != "root"] else: return loginChoice @@ -544,7 +544,7 @@ class VariableClClientUserMountHost(FieldValue, ReadonlyVariable): column = 3 -class SyncHelper(object): +class SyncHelper(): """ Вспомогательный объект для определения статуса синхронизации и времени по конфигурационным файлам @@ -597,9 +597,8 @@ class SyncHelper(object): objConfig) timeLogout = data["date_logout"] timeConfig = data["date"] - dates = filter(None, - [self.convertDate(timeLogout), - self.convertDate(timeConfig)]) + dates = [x for x in [self.convertDate(timeLogout), + self.convertDate(timeConfig)] if x] if dates: return dates[0] return "" @@ -644,9 +643,8 @@ class SyncHelper(object): cpRemote.read_string(desktopEnvRemoteData) timeLogout = cpRemote.get("main", "date_logout", fallback=None) timeConfig = cpRemote.get("main", "date", fallback=None) - dates = filter(None, - [self.convertDate(timeLogout), - self.convertDate(timeConfig)]) + dates = [x for x in [self.convertDate(timeLogout), + self.convertDate(timeConfig)] if x] if dates: return dates[0] return "" @@ -789,11 +787,10 @@ class VariableClClientSymlinks(ReadonlyVariable): def get(self): skipFiles = (self.Get('cl_sync_del_path') + self.Get('cl_sync_skip_path')) - reSkip = re.compile("|".join(map(lambda x: x.replace("*", ".*"), - skipFiles))).search - return filter(lambda x: not reSkip(x), - find(self.Get('ur_home_path'), onefilesystem=True, - filetype=FindFileType.SymbolicLink)) + reSkip = re.compile("|".join((x.replace("*", ".*") for x in skipFiles))).search + return [x for x in find(self.Get('ur_home_path'), onefilesystem=True, + filetype=FindFileType.SymbolicLink) + if not reSkip(x)] class VariableClClientNscdCache(Variable):