BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
boswatch.configYaml.ConfigYAML Class Reference

Public Member Functions

def __init__ (self, config=None)
 
def __iter__ (self)
 
def __len__ (self)
 returns the length of an config element
 
def __str__ (self)
 Returns the string representation of the internal config dict.
 
def loadConfigFile (self, configPath)
 loads a given configuration file
 
def get (self, *args, default=None)
 Get a single value from the config or a value set in a new configYAML class instance.
 

Protected Attributes

 _config
 

Constructor & Destructor Documentation

◆ __init__()

def boswatch.configYaml.ConfigYAML.__init__ (   self,
  config = None 
)
26 def __init__(self, config=None):
27 self._config = config
28

Member Function Documentation

◆ __iter__()

def boswatch.configYaml.ConfigYAML.__iter__ (   self)
29 def __iter__(self):
30 for item in self._config:
31 if type(item) is list or type(item) is dict:
32 yield ConfigYAML(item)
33 else:
34 yield item
35

◆ __len__()

def boswatch.configYaml.ConfigYAML.__len__ (   self)

returns the length of an config element

36 def __len__(self):
37 r"""!returns the length of an config element"""
38 return len(self._config)
39

◆ __str__()

def boswatch.configYaml.ConfigYAML.__str__ (   self)

Returns the string representation of the internal config dict.

40 def __str__(self):
41 r"""!Returns the string representation of the internal config dict"""
42 return str(self._config)
43

◆ loadConfigFile()

def boswatch.configYaml.ConfigYAML.loadConfigFile (   self,
  configPath 
)

loads a given configuration file

    @param configPath: Path to the config file
    @return True or False
44 def loadConfigFile(self, configPath):
45 r"""!loads a given configuration file
46
47 @param configPath: Path to the config file
48 @return True or False"""
49 logging.debug("load config file from: %s", configPath)
50 try:
51 with open(configPath) as file:
52 # use safe_load instead load
53 self._config = yaml.safe_load(file)
54 return True
55 except FileNotFoundError:
56 logging.error("config file not found: %s", configPath)
57 except yaml.parser.ParserError:
58 logging.exception("syntax error in config file: %s", configPath)
59 return False
60

◆ get()

def boswatch.configYaml.ConfigYAML.get (   self,
args,
  default = None 
)

Get a single value from the config or a value set in a new configYAML class instance.

Parameters
*argsConfig section (one ore more strings)
defaultDefault value if section not found (None)
Returns
: A single value, a value set in an configYAML instance, the default value
61 def get(self, *args, default=None):
62 r"""!Get a single value from the config
63 or a value set in a new configYAML class instance
64
65 @param *args: Config section (one ore more strings)
66 @param default: Default value if section not found (None)
67 @return: A single value, a value set in an configYAML instance, the default value"""
68 tmp = self._config
69 try:
70 for arg in args:
71 tmp = tmp.get(arg, default)
72 if type(tmp) is list or type(tmp) is dict:
73 return ConfigYAML(tmp)
74 else:
75 return tmp
76 except AttributeError: # pragma: no cover
77 return default

Field Documentation

◆ _config

boswatch.configYaml.ConfigYAML._config
protected