summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 18:29:27 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 18:29:27 +0200
commit00200c2eae827f0e1b867c6946387fe351608382 (patch)
treee3379dbf7d9d35e331f34ba28859609ce22f7a57
parent3270896ac47d7096468d921d82a7eca176add476 (diff)
downloadjt-00200c2eae827f0e1b867c6946387fe351608382.tar.gz
Split NewCommand.run into smaller methods
-rwxr-xr-xjt13
1 files changed, 10 insertions, 3 deletions
diff --git a/jt b/jt
index 951a3f6..7b89c0a 100755
--- a/jt
+++ b/jt
@@ -57,24 +57,31 @@ class NewCommand(Command):
self._app.settings.require('source')
self._app.settings.require('layout')
+ self._create_drafts_dir()
+ name = self._pick_draft_name()
+ self._create_draft(name, args[0])
+ self._app.edit_file(name)
+
+ def _create_drafts_dir(self):
if not os.path.exists(self._app.drafts_dir()):
os.mkdir(self._app.drafts_dir())
+ def _pick_draft_name(self):
for i in range(1000):
name = self._app.draft_name(i)
if not os.path.exists(name):
- break
+ return name
else:
raise cliapp.AppException('ERROR: too many existing drafts')
+ def _create_draft(self, name, title):
values = {
- 'title': args[0],
+ 'title': title,
'date': time.strftime('%Y-%m-%d %H:%M')
}
f = open(name, 'w')
f.write(template % values)
f.close()
- self._app.edit_file(name)
class ListCommand(Command):