Skip to content
Alexey Kuksin edited this page Dec 2, 2015 · 1 revision

E.g. configStr = getConfig(parsedConfig, "PROJECT.HOME")

Parameters

  • cfg: parsed JSON configuration file confRequest: configuration request created by stringing JSON labels together (e.g. PROJECT.HOME)
  • confCase: default value = None; pass in "LIST_INDEX" if desired return value is a list of the indices in the confRequest

Key Variables

  • confList: list of the individual variable keys passed in (split by ".") as the confRequest
  • label: individual labels in confRequest
  • cfg: desired portion of the configuration file

Functionality

  • GetConfig splits the confRequest by "." into labels, storing them in confList.
  • For each label in confList, getConfig finds the desired configuration based on the structure of the configuration (cfg). If cfg is a dictionary, getConfig sets cfg equal to the value associated with the label (which is a key in the cfg dictionary). If cfg is a list, getConfig finds the integer associated with the label, and uses the label to index into the cfg list and set cfg equal to the element at that index.
  • Each iteration through the for loop, cfg gets one layer deeper until the confRequest is found.
  • After the confRequest, if confCase is "LIST_INDEX" and the remaining cfg is a list, cfg becomes a list of the indices of the elements of the list, instead of returning the elements of the list.

Except Statement

  • If an error arises, the except block writes to the log file. It records the time, the error message, the confRequest, and the type of the configuration.
  • The configuration is set to "CONF_NOT_FOUND".

Return Value

GetConfig returns cfg, corresponding to the confRequest.