From 3bdc5103ae2b845e9c83a789b5781ee4ee979d7c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 22 Jun 2015 00:35:10 -0400 Subject: Refactored and added Environment module --- cbc/environment.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 cbc/environment.py (limited to 'cbc/environment.py') diff --git a/cbc/environment.py b/cbc/environment.py new file mode 100755 index 0000000..78b64cc --- /dev/null +++ b/cbc/environment.py @@ -0,0 +1,28 @@ +import os + +class IncompleteEnv(Exception): + pass + +class Environment(object): + def __init__(self, *args, **kwargs): + self.environ = os.environ.copy() + self.config = {} + self.cbchome = None + + if 'CBC_HOME' in kwargs: + self.cbchome = kwargs['CBC_HOME'] + if 'CBC_HOME' in self.environ: + self.cbchome = self.environ['CBC_HOME'] + + if self.cbchome is None: + raise IncompleteEnv('Environment.cbchome is undefined') + + if not os.path.exists(self.cbchome): + os.makedirs(self.cbchome) + + self.config['meta'] = self.join('meta.yaml') + self.config['build'] = self.join('build.sh') + self.config['build_windows'] = self.join('bld.bat') + + def join(self, path): + return os.path.join(self.cbchome, path) \ No newline at end of file -- cgit