Exemple #1
0
    def info(self, filepath, status, verbose=False):
        """
        Print information about the processed file and its status.
        """
        if verbose and not settings.TEST:
            if not filepath.startswith('/'):
                filepath = '/' + filepath

            print '%-65s  [%s]' % (excerpt_from_text(
                filepath, length=62, prefix=True), status)
Exemple #2
0
    def _update(self, verbose=False):
        """
        Update font cache and download missing font resources.
        """
        out('Updating font cache...Please Wait...', verbose=verbose)

        # get list of used fonts.
        font_declarations = self.get_used_font_declarations()
        if not font_declarations:
            return

        # get available backends and raise error, if we do not have at least
        # one font backend available to us...
        backends = self.get_backends()
        if not backends:
            raise ValueError(
                'Unable to update fonts because no font backend is ' + \
                'available. Please make sure that a list of font backends ' + \
                'is defined as \'CUBANE_FONT_BACKENDS\' in settings and ' + \
                'that each module path is correct and the module ' + \
                'can be imported.'
            )

        for font_declaration in font_declarations:
            if not self.is_font_cached(font_declaration.font_name):
                if self._cache_font(backends, font_declaration):
                    status = 'UPDATED'
                else:
                    status = 'NOT FOUND'

                    # raise error on debug, so the developer will instantly
                    # notice that a font could not be found, perhabs because
                    # of a spelling error...
                    if settings.DEBUG:
                        raise ValueError(
                            ('The font \'%s\' could not be found by any ' + \
                             'of the installed font backends.') %
                                 font_declaration.font_name
                        )
            else:
                status = 'CACHED'

            if not settings.TEST and verbose: # pragma: no cover
                print '%-35s  [%s]' % (
                    excerpt_from_text(
                        font_declaration.font_name,
                        length=32,
                        prefix=True
                    ),
                    status
                )
Exemple #3
0
 def get_excerpt(self, length=settings.CMS_EXCERPT_LENGTH):
     if self._excerpt:
         return excerpt_from_text(self._excerpt, length)
     else:
         return self.generate_excerpt(length)
Exemple #4
0
 def test_except_from_text_should_slice_left_padded_in_prefix_mode(self):
     self.assertEqual(
         excerpt_from_text('Hello World', length=3, prefix=True), '...rld')
Exemple #5
0
 def test_excerpt_from_text_should_trim_after_slice(self):
     self.assertEqual(excerpt_from_text('Hello   World', length=8),
                      'Hello...')
Exemple #6
0
 def test_excerpt_from_text_should_return_empty_string_for_none(self):
     self.assertEqual(excerpt_from_text(None), '')