Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Protected Attributes | Static Protected Attributes
SqlConfigParser Class Reference
Inheritance diagram for SqlConfigParser:
Inheritance graph
[legend]
Collaboration diagram for SqlConfigParser:
Collaboration graph
[legend]

Public Member Functions

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

Data Fields

 cnx
 

Protected Attributes

 _sections
 
 _tablename
 
- Protected Attributes inherited from MultiOrderedConfigParser
 _defaults
 
 _includes
 
 _parent
 
 _sections
 

Static Protected Attributes

str _tablename = "sippeers"
 

Additional Inherited Members

- Protected Member Functions inherited from MultiOrderedConfigParser
 _read (self, config_file, sect)
 

Detailed Description

Definition at line 13 of file sqlconfigparser.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  tablename = "sippeers" 
)

Reimplemented from MultiOrderedConfigParser.

Definition at line 17 of file sqlconfigparser.py.

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

Member Function Documentation

◆ connect()

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()

read (   self,
  filename,
  sect = None 
)
Parse configuration information from a file

Reimplemented from MultiOrderedConfigParser.

Definition at line 24 of file sqlconfigparser.py.

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:150

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

◆ write()

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

Reimplemented from MultiOrderedConfigParser.

Definition at line 67 of file sqlconfigparser.py.

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()

Referenced by MultiOrderedConfigParser.write().

◆ write_dicts()

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.

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

Field Documentation

◆ _sections

_sections
protected

◆ _tablename [1/2]

str _tablename = "sippeers"
staticprotected

Definition at line 15 of file sqlconfigparser.py.

Referenced by SqlConfigParser.read().

◆ _tablename [2/2]

_tablename
protected

Definition at line 18 of file sqlconfigparser.py.

Referenced by SqlConfigParser.read().

◆ 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: