modernized setup, changed os.path.walk to os.walk

py3_forced
parent 02811f6775
commit 8f18d742f1

@ -1941,27 +1941,26 @@ class _file(_error):
self.links = []
self.sockets = []
self.fifo = []
def getFilesDir(dirP, dirname,names):
for nameFile in names:
absNameFile = dirname + "/" + nameFile
if os.path.islink(absNameFile):
dest = absNameFile
src = os.readlink(absNameFile)
dirP.links.append((src,dest))
elif os.path.isfile(absNameFile):
dirP.files.append(absNameFile)
elif os.path.isdir(absNameFile):
dirP.dirs.append(absNameFile)
elif stat.S_ISSOCK(os.stat(absNameFile)[stat.ST_MODE]):
dirP.sockets.append(absNameFile)
elif stat.S_ISFIFO(os.stat(absNameFile)[stat.ST_MODE]):
dirP.fifo.append(absNameFile)
for profileDir in profilesDirs:
if profileDir:
dirP = dirProf()
dirP.baseDir = profileDir
for dirname, dirs, files in os.walk(profileDir):
for nameFile in dirs + files:
absNameFile = dirname + "/" + nameFile
if os.path.islink(absNameFile):
dest = absNameFile
src = os.readlink(absNameFile)
dirP.links.append((src,dest))
elif os.path.isfile(absNameFile):
dirP.files.append(absNameFile)
elif os.path.isdir(absNameFile):
dirP.dirs.append(absNameFile)
elif stat.S_ISSOCK(os.stat(absNameFile)[stat.ST_MODE]):
dirP.sockets.append(absNameFile)
elif stat.S_ISFIFO(os.stat(absNameFile)[stat.ST_MODE]):
dirP.fifo.append(absNameFile)
dirs.append(dirP)
os.path.walk(profileDir,getFilesDir, dirP)
return dirs
def __absFileName(self, nameFile):
@ -2725,17 +2724,16 @@ class profile(_file, _terms, xmlShare, processingTemplates):
def getInstallPkgGentoo():
"""Выдает словарь инсталлированных программ и номеров версий"""
pkgs = []
def getFilesDir(pkgs, dirname, names):
for nameFile in names:
absNameFile = os.path.join(dirname,nameFile)
for dirname, dirs, files in os.walk(self.basePkgDir):
for nameFile in dirs + files:
absNameFile = os.path.join(dirname, nameFile)
if os.path.isdir(absNameFile):
tail = absNameFile.split(self.basePkgDir)
if len(tail)==2:
if len(tail) == 2:
tail = tail[1].split('/')
if len(tail)==3 and tail[1]!='virtual':
if len(tail) == 3 and tail[1] != 'virtual':
pkgs.append(tail[2])
return True
os.path.walk(self.basePkgDir,getFilesDir, pkgs)
return sharePkg(pkgs)
def sharePkg(pkgs):
@ -3256,7 +3254,7 @@ class profile(_file, _terms, xmlShare, processingTemplates):
"""
return True
#TODO rewrite with os.walk
def scanDirs(self, profilesDirs, objVar=False):
"""Измененный метод сканирования директорий"""
dirs = []
@ -3269,40 +3267,7 @@ class profile(_file, _terms, xmlShare, processingTemplates):
self.sockets = []
flagError = False
blockDirs = []
def getFilesDir(dirP, dirname, names):
for nameFile in names:
absNameFile = dirname + "/" + nameFile
findBlock = False
for blDir in blockDirs:
st,mid,end = absNameFile.partition(blDir)
if (not st) and mid and end:
findBlock = True
break
if not findBlock:
if os.path.islink(absNameFile):
dest = absNameFile
src = os.readlink(absNameFile)
dirP.links.append((src,dest))
elif os.path.isfile(absNameFile):
# Добавляем файлы кроме описаний директорий
if self.profDirNameFile != nameFile:
dirP.files.append(absNameFile)
elif os.path.isdir(absNameFile):
# Обработка условий в названии директории
if self.getNeedProfile(absNameFile):
if self.getError():
blockDirs.append(absNameFile)
flagError = True
break
dirP.dirs.append(absNameFile)
else:
if self.getError():
blockDirs.append(absNameFile)
flagError = True
break
blockDirs.append(absNameFile)
elif stat.S_ISSOCK(os.stat(absNameFile)[stat.ST_MODE]):
dirP.sockets.append(absNameFile)
for profileDir in profilesDirs:
if profileDir:
# Обработка условий в названии директории
@ -3312,8 +3277,41 @@ class profile(_file, _terms, xmlShare, processingTemplates):
break
dirP = dirProf()
dirP.baseDir = profileDir
for dirname, dirs, files in os.walk(profileDir):
for nameFile in dirs + files:
absNameFile = dirname + "/" + nameFile
findBlock = False
for blDir in blockDirs:
st,mid,end = absNameFile.partition(blDir)
if (not st) and mid and end:
findBlock = True
break
if not findBlock:
if os.path.islink(absNameFile):
dest = absNameFile
src = os.readlink(absNameFile)
dirP.links.append((src,dest))
elif os.path.isfile(absNameFile):
# Добавляем файлы кроме описаний директорий
if self.profDirNameFile != nameFile:
dirP.files.append(absNameFile)
elif os.path.isdir(absNameFile):
# Обработка условий в названии директории
if self.getNeedProfile(absNameFile):
if self.getError():
blockDirs.append(absNameFile)
flagError = True
break
dirP.dirs.append(absNameFile)
else:
if self.getError():
blockDirs.append(absNameFile)
flagError = True
break
blockDirs.append(absNameFile)
elif stat.S_ISSOCK(os.stat(absNameFile)[stat.ST_MODE]):
dirP.sockets.append(absNameFile)
dirs.append(dirP)
os.path.walk(profileDir, getFilesDir, dirP)
else:
if self.getError():
flagError = True

@ -542,7 +542,7 @@ class SortMilter(Milter.Milter):
def close(self):
"""Execute after end of connect (include error disconnect)"""
return Milter.CONTINUE
#TODO rewrite with os.walk
def getMailFromFolder(dir):
# find all files in specified directory and generate list of Letter
for root, dirs, files in os.walk(dir):

@ -47,24 +47,24 @@ def scanDirs(profilesDirs):
self.baseDir = False
self.dirs = []
self.files = []
def getFilesDir(dirP, dirname,names):
if '/.svn' in dirname:
return False
for nameFile in names:
absNameFile = dirname + "/" + nameFile
if '/.svn' in absNameFile:
continue
if os.path.isfile(absNameFile):
dirP.files.append(absNameFile)
elif os.path.isdir(absNameFile):
dirP.dirs.append(absNameFile)
return True
for profileDir in profilesDirs:
if profileDir:
dirP = dirProf()
dirP.baseDir = profileDir
for dirname, dirs, files in os.walk(profileDir):
if '/.svn' in dirname:
return False
for nameFile in files:
absNameFile = dirname + "/" + nameFile
if '/.svn' in absNameFile:
continue
dirP.files.append(absNameFile)
for nameDir in dirs:
absNameDir = dirname + "/" + nameDir
if '/.svn' in absNameDir:
continue
dirP.dirs.append(absNameDir)
dirs.append(dirP)
os.path.walk(profileDir,getFilesDir, dirP)
return dirs
def create_data_files (data_dirs, prefix=""):
@ -85,7 +85,8 @@ def create_data_files (data_dirs, prefix=""):
break
for files_obj_dir in files_obj_dirs:
obj.dirs.remove(files_obj_dir)
files_obj_dirs.sort(lambda x, y: cmp(len(y), len(x)))
# files_obj_dirs.sort(lambda x, y: cmp(len(y), len(x)))
files_obj_dirs.sort(key=len)
for dir_name in files_obj_dirs:
wr_sp = (prefix+dir_name,[])
file_dirs = []
@ -147,7 +148,7 @@ class cl_install_data(install_data):
("/etc/conf.d/sortmilter.conf","sortmilter",None)]
data_find = \
dict(
[(os.path.basename(x[0]), [list(reversed((y for y in x[0].split("/") if y))), x[1],x[2]]) for x in data_file])
[(os.path.basename(x[0]), [list(reversed([y for y in x[0].split("/") if y])), x[1],x[2]]) for x in data_file])
for path in self.get_outputs():
nameFile = os.path.split(path)[1]

Loading…
Cancel
Save