From 00200c2eae827f0e1b867c6946387fe351608382 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 18:29:27 +0200 Subject: Split NewCommand.run into smaller methods --- jt | 13 ++++++++++--- 1 file 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): -- cgit v1.2.1