summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 18:54:40 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 18:54:40 +0200
commite54ace14101b2751c70ea0815193ac15cfe95ea7 (patch)
tree31c6c2a697ecda9fe58fb7e40864e6ea3c139b25
parent4a85d5b145768887cfa73619f1ddf41a31f9a03b (diff)
downloadjt-e54ace14101b2751c70ea0815193ac15cfe95ea7.tar.gz
Add DraftsDirectory.create_draft
-rwxr-xr-xjt21
1 files changed, 13 insertions, 8 deletions
diff --git a/jt b/jt
index 4073e85..c9a5954 100755
--- a/jt
+++ b/jt
@@ -54,6 +54,11 @@ class DraftsDirectory(object):
def get_draft_attachments_dirname(self, draft_number):
return os.path.join(self.dirname, '%s' % draft_number)
+ def create_draft(self, draft_number, content):
+ pathname = self.get_draft_pathname(draft_number)
+ with open(pathname, 'w') as f:
+ f.write(content)
+
def get_drafts(self):
for basename in os.listdir(self.dirname):
# .# is what Emacs autosave files start with.
@@ -89,25 +94,25 @@ class NewCommand(Command):
drafts_dir = DraftsDirectory(self._app.drafts_dir())
drafts_dir.create_if_missing()
- pathname = self._pick_draft_pathname(drafts_dir)
- self._create_draft(pathname, args[0])
- self._app.edit_file(pathname)
+ draft_number = self._pick_draft_number(drafts_dir)
+ self._create_draft(drafts_dir, draft_number, args[0])
+ self._app.edit_file(drafts_dir.get_draft_pathname(draft_number))
- def _pick_draft_pathname(self, drafts_dir):
+ def _pick_draft_number(self, drafts_dir):
for i in range(1000):
pathname = drafts_dir.get_draft_pathname(i)
if not os.path.exists(pathname):
- return pathname
+ return i
else:
raise cliapp.AppException('ERROR: too many existing drafts')
- def _create_draft(self, pathname, title):
+ def _create_draft(self, drafts_dir, draft_number, title):
values = {
'title': title,
'date': time.strftime('%Y-%m-%d %H:%M')
}
- with open(pathname, 'w') as f:
- f.write(template % values)
+ content = template % values
+ drafts_dir.create_draft(draft_number, content)
class ListCommand(Command):