diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-17 12:22:48 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-17 12:22:48 +0300 |
commit | 225ad8daf0ea7d05f557fc5e228fac4437d1d180 (patch) | |
tree | f58c6cd6df1b4e55b6c83359585ef8bf60d77d47 | |
parent | 4db360745d770bdec95092bae12303051b1c444e (diff) | |
download | jt-225ad8daf0ea7d05f557fc5e228fac4437d1d180.tar.gz |
Add --profile optionliw/profiles
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | jtlib/app.py | 20 |
2 files changed, 27 insertions, 0 deletions
@@ -1,6 +1,13 @@ NEWS for jt =========== +Version 0.10, released UNRELEASED +-------------------------------- + +* Added the `--profile` (`-p`) option to select a configuration file + section to use, in addition to the default `[config]`. This allows + the user to have, say, personal and work journals more easily. + Version 0.9, released 2015-10-03 -------------------------------- diff --git a/jtlib/app.py b/jtlib/app.py index 6e33646..5293e91 100644 --- a/jtlib/app.py +++ b/jtlib/app.py @@ -27,6 +27,12 @@ class JournalTool(cliapp.Application): def add_settings(self): self.settings.string( + ['profile', 'p'], + 'also use section PROFILE in configuration files, ' + 'in addition to [config]', + metavar='PROFILE') + + self.settings.string( ['source'], 'use journal source tree in DIR', metavar='DIR') @@ -67,6 +73,7 @@ class JournalTool(cliapp.Application): metavar='NOW') def process_args(self, args): + self.merge_profile() if self.settings['pretend-time']: self.now_tuple = time.strptime( self.settings['pretend-time'], '%Y-%m-%d %H:%M:%S') @@ -74,6 +81,19 @@ class JournalTool(cliapp.Application): self.now_tuple = time.localtime() cliapp.Application.process_args(self, args) + def merge_profile(self): + profile = self.settings['profile'] + if profile: + cp = self.settings.as_cp() + if profile not in cp.sections(): + raise cliapp.AppException('Unknown profile %s' % profile) + for key in cp.options(profile): + if key not in self.settings: + raise cliapp.AppException( + 'Profile %s uses unknown setting %s' % + (profile, key)) + self.settings[key] = cp.get(profile, key) + def drafts_dir(self): return os.path.join(self.settings['source'], 'drafts') |