From 275f7ebd71e6f0335772496e5904c4e1b52a4e65 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 19:46:58 +0200 Subject: Re-order cmd_ methods to be together --- jt | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/jt b/jt index d41bb55..02a9bb8 100755 --- a/jt +++ b/jt @@ -309,14 +309,6 @@ class JournalTool(cliapp.Application): '''Create a new journal entry draft.''' NewCommand(self).run(args) - def drafts_dir(self): - return os.path.join(self.settings['source'], 'drafts') - - def edit_file(self, pathname): - safe_pathname = cliapp.shell_quote(pathname) - cmdline = ['sh', '-c', self.settings['editor'] % pathname] - self.runcmd(cmdline, stdin=None, stdout=None, stderr=None) - def cmd_list(self, args): '''List journal entry drafts.''' ListCommand(self).run(args) @@ -325,24 +317,6 @@ class JournalTool(cliapp.Application): '''Edit a draft journal entry.''' EditCommand(self).run(args) - def choose_draft(self, drafts_dir, args): - if len(args) == 0: - drafts = list(drafts_dir.get_drafts()) - if len(drafts) == 1: - draft_id, filename = drafts[0] - return draft_id, filename - elif len(drafts) == 0: - raise cliapp.AppException('No drafts to choose from') - else: - raise cliapp.AppException('Cannot choose entry draft automatically') - elif len(args) == 1: - pathname = drafts_dir.get_draft_pathname(args[0]) - if not os.path.exists(pathname): - raise cliapp.AppException('draft %s does not exist' % args[0]) - return args[0], pathname - elif len(args) > 1: - raise cliapp.AppException('Must give at most one draft number') - def cmd_attach(self, args): '''Attach files to a journal entry draft.''' AttachCommand(self).run(args) @@ -364,5 +338,31 @@ class JournalTool(cliapp.Application): NewPersonCommand(self).run(args) + def drafts_dir(self): + return os.path.join(self.settings['source'], 'drafts') + + def edit_file(self, pathname): + safe_pathname = cliapp.shell_quote(pathname) + cmdline = ['sh', '-c', self.settings['editor'] % pathname] + self.runcmd(cmdline, stdin=None, stdout=None, stderr=None) + + def choose_draft(self, drafts_dir, args): + if len(args) == 0: + drafts = list(drafts_dir.get_drafts()) + if len(drafts) == 1: + draft_id, filename = drafts[0] + return draft_id, filename + elif len(drafts) == 0: + raise cliapp.AppException('No drafts to choose from') + else: + raise cliapp.AppException('Cannot choose entry draft automatically') + elif len(args) == 1: + pathname = drafts_dir.get_draft_pathname(args[0]) + if not os.path.exists(pathname): + raise cliapp.AppException('draft %s does not exist' % args[0]) + return args[0], pathname + elif len(args) > 1: + raise cliapp.AppException('Must give at most one draft number') + JournalTool(version=__version__).run() -- cgit v1.2.1