summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-09-13 11:50:56 +0100
committerLars Wirzenius <liw@liw.fi>2011-09-13 11:50:56 +0100
commit5ee4b1e3a9d2dc2622929b9fa274127d7385b5a6 (patch)
tree81464311c8e513ac0a6600c5c12fed7f2d86e41b
parent501077e74155c253911d6c4db1f2130e3ea53663 (diff)
downloadliw-automation-5ee4b1e3a9d2dc2622929b9fa274127d7385b5a6.tar.gz
Add attachment support to journal-note.
-rwxr-xr-xscripts/journal-note19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/journal-note b/scripts/journal-note
index ed87a79..b3fa466 100755
--- a/scripts/journal-note
+++ b/scripts/journal-note
@@ -18,6 +18,7 @@
import optparse
import os
import re
+import shutil
import subprocess
import sys
import tempfile
@@ -55,6 +56,7 @@ class App(object):
'new': self.new_entry,
'list': self.list_entries,
'edit': self.edit_entry,
+ 'attach': self.attach_entry,
'remove': self.remove_entry,
'finish': self.finish_entry,
}
@@ -118,6 +120,18 @@ class App(object):
raise AppException('draft %s does not exist' % args[0])
self.gedit_file(pathname)
+ def attach_entry(self, args, opts):
+ if len(args) < 2:
+ raise AppException('Usage: journal-note attach ID file...')
+ pathname = self.draftname(opts, args[0])
+ if not os.path.exists(pathname):
+ raise AppException('draft %s does not exist' % args[0])
+ dirname, ext = os.path.splitext(pathname)
+ if not os.path.exists(dirname):
+ os.mkdir(dirname)
+ for filename in args[1:]:
+ shutil.copy(filename, dirname)
+
def remove_entry(self, args, opts):
if not args:
raise AppException('Usage: journal-note remove ID')
@@ -140,6 +154,11 @@ class App(object):
basename = '%s-%d.mdwn' % (time.strftime('%Y-%m-%d-%H:%M:%S-'), i)
os.rename(draft, finished)
+ draft_dir, ext = os.path.splitext(draft)
+ if os.path.exists(draft_dir):
+ finished_dir, ext = os.path.splitext(finished)
+ shutil.copytree(draft_dir, finished_dir)
+
src = os.path.join(opts.base, 'src')
subprocess.check_call(['bzr', 'add', finished], cwd=src)
subprocess.check_call(['bzr', 'commit', '-m', 'new note'], cwd=src)