def main(no_dry, wheel_dir): """Remove old Python Wheels from local directory.""" pruned_bytes = bitmath.MiB() for old_wheel in old_wheels(wheel_dir): pruned_bytes += bitmath.getsize(old_wheel.path) if no_dry: old_wheel.path.unlink() LOG.info('Removed: %s', old_wheel.path) else: LOG.info('Would delete: %s', old_wheel.path) LOG.info('Freed: %s', pruned_bytes)
def file_size_check(filename, filetype, file_id, db_cursor, logger): """ Check if a file is within the size limits """ import bitmath file_size = os.path.getsize(filename) if filetype == "tif": if file_size < settings.tif_size_min: file_size = 1 file_size_info = "TIF file is smaller than expected ({})".format( bitmath.getsize(filename, system=bitmath.SI)) elif file_size > settings.tif_size_max: file_size = 1 file_size_info = "TIF file is larger than expected ({})".format( bitmath.getsize(filename, system=bitmath.SI)) else: file_size = 0 file_size_info = "{}".format( bitmath.getsize(filename, system=bitmath.SI)) file_check = 'tif_size' elif filetype == "raw": if file_size < settings.raw_size_min: file_size = 1 file_size_info = "RAW file is smaller than expected ({})".format( bitmath.getsize(filename, system=bitmath.SI)) elif file_size > settings.raw_size_max: file_size = 1 file_size_info = "RAW file is larger than expected ({})".format( bitmath.getsize(filename, system=bitmath.SI)) else: file_size = 0 file_size_info = "{}".format( bitmath.getsize(filename, system=bitmath.SI)) file_check = 'raw_size' db_cursor.execute( queries.file_check, { 'file_id': file_id, 'file_check': file_check, 'check_results': file_size, 'check_info': file_size_info }) logger.debug(db_cursor.query.decode("utf-8")) return True
def test_getsize_kibibyte_system_SI(self): """SI: getsize reports the correct type and size for kibibyte sized files""" expected = bitmath.kB(bytes=1024) result = bitmath.getsize(self.kibibyte_file, system=bitmath.SI) self.assertEqual(result, expected) self.assertIs(type(result), bitmath.kB)
def test_getsize_byte_system_NIST(self): """NIST: getsize reports the correct type and size for byte sized files""" expected = bitmath.Byte(bytes=38) result = bitmath.getsize(self.byte_file, system=bitmath.NIST) self.assertEqual(result, expected) self.assertIs(type(result), bitmath.Byte)
def calculateSize(self): return bitmath.getsize(self._output_file).format("{value:.2f} {unit}")