Skip to content

Commit

Permalink
Fix #2406 -- respect DEPLOY_* in github_deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 27, 2016
1 parent 90f204e commit 40b2cfe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 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
18 changes: 3 additions & 15 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 @@ -87,19 +87,7 @@ def _execute(self, command, args):
"Think about it for 5 seconds, I'll wait :-)\n\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)
undeployed_posts = clean_before_deployment(self.site)

if args:
presets = args
Expand Down
5 changes: 4 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,9 @@ def _execute(self, options, args):
for f in only_on_output:
os.unlink(f)

# Remove drafts and future posts if requested (Issue #2406)
clean_before_deployment(self.site)

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

Expand Down
20 changes: 19 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,24 @@ 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 40b2cfe

Please sign in to comment.