diff options
Diffstat (limited to 'nikola/plugins/command/deploy.py')
| -rw-r--r-- | nikola/plugins/command/deploy.py | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/nikola/plugins/command/deploy.py b/nikola/plugins/command/deploy.py index eb5787e..bd1c15f 100644 --- a/nikola/plugins/command/deploy.py +++ b/nikola/plugins/command/deploy.py @@ -25,7 +25,6 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import print_function -from ast import literal_eval import codecs from datetime import datetime import os @@ -40,8 +39,8 @@ from nikola.plugin_categories import Command from nikola.utils import remove_file, get_logger -class Deploy(Command): - """Deploy site. """ +class CommandDeploy(Command): + """Deploy site.""" name = "deploy" doc_usage = "" @@ -76,7 +75,7 @@ class Deploy(Command): undeployed_posts.append(post) for command in self.site.config['DEPLOY_COMMANDS']: - self.logger.notice("==> {0}".format(command)) + self.logger.info("==> {0}".format(command)) try: subprocess.check_call(command, shell=True) except subprocess.CalledProcessError as e: @@ -84,26 +83,22 @@ class Deploy(Command): 'returned {1}'.format(e.cmd, e.returncode)) sys.exit(e.returncode) - self.logger.notice("Successful deployment") - tzinfo = pytz.timezone(self.site.config['TIMEZONE']) + self.logger.info("Successful deployment") try: - with open(timestamp_path, 'rb') as inf: - last_deploy = literal_eval(inf.read().strip()) - if tzinfo: - last_deploy = last_deploy.replace(tzinfo=tzinfo) + with codecs.open(timestamp_path, 'rb', 'utf8') as inf: + last_deploy = datetime.strptime(inf.read().strip(), "%Y-%m-%dT%H:%M:%S.%f") clean = False - except Exception: + except (IOError, Exception) as e: + self.logger.debug("Problem when reading `{0}`: {1}".format(timestamp_path, e)) last_deploy = datetime(1970, 1, 1) - if tzinfo: - last_deploy = last_deploy.replace(tzinfo=tzinfo) clean = True - new_deploy = datetime.now() + new_deploy = datetime.utcnow() self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts) # Store timestamp of successful deployment with codecs.open(timestamp_path, 'wb+', 'utf8') as outf: - outf.write(repr(new_deploy)) + outf.write(new_deploy.isoformat()) def _emit_deploy_event(self, last_deploy, new_deploy, clean=False, undeployed=None): """ Emit events for all timeline entries newer than last deploy. @@ -129,9 +124,11 @@ class Deploy(Command): 'undeployed': undeployed } + tzinfo = pytz.timezone(self.site.config['TIMEZONE']) + deployed = [ entry for entry in self.site.timeline - if entry.date > last_deploy and entry not in undeployed + if entry.date > (last_deploy.replace(tzinfo=tzinfo) if tzinfo else last_deploy) and entry not in undeployed ] event['deployed'] = deployed |
