Рефакторинг: работа с файлами

legacy27
Mike Hiretsky 5 years ago
parent 5f80b4f3e3
commit b0ac9587b2

@ -180,9 +180,9 @@ def getPasswdUsers(minId=1000, maxId=65000, prefix="/",
if os.access(fileName, os.R_OK):
reNumb = re.compile("^\d+$")
lenData = 7
userData = filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"),
open(fileName)))
with open(fileName) as f:
userData = filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), f))
userData = filter(
lambda x: reNumb.match(x[2]) and minId <= int(x[2]) <= maxId,
userData)

@ -651,7 +651,7 @@ def check_rw(dn):
while mark_file is None or path.exists(mark_file):
mark_file = path.join(dn, "_mark_%s" % _random_string())
try:
open(mark_file, 'w')
open(mark_file, 'w').close()
os.unlink(mark_file)
return True
except (OSError, IOError):

@ -69,7 +69,8 @@ class InitrdFile(object):
def get_names(self):
if not path.exists(self._file):
# raise IOError
open(self._file)
with open(self._file, 'r'):
pass
buftype = typeFile(magic=0x4).getMTypeBuf
rdtype = buftype(self.skipcpio_data(self._file))
if "LZ4" in rdtype:

@ -218,13 +218,13 @@ def childMounts(pathname):
mtabFile = '/etc/mtab'
if not os.access(mtabFile, os.R_OK):
return ""
return reduce(lambda x, y: x + [y],
filter(lambda x: commonPath(absPath, x[0]) == absPath or \
commonPath(absPath, x[1]) == absPath,
map(lambda x: [x[0], x[1]],
map(lambda x: x.split(" "),
open(mtabFile)))),
[])
with open(mtabFile) as f:
return reduce(lambda x, y: x + [y],
filter(lambda x: commonPath(absPath, x[0]) == absPath or \
commonPath(absPath, x[1]) == absPath,
map(lambda x: [x[0], x[1]],
map(lambda x: x.split(" "), f))),
[])
class MountError(Exception):
pass

Loading…
Cancel
Save