From 4bb35b67ca3e2b27338bc6b33ab2ced0d017841f Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 21 Mar 2020 09:11:31 -0700 Subject: [PATCH] Refactor cdc config file method into mixin --- amanuensis/config/context.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/amanuensis/config/context.py b/amanuensis/config/context.py index 838b523..16ed2c3 100644 --- a/amanuensis/config/context.py +++ b/amanuensis/config/context.py @@ -62,6 +62,14 @@ class ConfigDirectoryContext(): os.delete(fpath) +class ConfigFileMixin(): + def config(self, edit=False): + if edit: + return self.edit('config') + else: + return self.read('config') + + class IndexDirectoryContext(ConfigDirectoryContext): """ A lookup layer for getting config directory contexts for lexicon @@ -107,7 +115,7 @@ class RootConfigDirectoryContext(ConfigDirectoryContext): UserConfigDirectoryContext) -class LexiconConfigDirectoryContext(ConfigDirectoryContext): +class LexiconConfigDirectoryContext(ConfigFileMixin, ConfigDirectoryContext): """ A config context for a lexicon's config directory. """ @@ -116,19 +124,9 @@ class LexiconConfigDirectoryContext(ConfigDirectoryContext): self.draft = ConfigDirectoryContext(os.path.join(self.path, 'draft')) self.src = ConfigDirectoryContext(os.path.join(self.path, 'src')) - def config(self, edit=False): - if edit: - return self.edit('config') - else: - return self.read('config') - -class UserConfigDirectoryContext(ConfigDirectoryContext): +class UserConfigDirectoryContext(ConfigFileMixin, ConfigDirectoryContext): """ A config context for a user's config directory. """ - def config(self, edit=False): - if edit: - return self.edit('config') - else: - return self.read('config') + pass