diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:29:27 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:29:27 +0200 |
commit | 00200c2eae827f0e1b867c6946387fe351608382 (patch) | |
tree | e3379dbf7d9d35e331f34ba28859609ce22f7a57 | |
parent | 3270896ac47d7096468d921d82a7eca176add476 (diff) | |
download | jt-00200c2eae827f0e1b867c6946387fe351608382.tar.gz |
Split NewCommand.run into smaller methods
-rwxr-xr-x | jt | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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): |