def test_humanize_filesize(): print humanize_filesize(20000000) assert humanize_filesize(256) == '256.0B' assert humanize_filesize(1024) == '1.0K' assert humanize_filesize(1048576) == '1.0M' assert humanize_filesize(2000000) == '1.9M' assert humanize_filesize(157286400) == '150.0M' assert humanize_filesize(20000000) == '19.1M' assert humanize_filesize(1073741824) == '1.0G' assert humanize_filesize(5000000000) == '4.7G'
def __init__(self, filepath, basedir='/'): self.filepath = filepath self.path = os.path.sep + os.path.relpath(filepath, basedir) self.bytes = os.path.getsize(filepath) self.size = humanize_filesize(self.bytes) self.name = os.path.basename(filepath) self.url = 'file://' + filepath self.content_type = 'application/netcdf' self.resourcename = filepath self._last_modified = None self.attributes = {} self._parse(filepath)