diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:20:56 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:20:56 +0200 |
commit | c53a50f3a219d3667af0a8636d180c1efc3cd265 (patch) | |
tree | 3435c624e0b9f52d96b83e232b2a6d0d0b739ec7 | |
parent | 32774872566e0c29aefec26d8fbc41242afebbef (diff) | |
download | jt-c53a50f3a219d3667af0a8636d180c1efc3cd265.tar.gz |
Move command finish to a separate class
-rwxr-xr-x | jt | 65 |
1 files changed, 35 insertions, 30 deletions
@@ -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 = { |