Skip to content

Commit

Permalink
Merge pull request #2410 from getnikola/github_deploy-filtering
Browse files Browse the repository at this point in the history
Fix #2406 -- respect DEPLOY_* in github_deploy
  • Loading branch information
punchagan committed Jul 27, 2016
2 parents 90f204e + f6024db commit d1f6647
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -9,6 +9,8 @@ Features
Bugfixes
--------

* Respect ``DEPLOY_DRAFTS`` and ``DEPLOY_FUTURE`` in ``github_deploy``
(Issue #2406)
* Don’t remove ``<!DOCTYPE html>`` if typogrify filters are in use
* Avoid infinite loop if bootstrap3 can't be loaded (Issue #2402)

Expand Down Expand Up @@ -1865,4 +1867,4 @@ Bugfixes
* Fix for content displaying too wide
* Changelog

vim: tw=70 syntax=rst
vim: cc=70 tw=70 syntax=rst
4 changes: 2 additions & 2 deletions nikola/conf.py.in
Expand Up @@ -277,12 +277,12 @@ POSTS_SECTIONS = True
# output / TRANSLATION[lang] / TAG_PATH / index.html (list of tags)
# output / TRANSLATION[lang] / TAG_PATH / tag.html (list of posts for a tag)
# output / TRANSLATION[lang] / TAG_PATH / tag.xml (RSS feed for a tag)
# (translatable)
# (translatable)
# TAG_PATH = "categories"

# See TAG_PATH's "list of tags" for the default setting value. Can be overwritten
# here any path relative to the output directory.
# (translatable)
# (translatable)
# TAGS_INDEX_PATH = "tags.html"

# If TAG_PAGES_ARE_INDEXES is set to True, each tag's page will contain
Expand Down
24 changes: 8 additions & 16 deletions nikola/plugins/command/deploy.py
Expand Up @@ -38,15 +38,15 @@
from blinker import signal

from nikola.plugin_categories import Command
from nikola.utils import get_logger, remove_file, STDERR_HANDLER
from nikola.utils import get_logger, clean_before_deployment, STDERR_HANDLER


class CommandDeploy(Command):
"""Deploy site."""

name = "deploy"

doc_usage = "[[preset [preset...]]"
doc_usage = "[preset [preset...]]"
doc_purpose = "deploy the site"
doc_description = "Deploy the site by executing deploy commands from the presets listed on the command line. If no presets are specified, `default` is executed."
logger = None
Expand Down Expand Up @@ -84,22 +84,14 @@ def _execute(self, command, args):
"You are deploying using the nikolademo Disqus account.\n"
"That means you will not be able to moderate the comments in your own site.\n"
"And is probably not what you want to do.\n"
"Think about it for 5 seconds, I'll wait :-)\n\n")
"Think about it for 5 seconds, I'll wait :-)\n"
"(press Ctrl+C to abort)\n")
time.sleep(5)

deploy_drafts = self.site.config.get('DEPLOY_DRAFTS', True)
deploy_future = self.site.config.get('DEPLOY_FUTURE', False)
undeployed_posts = []
if not (deploy_drafts and deploy_future):
# Remove drafts and future posts
out_dir = self.site.config['OUTPUT_FOLDER']
self.site.scan_posts()
for post in self.site.timeline:
if (not deploy_drafts and post.is_draft) or \
(not deploy_future and post.publish_later):
remove_file(os.path.join(out_dir, post.destination_path()))
remove_file(os.path.join(out_dir, post.source_path))
undeployed_posts.append(post)
# Remove drafts and future posts if requested
undeployed_posts = clean_before_deployment(self.site)
if undeployed_posts:
self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts)))

if args:
presets = args
Expand Down
7 changes: 6 additions & 1 deletion nikola/plugins/command/github_deploy.py
Expand Up @@ -34,7 +34,7 @@

from nikola.plugin_categories import Command
from nikola.plugins.command.check import real_scan_files
from nikola.utils import get_logger, req_missing, STDERR_HANDLER
from nikola.utils import get_logger, req_missing, clean_before_deployment, STDERR_HANDLER
from nikola.__main__ import main
from nikola import __version__

Expand Down Expand Up @@ -100,6 +100,11 @@ def _execute(self, options, args):
for f in only_on_output:
os.unlink(f)

# Remove drafts and future posts if requested (Issue #2406)
undeployed_posts = clean_before_deployment(self.site)
if undeployed_posts:
self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts)))

# Commit and push
self._commit_and_push(options['commit_message'])

Expand Down
21 changes: 20 additions & 1 deletion nikola/utils.py
Expand Up @@ -81,7 +81,7 @@
'adjust_name_for_index_path', 'adjust_name_for_index_link',
'NikolaPygmentsHTML', 'create_redirect', 'TreeNode',
'flatten_tree_structure', 'parse_escaped_hierarchical_category_name',
'join_hierarchical_category_path', 'indent')
'join_hierarchical_category_path', 'clean_before_deployment', 'indent')

# Are you looking for 'generic_rss_renderer'?
# It's defined in nikola.nikola.Nikola (the site object).
Expand Down Expand Up @@ -1867,6 +1867,25 @@ def dns_sd(port, inet6):
return None


def clean_before_deployment(site):
"""Clean drafts and future posts before deployment."""
undeployed_posts = []
deploy_drafts = site.config.get('DEPLOY_DRAFTS', True)
deploy_future = site.config.get('DEPLOY_FUTURE', False)
if not (deploy_drafts and deploy_future): # == !drafts || !future
# Remove drafts and future posts
out_dir = site.config['OUTPUT_FOLDER']
site.scan_posts()
for post in site.timeline:
if (not deploy_drafts and post.is_draft) or (not deploy_future and post.publish_later):
for lang in post.translated_to:
remove_file(os.path.join(out_dir, post.destination_path(lang)))
source_path = post.destination_path(lang, post.source_ext(True))
remove_file(os.path.join(out_dir, source_path))
undeployed_posts.append(post)
return undeployed_posts


# Stolen from textwrap in Python 3.4.3.
def indent(text, prefix, predicate=None):
"""Add 'prefix' to the beginning of selected lines in 'text'.
Expand Down

0 comments on commit d1f6647

Please sign in to comment.