diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-11 16:46:02 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-11 16:46:02 +0100 |
commit | b7ec55734157f26d1eb979929b15683845a4ff71 (patch) | |
tree | b822db81faeda5d9fee4d5556d26decc22337a15 | |
parent | e64f9c789faff4d71a6a98a501e0b36e49c0fdb9 (diff) | |
download | jt-b7ec55734157f26d1eb979929b15683845a4ff71.tar.gz |
Add cmd_list
-rwxr-xr-x | journal-note | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/journal-note b/journal-note index 006bd6e..c9b844c 100755 --- a/journal-note +++ b/journal-note @@ -50,6 +50,8 @@ class JournalNote(cliapp.Application): metavar='LAYOUT') def cmd_new(self, args): + '''Create a new journal entry draft.''' + if not args: raise cliapp.AppException('Usage: journal-note new TITLE') @@ -72,34 +74,36 @@ class JournalNote(cliapp.Application): f.close() self.edit_file(name) + def drafts_dir(self): + return os.path.join(self.settings['source'], 'drafts') + def draft_name(self, draft_id): - return os.path.join( - self.settings['source'], 'drafts', '%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]) - # def cmd_list(self, args): - # drafts = self.drafts() - # for draft_id, name in self.find_drafts(): - # if name.endswith('.mdwn'): - # f = open(os.path.join(drafts, name)) - # for line in f: - # m = re.match('\[\[!meta title="(?P<title>.*)("\]\])$', - # line) - # if m: - # title = m.group('title') - # break - # else: - # title = 'unknown title' - # f.close() - # print draft_id, title - - # def find_drafts(self, opts): - # drafts = self.drafts(opts) - # for name in os.listdir(drafts): - # if name.endswith('.mdwn'): - # yield name[:-len('.mdwn')], name + def cmd_list(self, args): + '''List journal entry drafts.''' + + for draft_id, filename in self.find_drafts(): + with open(filename) as f: + for line in f: + m = re.match( + '\[\[!meta title="(?P<title>.*)("\]\])$', + line) + if m: + title = m.group('title') + break + else: + title = 'unknown title' + print draft_id, title + + def find_drafts(self): + drafts_dir = self.drafts_dir() + for name in os.listdir(drafts_dir): + if name.endswith('.mdwn'): + yield name[:-len('.mdwn')], os.path.join(drafts_dir, name) # def choose_entry(self, args, opts): # if len(args) == 0: |