Skip to content

Commit 5f5e29b

Browse files
committedMay 28, 2015
Added possibility to list scheduled posts and draft posts.
By default, printing name and path of next scheduled post if there is one.
1 parent 4911008 commit 5f5e29b

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed
 

Diff for: ‎nikola/plugins/command/status.py

+42-18
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,26 @@ class CommandDeploy(Command):
4040
doc_purpose = "display site status"
4141
doc_description = "Show information about the posts and site deployment."
4242
logger = None
43-
44-
def _execute(self, command, args):
43+
cmd_options = [
44+
{
45+
'name': 'list_drafts',
46+
'short': 'd',
47+
'long': 'list-drafts',
48+
'type': bool,
49+
'default': False,
50+
'help': 'List all drafts',
51+
},
52+
{
53+
'name': 'list_scheduled',
54+
'short': 's',
55+
'long': 'list-scheduled',
56+
'type': bool,
57+
'default': False,
58+
'help': 'List all scheduled posts',
59+
},
60+
]
61+
62+
def _execute(self, options, args):
4563

4664
self.site.scan_posts()
4765

@@ -73,23 +91,29 @@ def _execute(self, command, args):
7391
else:
7492
print("Last deployment {0} ago.".format(self.human_time(last_deploy_offset)))
7593

94+
now = datetime.utcnow().replace(tzinfo=gettz("UTC"))
95+
7696
posts_count = len(self.site.all_posts)
77-
posts_drafts = 0
78-
posts_scheduled = 0
79-
nearest_scheduled_offset = None
80-
81-
for post in self.site.all_posts:
82-
if post.is_draft:
83-
posts_drafts = posts_drafts + 1
84-
if post.publish_later:
85-
posts_scheduled = posts_scheduled + 1
86-
post_due_offset = post.date - datetime.utcnow().replace(tzinfo=gettz("UTC"))
87-
if (nearest_scheduled_offset is None) or (post_due_offset.seconds < nearest_scheduled_offset.seconds):
88-
nearest_scheduled_offset = post_due_offset
89-
90-
if posts_scheduled > 0 and nearest_scheduled_offset is not None:
91-
print("{0} to next scheduled post.".format(self.human_time(nearest_scheduled_offset)))
92-
print("{0} posts in total, {1} scheduled, and {2} drafts.".format(posts_count, posts_scheduled, posts_drafts))
97+
98+
# find all drafts
99+
posts_drafts = [post for post in self.site.all_posts if post.is_draft]
100+
posts_drafts = sorted(posts_drafts, key=lambda post: post.source_path)
101+
102+
# find all scheduled posts with offset from now until publishing time
103+
posts_scheduled = [(post.date - now, post) for post in self.site.all_posts if post.publish_later]
104+
posts_scheduled = sorted(posts_scheduled, key=lambda offset_post: (offset_post[0],offset_post[1].source_path))
105+
106+
if len(posts_scheduled) > 0:
107+
if options['list_scheduled']:
108+
for offset, post in posts_scheduled:
109+
print("Scheduled: '{1}' ({2}; source: {3}) in {0}".format(self.human_time(offset), post.meta('title'), post.permalink(), post.source_path))
110+
else:
111+
offset, post = posts_scheduled[0]
112+
print("{0} to next scheduled post ('{1}'; {2}; source: {3}).".format(self.human_time(offset), post.meta('title'), post.permalink(), post.source_path))
113+
if options['list_drafts']:
114+
for post in posts_drafts:
115+
print("Draft: '{0}' ({1}; source: {2})".format(post.meta('title'), post.permalink(), post.source_path))
116+
print("{0} posts in total, {1} scheduled, and {2} drafts.".format(posts_count, len(posts_scheduled), len(posts_drafts)))
93117

94118
def human_time(self, dt):
95119
days = dt.days

0 commit comments

Comments
 (0)
Please sign in to comment.