|
|
|
@ -640,11 +640,19 @@ def readLinesFile(filename):
|
|
|
|
|
finally:
|
|
|
|
|
raise StopIteration
|
|
|
|
|
|
|
|
|
|
def readFile(filename):
|
|
|
|
|
"""Read whole file or return empty string"""
|
|
|
|
|
def readFile(filename,tailbyte=None):
|
|
|
|
|
"""
|
|
|
|
|
Прочитать целый файл или вернуть пустую строку.
|
|
|
|
|
tailbyte: прочитать только последнее указанное количество байт
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
if path.exists(filename):
|
|
|
|
|
return open(filename,'r').read()
|
|
|
|
|
with open(filename,'r') as f:
|
|
|
|
|
if tailbyte:
|
|
|
|
|
seeksize = max(0,os.stat(filename).st_size-tailbyte)
|
|
|
|
|
if seeksize:
|
|
|
|
|
f.seek(seeksize)
|
|
|
|
|
return f.read()
|
|
|
|
|
except (OSError,IOError):
|
|
|
|
|
pass
|
|
|
|
|
return ""
|
|
|
|
|