summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 19:37:32 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 19:37:32 +0200
commit2cf33a276340bb60ca07eaae1b07a0689e5362a0 (patch)
treefb85223d412c8463d0618f29fad87bccd9bc0fce
parent23976f87ea3396e3e848e04830ee0febcfec1cc0 (diff)
downloadjt-2cf33a276340bb60ca07eaae1b07a0689e5362a0.tar.gz
Move publishing into helper method
-rwxr-xr-xjt15
1 files 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,