Asterisk - The Open Source Telephony Project  18.5.0
Public Member Functions | Data Fields
SqlConfigParser Class Reference
Inheritance diagram for SqlConfigParser:
Inheritance graph
[legend]
Collaboration diagram for SqlConfigParser:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, tablename="sippeers")
 
def connect (self, user, password, host, port, database)
 
def read (self, filename, sect=None)
 
def write (self, config_file)
 
def write_dicts (self, config_file, mdicts)
 
- Public Member Functions inherited from MultiOrderedConfigParser
def __init__ (self, parent=None)
 
def add_default (self, key, template_keys=None)
 
def add_include (self, filename, parser=None)
 
def add_section (self, key, template_keys=None, mdicts=None)
 
def default (self, key)
 
def defaults (self)
 
def find_value (self, sections, key)
 
def get (self, section, key)
 
def get_defaults (self, key)
 
def get_sections (self, key, attr='_sections', searched=None)
 
def includes (self)
 
def multi_get (self, section, key_list)
 
def read (self, filename, sect=None)
 
def section (self, key)
 
def sections (self)
 
def set (self, section, key, val)
 
def write (self, config_file)
 

Data Fields

 cnx
 

Detailed Description

Definition at line 13 of file sqlconfigparser.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  tablename = "sippeers" 
)

Definition at line 17 of file sqlconfigparser.py.

References SqlConfigParser._tablename.

17  def __init__(self,tablename="sippeers"):
18  self._tablename=tablename
19  MultiOrderedConfigParser.__init__(self)
20 

Member Function Documentation

◆ connect()

def connect (   self,
  user,
  password,
  host,
  port,
  database 
)

Definition at line 21 of file sqlconfigparser.py.

21  def connect(self, user, password, host, port, database):
22  self.cnx = MySQLdb.connect(user=user,passwd=password,host=host,port=int(port),db=database)
23 

◆ read()

def read (   self,
  filename,
  sect = None 
)

Definition at line 24 of file sqlconfigparser.py.

References SqlConfigParser._tablename, MultiOrderedConfigParser.add_section(), SqlConfigParser.cnx, and str.

24  def read(self, filename, sect=None):
25  MultiOrderedConfigParser.read(self, filename, sect)
26  # cursor = self.cnx.cursor(dictionary=True)
27  cursor = self.cnx.cursor(cursorclass=MySQLdb.cursors.DictCursor)
28  cursor.execute("SELECT * from `" + MySQLdb.escape_string(self._tablename) + "`")
29  rows = cursor.fetchall()
30 
31  for row in rows:
32  sect = self.add_section(row['name'])
33  for key in row:
34  if (row[key] != None):
35  for elem in str(row[key]).split(";"):
36  sect[key] = elem
37  #sect[key] = str(row[key]).split(";")
38 
const char * str
Definition: app_jack.c:147

◆ write()

def write (   self,
  config_file 
)
Write configuration information out to a file

Definition at line 67 of file sqlconfigparser.py.

References MultiOrderedConfigParser._sections, and SqlConfigParser.write_dicts().

67  def write(self, config_file):
68  """Write configuration information out to a file"""
69  try:
70  self.write_dicts(config_file, self._sections)
71  except:
72  print("Could not open file " + config_file + " for writing")
73  traceback.print_exc()
74 

◆ write_dicts()

def write_dicts (   self,
  config_file,
  mdicts 
)
Write the contents of the mdicts to the specified config file

Definition at line 39 of file sqlconfigparser.py.

Referenced by SqlConfigParser.write().

39  def write_dicts(self, config_file, mdicts):
40  """Write the contents of the mdicts to the specified config file"""
41  for section, sect_list in mdicts.iteritems():
42  # every section contains a list of dictionaries
43  for sect in sect_list:
44  sql = "INSERT INTO "
45  if (sect.get('type')[0] == "endpoint"):
46  sql += "ps_endpoints "
47  elif (sect.get('type')[0] == "aor" and section != "sbc"):
48  sql += "ps_aors "
49  elif (sect.get('type')[0] == "identify"):
50  sql += "ps_endpoint_id_ips"
51  else:
52  continue
53 
54  sql += " SET `id` = " + "\"" + MySQLdb.escape_string(section) + "\""
55  for key, val_list in sect.iteritems():
56  if key == "type":
57  continue
58  # every value is also a list
59 
60  key_val = " `" + key + "`"
61  key_val += " = " + "\"" + MySQLdb.escape_string(";".join(val_list)) + "\""
62  sql += ","
63  sql += key_val
64 
65  config_file.write("%s;\n" % (sql))
66 
def write_dicts(config_file, mdicts)

Field Documentation

◆ cnx

cnx

Definition at line 22 of file sqlconfigparser.py.

Referenced by SqlConfigParser.read().


The documentation for this class was generated from the following file: