-
Notifications
You must be signed in to change notification settings - Fork 4
/
K2PKConfig.py
97 lines (77 loc) · 2.91 KB
/
K2PKConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from configparser import ConfigParser
def read_db_config(filename='config.ini', section='mysql'):
""" Read database configuration file and return a dictionary object.
:param filename: name of the configuration file
:param section: section of database configuration
:return: a dictionary of database parameters
"""
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
db = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
db[item[0]] = item[1]
else:
raise Exception(
'{0} not found in the {1} file'.format(section, filename))
return db
def read_octopart_config(filename='config.ini', section='octopart'):
""" Read database configuration file and return a dictionary object.
:param filename: name of the configuration file
:param section: section of database configuration
:return: a dictionary of Octopart parameters
"""
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
octopart = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
octopart[item[0]] = item[1]
else:
raise Exception(
'{0} not found in the {1} file'.format(section, filename))
return octopart
def read_distributors_config(filename='config.ini', section='distributors'):
""" Read database configuration file and return a dictionary object.
:param filename: name of the configuration file
:param section: section of database configuration
:return: a dictionary of database parameters
"""
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
distributors = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
distributors[item[0]] = item[1]
else:
raise Exception(
'{0} not found in the {1} file'.format(section, filename))
return distributors
def read_currency_config(filename='config.ini', section='currency'):
""" Read database configuration file and return a dictionary object.
:param filename: name of the configuration file
:param section: section of database configuration
:return: a dictionary of database parameters
"""
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
currency = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
currency[item[0]] = item[1]
else:
raise Exception(
'{0} not found in the {1} file'.format(section, filename))
return currency