@@ -0,0 +1,2406 @@
+# Copyright 2013 Mitchell Stanton-Cook Licensed under the%0A# Educational Community License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may%0A# obtain a copy of the License at%0A#%0A# http://www.osedu.org/licenses/ECL-2.0%0A#%0A# Unless required by applicable law or agreed to in writing,%0A# software distributed under the License is distributed on an %22AS IS%22%0A# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express%0A# or implied. See the License for the specific language governing%0A# permissions and limitations under the License.%0A%0A%0Aimport os%0Aimport sys%0A%0Aclass BanzaiEBConfig():%0A    %22%22%22%0A    Banzai-EasyBuild configuration class%0A    %22%22%22%0A%0A    def __init__(self):%0A        self.config = self.read_config()%0A%0A    def __getitem__(self, key):%0A        try:%0A            return self.config%5Bkey%5D%0A        except KeyError:%0A            msg = %22Trying to get config option that does not exist.%5Cn%22%0A            sys.stderr.write(msg)%0A            return None%0A%0A    def __setitem__(self, key, item):%0A        self.config%5Bkey%5D = item%0A%0A    def read_config(self):%0A        %22%22%22%0A        Read a Banzai-EasyBuild configuration file%0A    %0A        Currently only supports:%0A            * cfg_location = %5Bdef = ''%5D%0A    %22%22%22%0A        cfg = %7B%7D%0A        cfg%5B'cfg_location'%5D = ''%0A        try:%0A            with open(os.path.expanduser('~/')+'.BanzaiEB.cfg') as fin:%0A                colors = %5B%5D%0A                for line in fin:%0A                    if line.startswith('cfg_location'):%0A                        option, val = line.split('=')%0A                        cfg%5Boption.strip()%5D = val.strip()%0A        except IOError:%0A            print %22Banzai-EasyBuild config file NOT FOUND%22%0A        return cfg%0A%0A    def dump_items(self):%0A        %22%22%22%0A        Prints all set configuration options to STDOUT%0A        %22%22%22%0A        for key, value in self.config.items():%0A            print %22%25s = %25s%5Cn%22 %25 (str(key), str(value))%0A%0A    def write_items(self):%0A        %22%22%22%0A        Writes the config options to ~/.BanzaiEB.cfg%0A        %22%22%22%0A        if os.path.isfile(os.path.expanduser('~/')+'.BanzaiEB.cfg'):%0A            print %22Banzai-Easybuild config file exists. Not overwriting%22%0A            sys.exit(-1)%0A        else:%0A            with open(os.path.expanduser('~/')+'.BanzaiEB.cfg', 'w') as fout:%0A                for key, value in self.config.items():%0A                    fout.write(%22%25s = %25s%5Cn%22 %25 (str(key), str(value)))%0A

Add a config object