mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
improve result output of a pelican run
* display count of hidden pages * pluralize only if necessary * add maybe_pluralize to utils * add tests for maybe_pluralize
This commit is contained in:
parent
940eb76b7f
commit
39fd4936b5
3 changed files with 50 additions and 7 deletions
|
|
@ -22,7 +22,8 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
TemplatePagesGenerator)
|
TemplatePagesGenerator)
|
||||||
from pelican.readers import Readers
|
from pelican.readers import Readers
|
||||||
from pelican.settings import read_settings
|
from pelican.settings import read_settings
|
||||||
from pelican.utils import clean_output_dir, folder_watcher, file_watcher
|
from pelican.utils import (clean_output_dir, folder_watcher,
|
||||||
|
file_watcher, maybe_pluralize)
|
||||||
from pelican.writers import Writer
|
from pelican.writers import Writer
|
||||||
|
|
||||||
__version__ = "3.5.0"
|
__version__ = "3.5.0"
|
||||||
|
|
@ -183,12 +184,32 @@ class Pelican(object):
|
||||||
pages_generator = next(g for g in generators
|
pages_generator = next(g for g in generators
|
||||||
if isinstance(g, PagesGenerator))
|
if isinstance(g, PagesGenerator))
|
||||||
|
|
||||||
print('Done: Processed {} article(s), {} draft(s) and {} page(s) in ' \
|
pluralized_articles = maybe_pluralize(
|
||||||
'{:.2f} seconds.'.format(
|
len(articles_generator.articles) +
|
||||||
len(articles_generator.articles) + len(articles_generator.translations),
|
len(articles_generator.translations),
|
||||||
len(articles_generator.drafts) + \
|
'article',
|
||||||
len(articles_generator.drafts_translations),
|
'articles')
|
||||||
len(pages_generator.pages) + len(pages_generator.translations),
|
pluralized_drafts = maybe_pluralize(
|
||||||
|
len(articles_generator.drafts) +
|
||||||
|
len(articles_generator.drafts_translations),
|
||||||
|
'draft',
|
||||||
|
'drafts')
|
||||||
|
pluralized_pages = maybe_pluralize(
|
||||||
|
len(pages_generator.pages) +
|
||||||
|
len(pages_generator.translations),
|
||||||
|
'page',
|
||||||
|
'pages')
|
||||||
|
pluralized_hidden_pages = maybe_pluralize(
|
||||||
|
len(pages_generator.hidden_pages) +
|
||||||
|
len(pages_generator.hidden_translations),
|
||||||
|
'hidden page',
|
||||||
|
'hidden pages')
|
||||||
|
|
||||||
|
print('Done: Processed {}, {}, {} and {} in {:.2f} seconds.'.format(
|
||||||
|
pluralized_articles,
|
||||||
|
pluralized_drafts,
|
||||||
|
pluralized_pages,
|
||||||
|
pluralized_hidden_pages,
|
||||||
time.time() - start_time))
|
time.time() - start_time))
|
||||||
|
|
||||||
def get_generator_classes(self):
|
def get_generator_classes(self):
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,12 @@ class TestUtils(LoggedTestCase):
|
||||||
locale.setlocale(locale.LC_ALL, old_locale)
|
locale.setlocale(locale.LC_ALL, old_locale)
|
||||||
|
|
||||||
|
|
||||||
|
def test_maybe_pluralize(self):
|
||||||
|
self.assertEqual(utils.maybe_pluralize(0, 'Article', 'Articles'), '0 Articles')
|
||||||
|
self.assertEqual(utils.maybe_pluralize(1, 'Article', 'Articles'), '1 Article')
|
||||||
|
self.assertEqual(utils.maybe_pluralize(2, 'Article', 'Articles'), '2 Articles')
|
||||||
|
|
||||||
|
|
||||||
class TestCopy(unittest.TestCase):
|
class TestCopy(unittest.TestCase):
|
||||||
'''Tests the copy utility'''
|
'''Tests the copy utility'''
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -767,3 +767,19 @@ def path_to_file_url(path):
|
||||||
'''Convert file-system path to file:// URL'''
|
'''Convert file-system path to file:// URL'''
|
||||||
return six.moves.urllib_parse.urljoin(
|
return six.moves.urllib_parse.urljoin(
|
||||||
"file://", six.moves.urllib.request.pathname2url(path))
|
"file://", six.moves.urllib.request.pathname2url(path))
|
||||||
|
|
||||||
|
|
||||||
|
def maybe_pluralize(count, singular, plural):
|
||||||
|
'''
|
||||||
|
Returns a formatted string containing count and plural if count is not 1
|
||||||
|
Returns count and singular if count is 1
|
||||||
|
|
||||||
|
maybe_pluralize(0, 'Article', 'Articles') -> '0 Articles'
|
||||||
|
maybe_pluralize(1, 'Article', 'Articles') -> '1 Article'
|
||||||
|
maybe_pluralize(2, 'Article', 'Articles') -> '2 Articles'
|
||||||
|
|
||||||
|
'''
|
||||||
|
selection = plural
|
||||||
|
if count == 1:
|
||||||
|
selection = singular
|
||||||
|
return '{} {}'.format(count, selection)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue