summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 18:20:56 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 18:20:56 +0200
commitc53a50f3a219d3667af0a8636d180c1efc3cd265 (patch)
tree3435c624e0b9f52d96b83e232b2a6d0d0b739ec7
parent32774872566e0c29aefec26d8fbc41242afebbef (diff)
downloadjt-c53a50f3a219d3667af0a8636d180c1efc3cd265.tar.gz
Move command finish to a separate class
-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 = {