# Simple adjective-noun phrase generator.
#  by Leonard Richardson (leonardr@segfault.org)
#  for the PyCon 2003 talk "Beyond the Config File"
#  Example #2: Configuration interface-controlled configuration
#   Base CGI class for configure.cgi and generator.cgi

import IWantOptions
import os

class CGI:

    def __init__(self):
        self.config = \
                    IWantOptions.OptionConfig(self.getFile('definitionStore'),
                                              IWantOptions.OptionWrapper())
        self.context = IWantOptions.FileBackedContext \
                       (self.config, self.getFile('configurationStore'))
        self.run()        

    def getFile(self, file):
        "Returns the path to a file in the current directory."
        return os.path.join(os.getcwd(), file)

    def __getitem__(self, key):
        "Returns a value from the configuration."
        return self.config.getOptionValue(key, self.context)

    def run(self):
        "Hook method."
        pass


