Skip to content
Permalink
Browse files

Merge pull request #2337 from getnikola/add-status-options

Add options to list private and published posts.
  • Loading branch information
Kwpolska committed May 6, 2016
2 parents cfc8554 + 18820ce commit 0069bc789983b960436e1c0350ab8c5ee19fa757
Showing with 32 additions and 2 deletions.
  1. +32 −2 nikola/plugins/command/status.py
@@ -41,7 +41,7 @@ class CommandStatus(Command):

doc_purpose = "display site status"
doc_description = "Show information about the posts and site deployment."
doc_usage = '[-l|--list-drafts] [-m|--list-modified] [-s|--list-scheduled]'
doc_usage = '[-d|--list-drafts] [-m|--list-modified] [-p|--list-private] [-P|--list-published] [-s|--list-scheduled]'
logger = None
cmd_options = [
{
@@ -60,6 +60,22 @@ class CommandStatus(Command):
'default': False,
'help': 'List all modified files since last deployment',
},
{
'name': 'list_private',
'short': 'p',
'long': 'list-private',
'type': bool,
'default': False,
'help': 'List all private posts',
},
{
'name': 'list_published',
'short': 'P',
'long': 'list-published',
'type': bool,
'default': False,
'help': 'List all published posts',
},
{
'name': 'list_scheduled',
'short': 's',
@@ -105,6 +121,14 @@ def _execute(self, options, args):

posts_count = len(self.site.all_posts)

# find all published posts
posts_published = [post for post in self.site.all_posts if post.use_in_feeds]
posts_published = sorted(posts_published, key=lambda post: post.source_path)

# find all private posts
posts_private = [post for post in self.site.all_posts if post.is_private]
posts_private = sorted(posts_private, key=lambda post: post.source_path)

# find all drafts
posts_drafts = [post for post in self.site.all_posts if post.is_draft]
posts_drafts = sorted(posts_drafts, key=lambda post: post.source_path)
@@ -123,7 +147,13 @@ def _execute(self, options, args):
if options['list_drafts']:
for post in posts_drafts:
print("Draft: '{0}' ({1}; source: {2})".format(post.meta('title'), post.permalink(), post.source_path))
print("{0} posts in total, {1} scheduled, and {2} drafts.".format(posts_count, len(posts_scheduled), len(posts_drafts)))
if options['list_private']:
for post in posts_private:
print("Private: '{0}' ({1}; source: {2})".format(post.meta('title'), post.permalink(), post.source_path))
if options['list_published']:
for post in posts_published:
print("Published: '{0}' ({1}; source: {2})".format(post.meta('title'), post.permalink(), post.source_path))
print("{0} posts in total, {1} scheduled, {2} drafts, {3} private and {4} published.".format(posts_count, len(posts_scheduled), len(posts_drafts), len(posts_private), len(posts_published)))

def human_time(self, dt):
"""Translate time into a human-friendly representation."""

0 comments on commit 0069bc7

Please sign in to comment.
You can’t perform that action at this time.