mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
more closely matching file object
This commit is contained in:
parent
d3226bd9c3
commit
2ced3fd7d2
@ -3,7 +3,6 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class RotatingLog:
|
class RotatingLog:
|
||||||
"""
|
"""
|
||||||
A file() (or open()) replacement that will automatically open and write
|
A file() (or open()) replacement that will automatically open and write
|
||||||
@ -37,7 +36,14 @@ class RotatingLog:
|
|||||||
self.file.flush()
|
self.file.flush()
|
||||||
self.file.close()
|
self.file.close()
|
||||||
del self.file
|
del self.file
|
||||||
|
if hasattr(self, "closed"):
|
||||||
|
del self.closed
|
||||||
|
del self.mode
|
||||||
|
del self.name
|
||||||
|
del self.softspace
|
||||||
|
#del self.encoding
|
||||||
|
#del self.newlines
|
||||||
|
|
||||||
def shouldRotate(self):
|
def shouldRotate(self):
|
||||||
"""
|
"""
|
||||||
Returns a bool about whether a new log file should
|
Returns a bool about whether a new log file should
|
||||||
@ -61,7 +67,7 @@ class RotatingLog:
|
|||||||
# Hmm, 26 files are full? throw the rest in z:
|
# Hmm, 26 files are full? throw the rest in z:
|
||||||
# Maybe we should clear the self.sizeLimit here... maybe.
|
# Maybe we should clear the self.sizeLimit here... maybe.
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def rotate(self):
|
def rotate(self):
|
||||||
"""
|
"""
|
||||||
Rotate the log now. You normally shouldn't need to call this.
|
Rotate the log now. You normally shouldn't need to call this.
|
||||||
@ -76,6 +82,15 @@ class RotatingLog:
|
|||||||
# until the first write:
|
# until the first write:
|
||||||
file.seek(0, 2)
|
file.seek(0, 2)
|
||||||
self.file=file
|
self.file=file
|
||||||
|
|
||||||
|
# Some of these data members may be expected by some of our clients:
|
||||||
|
self.closed = self.file.closed
|
||||||
|
self.mode = self.file.mode
|
||||||
|
self.name = self.file.name
|
||||||
|
self.softspace = self.file.softspace
|
||||||
|
#self.encoding = self.file.encoding # Python 2.3
|
||||||
|
#self.newlines = self.file.newlines # Python 2.3, maybe
|
||||||
|
|
||||||
if self.timeLimit is not None and time.time() > self.timeLimit:
|
if self.timeLimit is not None and time.time() > self.timeLimit:
|
||||||
self.timeLimit=time.time()+self.timeInterval
|
self.timeLimit=time.time()+self.timeInterval
|
||||||
else:
|
else:
|
||||||
@ -91,6 +106,42 @@ class RotatingLog:
|
|||||||
if self.shouldRotate():
|
if self.shouldRotate():
|
||||||
self.rotate()
|
self.rotate()
|
||||||
if hasattr(self, "file"):
|
if hasattr(self, "file"):
|
||||||
self.file.write(data)
|
r = self.file.write(data)
|
||||||
self.file.flush()
|
self.file.flush()
|
||||||
|
return r
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
return self.file.flush()
|
||||||
|
|
||||||
|
def fileno(self):
|
||||||
|
return self.file.fileno()
|
||||||
|
|
||||||
|
def isatty(self):
|
||||||
|
return self.file.isatty()
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
return self.file.next()
|
||||||
|
|
||||||
|
def read(self, size):
|
||||||
|
return self.file.read(size)
|
||||||
|
|
||||||
|
def readline(self, size):
|
||||||
|
return self.file.readline(size)
|
||||||
|
|
||||||
|
def readlines(self, sizehint):
|
||||||
|
return self.file.readlines(sizehint)
|
||||||
|
|
||||||
|
def xreadlines(self):
|
||||||
|
return self.file.xreadlines()
|
||||||
|
|
||||||
|
def seek(self, offset, whence=0):
|
||||||
|
return self.file.seek(offset, whence)
|
||||||
|
|
||||||
|
def tell(self):
|
||||||
|
return self.file.tell()
|
||||||
|
|
||||||
|
def truncate(self, size):
|
||||||
|
return self.file.truncate(size)
|
||||||
|
|
||||||
|
def writelines(self, sequence):
|
||||||
|
return self.file.writelines(sequence)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user