1
0
Fork 0
mirror of synced 2024-06-01 15:01:10 -04:00
dotbot/dotbot/context.py
E. Keys d6e1e4ad56 Context._options defaults to argparse.Namespace
Updated default value of `Context._options` from `None` to `Namespace`.
This makes member access operate the same regardless of where used and
to remove the need for None checking. It also provides a hint to plugin
developers for how to deserialize options from a dict if they had to.
Opted for `argparse.Namespace` instead of `types.SimpleNamespace` to
support Python 2.7.
2020-12-03 17:28:28 -05:00

33 lines
848 B
Python

import copy
import os
from argparse import Namespace
class Context(object):
'''
Contextual data and information for plugins.
'''
def __init__(self, base_directory, options=Namespace()):
self._base_directory = base_directory
self._defaults = {}
self._options = options
pass
def set_base_directory(self, base_directory):
self._base_directory = base_directory
def base_directory(self, canonical_path=True):
base_directory = self._base_directory
if canonical_path:
base_directory = os.path.realpath(base_directory)
return base_directory
def set_defaults(self, defaults):
self._defaults = defaults
def defaults(self):
return copy.deepcopy(self._defaults)
def options(self):
return copy.deepcopy(self._options)