From 5ee4b1e3a9d2dc2622929b9fa274127d7385b5a6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 13 Sep 2011 11:50:56 +0100 Subject: Add attachment support to journal-note. --- scripts/journal-note | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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) -- cgit v1.2.1