Example #1
0
    def CheckNetworkDownload(self, possible_mime, num_bytes,
                             is_complete_file_size):

        if is_complete_file_size:

            error_prefix = 'Download was apparently '

        else:

            error_prefix = 'Download was at least '

        if possible_mime is not None:

            if possible_mime == HC.IMAGE_GIF and self._max_gif_size is not None and num_bytes > self._max_gif_size:

                raise HydrusExceptions.FileImportRulesException(
                    error_prefix + HydrusData.ToHumanBytes(num_bytes) +
                    ' but the upper limit for gifs is ' +
                    HydrusData.ToHumanBytes(self._max_gif_size) + '.')

        if self._max_size is not None and num_bytes > self._max_size:

            raise HydrusExceptions.FileImportRulesException(
                error_prefix + HydrusData.ToHumanBytes(num_bytes) +
                ' but the upper limit is ' +
                HydrusData.ToHumanBytes(self._max_size) + '.')

        if is_complete_file_size:

            if self._min_size is not None and num_bytes < self._min_size:

                raise HydrusExceptions.FileImportRulesException(
                    error_prefix + HydrusData.ToHumanBytes(num_bytes) +
                    ' but the lower limit is ' +
                    HydrusData.ToHumanBytes(self._min_size) + '.')
Example #2
0
    def CheckFileIsValid(self, size, mime, width, height):

        if self._min_size is not None and size < self._min_size:

            raise HydrusExceptions.FileImportRulesException(
                'File was ' + HydrusData.ToHumanBytes(size) +
                ' but the lower limit is ' +
                HydrusData.ToHumanBytes(self._min_size) + '.')

        if self._max_size is not None and size > self._max_size:

            raise HydrusExceptions.FileImportRulesException(
                'File was ' + HydrusData.ToHumanBytes(size) +
                ' but the upper limit is ' +
                HydrusData.ToHumanBytes(self._max_size) + '.')

        if mime == HC.IMAGE_GIF and self._max_gif_size is not None and size > self._max_gif_size:

            raise HydrusExceptions.FileImportRulesException(
                'File was ' + HydrusData.ToHumanBytes(size) +
                ' but the upper limit for gifs is ' +
                HydrusData.ToHumanBytes(self._max_gif_size) + '.')

        if self._min_resolution is not None:

            (min_width, min_height) = self._min_resolution

            too_thin = width is not None and width < min_width
            too_short = height is not None and height < min_height

            if too_thin or too_short:

                raise HydrusExceptions.FileImportRulesException(
                    'File had resolution ' +
                    HydrusData.ConvertResolutionToPrettyString((width,
                                                                height)) +
                    ' but the lower limit is ' +
                    HydrusData.ConvertResolutionToPrettyString(
                        self._min_resolution))

        if self._max_resolution is not None:

            (max_width, max_height) = self._max_resolution

            too_wide = width is not None and width > max_width
            too_tall = height is not None and height > max_height

            if too_wide or too_tall:

                raise HydrusExceptions.FileImportRulesException(
                    'File had resolution ' +
                    HydrusData.ConvertResolutionToPrettyString((width,
                                                                height)) +
                    ' but the upper limit is ' +
                    HydrusData.ConvertResolutionToPrettyString(
                        self._max_resolution))