Esempio n. 1
0
  def get_params (self, section):
    try:

      return self._data.items(section)

    except:
      raise CfgVariableError('Config error! Section "{}" does not exist'.format(section))
Esempio n. 2
0
  def get (self, key, default=None):

    try:
      return self._data if key in self._data else default

    except:
      raise CfgVariableError('Type variable not recognized! Possible variables are only [bool, int, float, string, vector<int>, vector<float>, vector<string>].')
Esempio n. 3
0
  def __init__ (self, filename):

    if not os.path.isfile(filename):
      raise FileNotFoundError('Could not open or find the config file. Given: {}'.format(filename))

    self._data = configparser.ConfigParser(defaults=None, dict_type=self.multidict, strict=False)
    self._data.read(filename)

    first_section = self._data.sections()[0]

    if not first_section.startswith('net') and not first_section.startswith('network'):
      raise CfgVariableError('Config error! First section must be a network one (ex. [net] / [network]). Given: [{}]'.format(first_section))
Esempio n. 4
0
  def get (self, key, default=None):
    '''
    Getter function

    Parameters
    ----------
      key : str
        config dictionary key

      default : dtype (default=None)
        the default value if the key is not found in the data config
    '''

    try:
      return self._data[key] if key in self._data else default

    except:
      raise CfgVariableError('Type variable not recognized! Possible variables are only [bool, int, float, string, vector<int>, vector<float>, vector<string>].')
Esempio n. 5
0
    def __init__(self, filename):
        '''
    Network config parser

    Parameters
    ----------
      filename : str
        Network config filename or path

    Returns
    -------
      net_config object

    Notes
    -----
    The network configuration file must be stored in INI format.
    Since multiple layers can have the same type the dictionary must be overloaded by a
    custom OrderedDict
    '''

        if not os.path.isfile(filename):
            raise IOError(
                'Could not open or find the config file. Given: {}'.format(
                    filename))

        self._data = configparser.ConfigParser(defaults=None,
                                               dict_type=self.multidict,
                                               strict=False)
        self._data.read(filename)
        self._index = 0

        first_section = self._data.sections()[0]

        if not first_section.startswith(
                'net') and not first_section.startswith('network'):
            raise CfgVariableError(
                'Config error! First section must be a network one (ex. [net] / [network]). Given: [{}]'
                .format(first_section))