summaryrefslogtreecommitdiff
path: root/jt
diff options
context:
space:
mode:
Diffstat (limited to 'jt')
-rwxr-xr-xjt65
1 files changed, 35 insertions, 30 deletions
diff --git a/jt b/jt
index ad02c62..3e78621 100755
--- a/jt
+++ b/jt
@@ -123,6 +123,40 @@ class RemoveCommand(Command):
shutil.rmtree(dirname)
+class FinishCommand(Command):
+
+ def run(self, args):
+ draft_mdwn = self._app.choose_draft(args)
+ draft_attch, ext = os.path.splitext(draft_mdwn)
+ assert ext == '.mdwn'
+
+ pub_attch = os.path.join(
+ self._app.published_dir(), self._app.published_basename(draft_mdwn))
+ pub_mdwn = pub_attch + '.mdwn'
+
+ if os.path.exists(pub_mdwn):
+ raise cliapp.AppException('%s already exists' % pub_mdwn)
+
+ if not os.path.exists(self._app.published_dir()):
+ os.makedirs(self._app.published_dir())
+ os.rename(draft_mdwn, pub_mdwn)
+ if os.path.exists(draft_attch):
+ os.rename(draft_attch, pub_attch)
+
+ if self._app.settings['git']:
+ argv = ['git', 'add', pub_mdwn]
+ if os.path.exists(pub_attch):
+ argv.append(pub_attch)
+ cliapp.runcmd(argv, cwd=self._app.settings['source'])
+ cliapp.runcmd(
+ ['git', 'commit', '-m', 'Publish log entry'],
+ cwd=self._app.settings['source'])
+ if self.settings['push']:
+ cliapp.runcmd(
+ ['git', 'push', 'origin', 'HEAD'],
+ cwd=self._app.settings['source'])
+
+
class JournalTool(cliapp.Application):
cmd_synopsis = {
@@ -235,36 +269,7 @@ class JournalTool(cliapp.Application):
def cmd_finish(self, args):
'''Publish a draft journal entry.'''
-
- draft_mdwn = self.choose_draft(args)
- draft_attch, ext = os.path.splitext(draft_mdwn)
- assert ext == '.mdwn'
-
- pub_attch = os.path.join(
- self.published_dir(), self.published_basename(draft_mdwn))
- pub_mdwn = pub_attch + '.mdwn'
-
- 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)
-
- if self.settings['git']:
- argv = ['git', 'add', pub_mdwn]
- if os.path.exists(pub_attch):
- argv.append(pub_attch)
- cliapp.runcmd(argv, cwd=self.settings['source'])
- cliapp.runcmd(
- ['git', 'commit', '-m', 'Publish log entry'],
- cwd=self.settings['source'])
- if self.settings['push']:
- cliapp.runcmd(
- ['git', 'push', 'origin', 'HEAD'],
- cwd=self.settings['source'])
+ FinishCommand(self).run(args)
def published_dir(self):
subdirs = {