diff options
Diffstat (limited to 'jtlib/app.py')
-rw-r--r-- | jtlib/app.py | 20 |
1 files changed, 20 insertions, 0 deletions
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') |