/
conf_reader.py
36 lines (28 loc) · 1004 Bytes
/
conf_reader.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
#!/usr/bin/env python3
import configparser
import os
class ReadConfig:
def __init__(self, filepath="analyzer.conf"):
root_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(root_dir, filepath)
self.cf = configparser.ConfigParser()
self.cf.read(config_path, encoding='utf-8')
def get_thread_num(self):
value = self.cf.get("script", "thread_num")
return int(value)
def get_csv_path(self):
value = self.cf.get("script", "hosts_csv_filename")
return str(value)
def get_analyze_nums(self):
value = self.cf.get("script", "analyze_num")
return int(value)
def get_multi_thread_opt(self):
value = self.cf.get("script", "multi_thread")
return bool(value)
if __name__ == '__main__':
# test
config = ReadConfig()
print(config.get_thread_num())
print(config.get_csv_path())
print(config.get_analyze_nums())
print(config.get_multi_thread_opt())