summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 19:32:12 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 19:32:12 +0200
commit23976f87ea3396e3e848e04830ee0febcfec1cc0 (patch)
tree87d2e9e3348684a71ca216dfbd4dddcf92938991
parent5523218f134c29adaf83314f2d1b48d25c22c5dc (diff)
downloadjt-23976f87ea3396e3e848e04830ee0febcfec1cc0.tar.gz
Move get_draft_title to DraftsDirectory
-rwxr-xr-xjt37
1 files changed, 20 insertions, 17 deletions
diff --git a/jt b/jt
index c042ff6..2167499 100755
--- a/jt
+++ b/jt
@@ -83,6 +83,21 @@ class DraftsDirectory(object):
if os.path.exists(dirname):
shutil.rmtree(dirname)
+ def get_draft_title(self, draft_id):
+ pathname = self.get_draft_pathname(draft_id)
+ with open(pathname) as f:
+ for line in f:
+ m = re.match(
+ '\[\[!meta title="(?P<title>.*)("\]\])$',
+ line)
+ if m:
+ title = m.group('title')
+ break
+ else:
+ title = None
+ return title
+ return ''
+
class Command(object):
@@ -118,7 +133,7 @@ class ListCommand(Command):
def run(self, args):
drafts_dir = DraftsDirectory(self._app.drafts_dir())
for draft_id, filename in drafts_dir.get_drafts():
- print draft_id, self._app.get_draft_title(filename) or ""
+ print draft_id, drafts_dir.get_draft_title(draft_id)
class EditCommand(Command):
@@ -162,7 +177,8 @@ class FinishCommand(Command):
draft_attch = drafts_dir.get_draft_attachments_dirname(draft_id)
pub_attch = os.path.join(
- self._published_dir(), self._published_basename(draft_mdwn))
+ self._published_dir(),
+ self._published_basename(drafts_dir, draft_id, draft_mdwn))
pub_mdwn = pub_attch + '.mdwn'
if os.path.exists(pub_mdwn):
@@ -192,11 +208,11 @@ class FinishCommand(Command):
subdir = subdirs[self._app.settings['layout']]
return os.path.join(self._app.settings['source'], subdir)
- def _published_basename(self, draft_mdwn):
+ def _published_basename(self, drafts_dir, draft_id, draft_mdwn):
if self._app.settings['layout'] in ('liw', 'ct'):
basename = time.strftime('%Y-%m-%d-%H:%M:%S')
elif self._app.settings['layout'] == 'pkb':
- title = self._app.get_draft_title(draft_mdwn)
+ title = drafts_dir.get_draft_title(draft_id)
if not title:
raise Exception("%s has no title" % draft_mdwn)
basename = self._summarise_title(title)
@@ -323,19 +339,6 @@ class JournalTool(cliapp.Application):
'''List journal entry drafts.'''
ListCommand(self).run(args)
- def get_draft_title(self, filename):
- with open(filename) as f:
- for line in f:
- m = re.match(
- '\[\[!meta title="(?P<title>.*)("\]\])$',
- line)
- if m:
- title = m.group('title')
- break
- else:
- title = None
- return title
-
def cmd_edit(self, args):
'''Edit a draft journal entry.'''
EditCommand(self).run(args)