From 2cf33a276340bb60ca07eaae1b07a0689e5362a0 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 19:37:32 +0200 Subject: Move publishing into helper method --- jt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jt b/jt index 2167499..57d7f6a 100755 --- a/jt +++ b/jt @@ -173,6 +173,7 @@ class FinishCommand(Command): def run(self, args): drafts_dir = DraftsDirectory(self._app.drafts_dir()) + draft_id, draft_mdwn = self._app.choose_draft(drafts_dir, args) draft_attch = drafts_dir.get_draft_attachments_dirname(draft_id) @@ -184,11 +185,7 @@ class FinishCommand(Command): if os.path.exists(pub_mdwn): raise cliapp.AppException('%s already exists' % pub_mdwn) - if not os.path.exists(self._published_dir()): - os.makedirs(self._published_dir()) - os.rename(draft_mdwn, pub_mdwn) - if os.path.exists(draft_attch): - os.rename(draft_attch, pub_attch) + self._publish_draft(draft_mdwn, draft_attch, pub_mdwn, pub_attch) if self._app.settings['git']: if os.path.exists(pub_attch): @@ -232,6 +229,14 @@ class FinishCommand(Command): basename += '_' return basename + def _publish_draft(self, draft_mdwn, draft_attch, pub_mdwn, pub_attch): + parent_dir = os.path.dirname(pub_mdwn) + if not os.path.exists(parent_dir): + os.makedirs(parent_dir) + os.rename(draft_mdwn, pub_mdwn) + if os.path.exists(draft_attch): + os.rename(draft_attch, pub_attch) + def _commit_to_git(self, pathnames): cliapp.runcmd( ['git', 'add'] + pathname, -- cgit v1.2.1