Refactor cdc config file method into mixin

This commit is contained in:
Tim Van Baak 2020-03-21 09:11:31 -07:00
parent 5444a45d90
commit 4bb35b67ca
1 changed files with 11 additions and 13 deletions

View File

@ -62,6 +62,14 @@ class ConfigDirectoryContext():
os.delete(fpath) os.delete(fpath)
class ConfigFileMixin():
def config(self, edit=False):
if edit:
return self.edit('config')
else:
return self.read('config')
class IndexDirectoryContext(ConfigDirectoryContext): class IndexDirectoryContext(ConfigDirectoryContext):
""" """
A lookup layer for getting config directory contexts for lexicon A lookup layer for getting config directory contexts for lexicon
@ -107,7 +115,7 @@ class RootConfigDirectoryContext(ConfigDirectoryContext):
UserConfigDirectoryContext) UserConfigDirectoryContext)
class LexiconConfigDirectoryContext(ConfigDirectoryContext): class LexiconConfigDirectoryContext(ConfigFileMixin, ConfigDirectoryContext):
""" """
A config context for a lexicon's config directory. 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.draft = ConfigDirectoryContext(os.path.join(self.path, 'draft'))
self.src = ConfigDirectoryContext(os.path.join(self.path, 'src')) 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(ConfigFileMixin, ConfigDirectoryContext):
class UserConfigDirectoryContext(ConfigDirectoryContext):
""" """
A config context for a user's config directory. A config context for a user's config directory.
""" """
def config(self, edit=False): pass
if edit:
return self.edit('config')
else:
return self.read('config')