예제 #1
0
    def test_calculate_size(self):
        test_file = open(self.test_file)
        try:
            file_size = file_utils.calculate_size(test_file)
        finally:
            test_file.close()

        self.assertEquals(file_size, 1675)
예제 #2
0
    def test_calculate_size(self):
        test_file = open(self.test_file)
        try:
            file_size = file_utils.calculate_size(test_file)
        finally:
            test_file.close()

        self.assertEquals(file_size, 1675)
예제 #3
0
파일: models.py 프로젝트: bkearney/pulp_rpm
    def calculate_size(file_handle):
        """
        Return the size of the given file-like object in Bytes.

        :param file_handle: A handle to an open file-like object
        :type  file_handle: file-like object
        :return:            The file's size, in Bytes
        :rtype:             int
        """
        # Calculate the size by seeking to the end to find the file size with tell()
        return file_utils.calculate_size(file_handle)
예제 #4
0
    def calculate_size(file_handle):
        """
        Return the size of the given file-like object in Bytes.

        :param file_handle: A handle to an open file-like object
        :type  file_handle: file-like object
        :return:            The file's size, in Bytes
        :rtype:             int
        """
        # Calculate the size by seeking to the end to find the file size with tell()
        return file_utils.calculate_size(file_handle)
예제 #5
0
    def generate_unit_key_and_metadata(filepath, **kwargs):
        """
        Analyze the ISO found at the path specified by filepath, and return its unit_key and
        metadata as a 2-tuple. Since ISOs don't have metadata, this just amounts to the unit key and
        an empty metadata dict.

        :param filepath: The path of the file that we need the unit key and metadata for
        :type  filepath: str
        :param kwargs:   Unused keyword arguments
        :type  kwargs:   dict
        :return:         A two tuple of (unit_key, metadata), both dicts
        :rtype:          tuple
        """
        iso = open(filepath)
        try:
            size = file_utils.calculate_size(iso)
            checksum = file_utils.calculate_checksum(iso)
        finally:
            iso.close()
        return {'name': os.path.basename(filepath), 'size': size, 'checksum': checksum}, {}
예제 #6
0
파일: upload.py 프로젝트: ulif/pulp_rpm
    def generate_unit_key_and_metadata(filepath, **kwargs):
        """
        Analyze the ISO found at the path specified by filepath, and return its unit_key and
        metadata as a 2-tuple. Since ISOs don't have metadata, this just amounts to the unit key and
        an empty metadata dict.

        :param filepath: The path of the file that we need the unit key and metadata for
        :type  filepath: str
        :param kwargs:   Unused keyword arguments
        :type  kwargs:   dict
        :return:         A two tuple of (unit_key, metadata), both dicts
        :rtype:          tuple
        """
        iso = open(filepath)
        try:
            size = file_utils.calculate_size(iso)
            checksum = file_utils.calculate_checksum(iso)
        finally:
            iso.close()
        return {'name': os.path.basename(filepath), 'size': size, 'checksum': checksum}, {}