diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-11 16:50:37 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-11 16:50:37 +0100 |
commit | 6a89c17542193fc6bc0f5bbaea5bd073c37d129e (patch) | |
tree | 6dcd9fd1568dce9cf12ba4ec1a701f1972260019 | |
parent | b7ec55734157f26d1eb979929b15683845a4ff71 (diff) | |
download | jt-6a89c17542193fc6bc0f5bbaea5bd073c37d129e.tar.gz |
Implement cmd_edit
-rwxr-xr-x | journal-note | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/journal-note b/journal-note index c9b844c..452ecd4 100755 --- a/journal-note +++ b/journal-note @@ -78,7 +78,7 @@ class JournalNote(cliapp.Application): return os.path.join(self.settings['source'], 'drafts') def draft_name(self, draft_id): - return os.path.join(self.drafts_dir, '%s.mdwn' % draft_id) + return os.path.join(self.drafts_dir(), '%s.mdwn' % draft_id) def edit_file(self, pathname): subprocess.check_call(['echo', 'sensible-editor', pathname]) @@ -105,25 +105,27 @@ class JournalNote(cliapp.Application): if name.endswith('.mdwn'): yield name[:-len('.mdwn')], os.path.join(drafts_dir, name) - # def choose_entry(self, args, opts): - # if len(args) == 0: - # drafts = list(self.find_drafts(opts)) - # if len(drafts) == 1: - # draft_id, filename = drafts[0] - # return draft_id - # else: - # raise AppException('Cannot choose entry automatically') - # elif len(args) == 1: - # return args[0] - # elif len(args) > 1: - # raise AppException('Must give only one entry') - - # def cmd_edit(self, args, opts): - # draft_id = self.choose_entry(args, opts) - # pathname = self.draftname(opts, draft_id) - # if not os.path.exists(pathname): - # raise AppException('draft %s does not exist' % args[0]) - # self.gedit_file(pathname) + def cmd_edit(self, args): + '''Edit a draft journal entry.''' + + filename = self.choose_draft(args) + self.edit_file(filename) + + def choose_draft(self, args): + if len(args) == 0: + drafts = list(self.find_drafts()) + if len(drafts) == 1: + draft_id, filename = drafts[0] + return filename + else: + raise cliapp.AppException('Cannot choose entry draft automatically') + elif len(args) == 1: + filename = self.draft_name(args[0]) + if not os.path.exists(filename): + raise cliapp.AppException('draft %s does not exist' % args[0]) + return filename + elif len(args) > 1: + raise cliapp.AppException('Must give only one draft number') # def cmd_attach(self, args, opts): # if len(args) < 2: |