Esempio n. 1
0
    def load(self, filename):
        """
        Load pickle dumped filename into a Result instance

        :param string filename: file path name
        """
        if not os.path.exists(filename):
            raise KiwiResultError('No result information %s found' % filename)
        try:
            with open(filename, 'rb') as result:
                return pickle.load(result)
        except Exception as e:
            raise KiwiResultError('Failed to pickle load results: %s' %
                                  type(e).__name__)
Esempio n. 2
0
    def dump(self, filename: str, portable: bool = True) -> None:
        """
        Picke dump this instance to a file

        :param str filename: file path name
        :param bool portable:
            If set to true also create a .json formatted variant
            of the dump file which contains the elements of this
            instance that could be expressed in a portable json
            document. Default is set to: True

        :raises KiwiResultError: if pickle fails to dump :class:`Result`
            instance
        """
        try:
            with open(filename, 'wb') as result:
                pickle.dump(self, result)
            if portable:
                with open(filename + '.json', 'w') as result_portable:
                    result_portable.write(
                        simplejson.dumps(
                            self.result_files, sort_keys=True, indent=4) +
                        os.linesep)
        except Exception as e:
            raise KiwiResultError('Failed to pickle dump results: %s' %
                                  format(e))
Esempio n. 3
0
    def load(filename: str) -> result_type:
        """
        Load pickle dumped filename into a Result instance

        :param str filename: file path name

        :raises KiwiResultError: if filename does not exist or pickle fails
            to load filename
        """
        if not os.path.exists(filename):
            raise KiwiResultError('No result information %s found' % filename)
        try:
            with open(filename, 'rb') as result:
                return pickle.load(result)
        except Exception as e:
            raise KiwiResultError('Failed to pickle load results: %s' %
                                  type(e).__name__)
Esempio n. 4
0
    def dump(self, filename):
        """
        Picke dump this instance to a file

        :param string filename: file path name
        """
        try:
            with open(filename, 'wb') as result:
                pickle.dump(self, result)
        except Exception as e:
            raise KiwiResultError('Failed to pickle dump results: %s' %
                                  format(e))
Esempio n. 5
0
    def verify_image_size(self, size_limit, filename):
        """
        Verifies the given image file does not exceed the size limit.
        Throws an exception if the limit is exceeded. If the size limit
        is set to None no verification is done.

        :param int size_limit: The size limit for filename in bytes.
        :param string filename: File to verify.
        """
        if size_limit is not None:
            if os.path.getsize(filename) > size_limit:
                raise KiwiResultError(
                    'Build constraint failed: {0} is bigger than {1}'
                    .format(filename, size_limit)
                )
Esempio n. 6
0
    def dump(self, filename: str) -> None:
        """
        Picke dump this instance to a file

        :param str filename: file path name

        :raises KiwiResultError: if pickle fails to dump :class:`Result`
            instance
        """
        try:
            with open(filename, 'wb') as result:
                pickle.dump(self, result)
        except Exception as e:
            raise KiwiResultError('Failed to pickle dump results: %s' %
                                  format(e))