diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-22 14:59:33 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-22 14:59:33 +0200 |
commit | 339049495dd8a82cc2d5058e805144e244bc7d72 (patch) | |
tree | 7541d27ead7689d63ac95eab466d0164373bae86 /jtlib | |
parent | af8c346af93e153e1a553d1edc10ac3dc444be09 (diff) | |
download | jt-339049495dd8a82cc2d5058e805144e244bc7d72.tar.gz |
Add: put back --layout setting
Support ct and pkb layouts now.
Diffstat (limited to 'jtlib')
-rw-r--r-- | jtlib/app.py | 6 | ||||
-rw-r--r-- | jtlib/plugins/finish_plugin.py | 17 | ||||
-rw-r--r-- | jtlib/plugins/new_plugin.py | 1 |
3 files changed, 22 insertions, 2 deletions
diff --git a/jtlib/app.py b/jtlib/app.py index 6ea2e74..81fda8b 100644 --- a/jtlib/app.py +++ b/jtlib/app.py @@ -32,6 +32,12 @@ class JournalTool(cliapp.Application): 'in addition to [config]', metavar='PROFILE') + self.settings.choice( + ['layout'], + ['pkb', 'ct'], + 'use journal layout (one of pkb, ct)', + metavar='LAYOUT') + self.settings.string( ['source'], 'use journal source tree in DIR', diff --git a/jtlib/plugins/finish_plugin.py b/jtlib/plugins/finish_plugin.py index e98f59a..c05f88e 100644 --- a/jtlib/plugins/finish_plugin.py +++ b/jtlib/plugins/finish_plugin.py @@ -42,7 +42,7 @@ class FinishCommand(cliapp.Plugin): pub_attch = os.path.join( self._published_dir(), - self._summarise_title(title)) + self._published_basename(title, draft_mdwn),) pub_mdwn = pub_attch + '.mdwn' if os.path.exists(pub_mdwn): @@ -59,12 +59,25 @@ class FinishCommand(cliapp.Plugin): self._push_git() def _published_dir(self): - subdir = time.strftime('%Y/%m/%d', self.app.now_tuple) + subdirs = { + 'ct': '%d' % self.app.now_tuple.tm_year, + 'pkb': time.strftime('%Y/%m/%d', self.app.now_tuple), + } + + subdir = subdirs[self.app.settings['layout']] return os.path.join( self.app.settings['source'], self.app.settings['notes-dir'], subdir) + def _published_basename(self, title, draft_mdwn): + layout = self.app.settings['layout'] + basenames = { + 'ct': time.strftime('%Y-%m-%d-%H:%M:%S', self.app.now_tuple), + 'pkb': self._summarise_title(title), + } + return basenames[layout] + def _summarise_title(self, title): basename = '' acceptable = set(string.ascii_letters + string.digits + '-_') diff --git a/jtlib/plugins/new_plugin.py b/jtlib/plugins/new_plugin.py index 25facf8..d704242 100644 --- a/jtlib/plugins/new_plugin.py +++ b/jtlib/plugins/new_plugin.py @@ -52,6 +52,7 @@ class NewCommand(cliapp.Plugin): raise cliapp.AppException('Usage: journal-note new TITLE') self.app.settings.require('source') + self.app.settings.require('layout') topic = self.app.settings['topic'] if topic and not self._topic_page_exists(topic): raise cliapp.AppException('Topic %s does not exist yet' % topic) |