Exemplo n.º 1
0
 def print_content(self, substitute_values=True):
     """ print all the options variables substituted.
     
         :param a_substitue_vals: bool for substituting values
         :returns: the string containing all sections and variables
     """
     raise exceptions.Error("Not implemented in MockupConf")
Exemplo n.º 2
0
    def get_dict(self, section, option, default=None, fail_if_missing=False):
        """ get a dict """

        val = self.get(section, option, default, fail_if_missing)

        # parse it and return an error if invalid
        try:
            compiler = struct_parser.Compiler()
            return compiler.compile_dict(val)
        except struct_parser.CompilerError, err:
            raise exceptions.Error(err.message)
Exemplo n.º 3
0
 def items(self, section):
     """ return all items from a section. Items is a list of tuples (option,value)
         
         Args:
            section. The section where to find the option
            
         Returns: a list of tuples (option,value)
     
         Raises:
            exception NoSectionError if the section cannot be found
     """
     raise exceptions.Error("Not implemented in MockupConf")
 def _get_defaults(cls, section, option, default, fail_if_missing):
     """ To manage defaults.
         Args:
            default. The default value to return if fail_if_missing is False
            fail_if_missing. Throw an exception when the option is not found and fail_if_missing is true
            
         Returns: default if fail_if_missing is False
     
         Raises:
            exception NoOptionError if fail_if_missing is True
     """
     if fail_if_missing:
         raise exceptions.Error(2, "No option %s in section %s" %(option, section))
     else:
         if default is not None:
             return str(default)
         else:
             return None
    def _load_config(self, a_file=None):
        """ _load the configuration file """
        try:  
            # get it from a Resource if not files are passed
            if a_file is None:
                a_file = self._conf_resource.get_value() 

            if a_file is None:
                raise exceptions.Error("Conf. Error, need a configuration file path")

            with codecs.open(a_file, 'r', 'utf-8') as f:
                self._read(f, a_file)

            # memorize conf file path
            self._configuration_file_path = a_file

        except Exception, exce:
            print "Can't read the config file %s" % a_file
            print "Current executing from dir = %s\n" % os.getcwd()
            raise exce
Exemplo n.º 6
0
    def _load_config(self, a_file=None):
        """ _load the configuration file """
        try:
            # get it from a Resource if not files are passed
            if a_file is None:
                a_file = self._conf_resource.getValue()

            if a_file is None:
                raise exceptions.Error(
                    "Conf. Error, need a configuration file path")

            f_desc = open(a_file, 'r')

            self._read(f_desc, a_file)

            # memorize conf file path
            self._configuration_file_path = a_file

        except Exception, exce:
            print "Can't read the config file %s" % (a_file)
            print "Current executing from dir = %s\n" % (os.getcwd())
            raise exce