diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-12-07 10:27:29 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-12-07 10:27:29 +0000 |
commit | 338b1caaee28d4b01a1b2c3a168b201033ebfc9f (patch) | |
tree | 69424c4f755671c7515c93e637490ad0400b8c1e | |
parent | 6b9738fb93cedcf44056466792876f3fd5746d05 (diff) | |
download | liw-automation-338b1caaee28d4b01a1b2c3a168b201033ebfc9f.tar.gz |
Put drafts in drafts folder with simple names.
Show titles when listing drafts.
-rwxr-xr-x | scripts/journal-note | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/scripts/journal-note b/scripts/journal-note index 211aa72..60ab9c0 100755 --- a/scripts/journal-note +++ b/scripts/journal-note @@ -17,6 +17,7 @@ import optparse import os +import re import subprocess import sys import tempfile @@ -49,12 +50,6 @@ class App(object): return p.parse_args() - def tempfile(self, dirname, content): - fd, name = tempfile.mkstemp(dir=dirname) - os.write(fd, content) - os.close(fd) - return name - def main(self): commands = { 'new': self.new_entry, @@ -75,17 +70,37 @@ class App(object): def new_entry(self, args, opts): if not args: raise AppException('Usage: journal-note new TITLE') + + for i in range(1000): + name = os.path.join(opts.base, 'drafts', '%d.mdwn' % i) + if not os.path.exists(name): + break + else: + raise AppException('ERROR: too many existing drafts') + values = { 'title': args[0], 'date': time.strftime('%Y-%m-%d %H:%M') } - - name = self.tempfile(self.drafts(opts), template % values) - print name + f = open(name, 'w') + f.write(template % values) + f.close() def list_entries(self, args, opts): - for name in os.listdir(self.drafts(opts)): - print name + drafts = self.drafts(opts) + for name in os.listdir(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 name[:-len('.mdwn')], title def edit_entry(self, args, opts): if not args: |