def get_file_stat(path):
"""
This is a helper function that given a local path return the size of
the file in bytes and time of last modification.
"""
try:
stats = os.stat(path)
except IOError as e:
raise ValueError('Could not retrieve file stat of "%s": %s' % (
path, e))
try:
update_time = datetime.fromtimestamp(stats.st_mtime, tzlocal())
except (ValueError, OSError, OverflowError):
# Python's fromtimestamp raises value errors when the timestamp is out
# of range of the platform's C localtime() function. This can cause
# issues when syncing from systems with a wide range of valid
# timestamps to systems with a lower range. Some systems support
# 64-bit timestamps, for instance, while others only support 32-bit.
# We don't want to fail in these cases, so instead we pass along none.
update_time = None
return stats.st_size, update_time
评论列表
文章目录