From 726cb96b71b38d052eedf99b40f0aa1d48b5ba65 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 7 Dec 2010 10:38:29 +0000 Subject: Centralize generation of pathname for draft. --- scripts/journal-note | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/journal-note b/scripts/journal-note index 3cd7b78..ed87a79 100755 --- a/scripts/journal-note +++ b/scripts/journal-note @@ -68,6 +68,9 @@ class App(object): def drafts(self, opts): return os.path.join(opts.base, 'drafts') + def draftname(self, opts, draft_id): + return os.path.join(opts.base, 'drafts', '%s.mdwn' % draft_id) + def gedit_file(self, pathname): subprocess.check_call(['gedit', '--new-window', pathname]) @@ -76,7 +79,7 @@ class App(object): raise AppException('Usage: journal-note new TITLE') for i in range(1000): - name = os.path.join(opts.base, 'drafts', '%d.mdwn' % i) + name = self.draftname(opts, i) if not os.path.exists(name): break else: @@ -110,7 +113,7 @@ class App(object): def edit_entry(self, args, opts): if not args: raise AppException('Usage: journal-note edit ID') - pathname = os.path.join(self.drafts(opts), args[0] + '.mdwn') + pathname = self.draftname(opts, args[0]) if not os.path.exists(pathname): raise AppException('draft %s does not exist' % args[0]) self.gedit_file(pathname) @@ -118,13 +121,13 @@ class App(object): def remove_entry(self, args, opts): if not args: raise AppException('Usage: journal-note remove ID') - pathname = os.path.join(self.drafts(opts), args[0] + '.mdwn') + pathname = self.draftname(opts, args[0]) os.remove(pathname) def finish_entry(self, args, opts): if not args: raise AppException('Usage: journal-note finish ID') - draft = os.path.join(self.drafts(opts), args[0] + '.mdwn') + draft = self.draftname(opts, args[0]) if not os.path.exists(draft): raise AppException('draft %s does not exist' % args[0]) basename = time.strftime('%Y-%m-%d-%H:%M.mdwn') -- cgit v1.2.1