-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathini.py
62 lines (54 loc) · 1.54 KB
/
ini.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
from ConfigParser import ConfigParser
from PyQt4.QtCore import QString
def read_ini(file, section, value, default=""):
if isinstance(file, str) or isinstance(file, QString):
conf = ConfigParser()
conf.read(str(file))
else:
conf = file
values = conf.sections()
for val in values:
if val.lower() == section.lower():
for c in conf.options(val):
if c.lower() == value.lower():
return conf.get(val, c)
return default
def read_ini_bool(file, section, value, default=False):
if isinstance(file, str) or isinstance(file, QString):
conf = ConfigParser()
conf.read(str(file))
else:
conf = file
values = conf.sections()
for val in values:
if val.lower() == section.lower():
for c in conf.options(val):
if c.lower() == value.lower():
return conf.getboolean(val, c)
return default
def read_ini_int(file, section, value, default=0):
if isinstance(file, str) or isinstance(file, QString):
conf = ConfigParser()
conf.read(str(file))
else:
conf = file
values = conf.sections()
for val in values:
if val.lower() == section.lower():
for c in conf.options(val):
if c.lower() == value.lower():
return conf.getint(val, c)
return default
def read_ini_float(file, section, value, default=0.0):
if isinstance(file, str) or isinstance(file, QString):
conf = ConfigParser()
conf.read(str(file))
else:
conf = file
values = conf.sections()
for val in values:
if val.lower() == section.lower():
for c in conf.options(val):
if c.lower() == value.lower():
return conf.getfloat(val, c)
return default