def read(self):
"""
Returns RFC 3339 timestamp string. Tries to read given file.
If file cannot be read, current time is returned.
"""
logging.debug("Looking for bookmark file")
try:
if os.path.getsize(self.bmfile) < 10:
logging.error("Bookmark file appears corrupt: %s", self.bmfile)
self._generate_bm_time()
return self.s_time
except FileNotFoundError:
logging.debug("Bookmark file not found: %s.", self.bmfile)
self._generate_bm_time()
return self.s_time
try:
with open(self.bmfile, 'r') as self.open_bmfile:
logging.debug("Opening: %s", self.bmfile)
self.bookmark = self.open_bmfile.read()
logging.debug("File found. Reading timestamp: %s",
convert_time(self.bookmark))
if validate_time('s', self.bookmark):
logging.debug("Bookmark time is valid")
self.s_time = self.bookmark
return self.s_time
else:
logging.error("Invalid bookmark data. Using current time")
self._generate_bm_time()
return self.s_time
except OSError:
logging.debug("Bookmark file cannot be accessed: %s.", self.bmfile)
self._generate_bm_time()
return self.s_time
评论列表
文章目录