Skip to content

Commit

Permalink
Fix #2317 -- use state file for deploy dates in github_deploy and nik…
Browse files Browse the repository at this point in the history
…ola status

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 29, 2016
1 parent 78adaf3 commit 91f245d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -9,6 +9,8 @@ Features
Bugfixes
--------

* Use state files in ``nikola github_deploy`` and ``nikola status``
(Issue #2317)
* Add ``align`` options for ``youtube``, ``vimeo``, ``soundcloud``
reST directives (Issue #2304)
* Update ``FILE_METADATA_REGEXP`` example in docs (Issue #2296)
Expand Down
1 change: 0 additions & 1 deletion nikola/plugins/command/deploy.py
Expand Up @@ -130,7 +130,6 @@ def _execute(self, command, args):
new_deploy = datetime.utcnow()
self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)

makedirs(self.site.config['CACHE_FOLDER'])
# Store timestamp of successful deployment
self.site.state.set('last_deploy', new_deploy.isoformat())

Expand Down
5 changes: 1 addition & 4 deletions nikola/plugins/command/github_deploy.py
Expand Up @@ -164,8 +164,5 @@ def _commit_and_push(self, commit_first_line):
self.logger.info("Successful deployment")

# Store timestamp of successful deployment
timestamp_path = os.path.join(self.site.config["CACHE_FOLDER"], "lastdeploy")
new_deploy = datetime.utcnow()
makedirs(self.site.config["CACHE_FOLDER"])
with io.open(timestamp_path, "w+", encoding="utf8") as outf:
outf.write(unicode_str(new_deploy.isoformat()))
self.site.state.set('last_deploy', new_deploy.isoformat())
15 changes: 5 additions & 10 deletions nikola/plugins/command/status.py
Expand Up @@ -27,7 +27,6 @@
"""Display site status."""

from __future__ import print_function
import io
import os
from datetime import datetime
from dateutil.tz import gettz, tzlocal
Expand Down Expand Up @@ -75,15 +74,11 @@ def _execute(self, options, args):
"""Display site status."""
self.site.scan_posts()

timestamp_path = os.path.join(self.site.config["CACHE_FOLDER"], "lastdeploy")

last_deploy = None

try:
with io.open(timestamp_path, "r", encoding="utf8") as inf:
last_deploy = datetime.strptime(inf.read().strip(), "%Y-%m-%dT%H:%M:%S.%f")
last_deploy_offset = datetime.utcnow() - last_deploy
except (IOError, Exception):
last_deploy = self.site.state.get('last_deploy')
if last_deploy is not None:
last_deploy = datetime.strptime(last_deploy, "%Y-%m-%dT%H:%M:%S.%f")
last_deploy_offset = datetime.utcnow() - last_deploy
else:
print("It does not seem like you've ever deployed the site (or cache missing).")

if last_deploy:
Expand Down

0 comments on commit 91f245d

Please sign in to comment.