Source code for pyensae.filehelper.format_helper

"""
Various functions to display information about files


:githublink:`%|py|5`
"""

import datetime


[docs]def format_file_size(size): """ Formats the file size as string. :param size: numeric value :return: string (something + unit) :githublink:`%|py|15` """ if size >= 2 ** 30: size = size / 2 ** 30 return "%1.2f Gb" % size elif size >= 2 ** 20: size = size / 2 ** 20 return "%1.2f Mb" % size elif size >= 2 ** 10: size = size / 2 ** 10 return "%1.2f Kb" % size else: return "%d" % size
[docs]def format_file_mtime(timestamp): """ Returns a :epkg:`datetime` for a file. :param timestamp: modified date for example :return: datetime :githublink:`%|py|35` """ return datetime.datetime.fromtimestamp(timestamp)