diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-12-07 10:38:29 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-12-07 10:38:29 +0000 |
commit | 726cb96b71b38d052eedf99b40f0aa1d48b5ba65 (patch) | |
tree | 772f940ffed5241b39492cb79d1f6f1daa72df76 /scripts | |
parent | ea559066a15c5fc67268db2b117e25e1b066b0c2 (diff) | |
download | liw-automation-726cb96b71b38d052eedf99b40f0aa1d48b5ba65.tar.gz |
Centralize generation of pathname for draft.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/journal-note | 11 |
1 files 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') |