diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-11-22 19:37:32 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-11-22 19:37:32 +0200 |
commit | 2cf33a276340bb60ca07eaae1b07a0689e5362a0 (patch) | |
tree | fb85223d412c8463d0618f29fad87bccd9bc0fce /jt | |
parent | 23976f87ea3396e3e848e04830ee0febcfec1cc0 (diff) | |
download | jt-2cf33a276340bb60ca07eaae1b07a0689e5362a0.tar.gz |
Move publishing into helper method
Diffstat (limited to 'jt')
-rwxr-xr-x | jt | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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, |