-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (21 loc) · 751 Bytes
/
utils.py
File metadata and controls
30 lines (21 loc) · 751 Bytes
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
# -*- coding: utf8 -*-
import os
import configparser
_base_dir = os.path.abspath(os.path.dirname(__name__))
def load_config(filename):
"""
load config file
:param str filename: file path
"""
config = configparser.ConfigParser()
file_path = os.path.join(_base_dir, filename)
config.read(file_path)
print("Loaded config from path: {}".format(file_path))
if 'default' not in config:
raise IOError('Unable to load configuration file "{}"'.format(filename))
# 必选字段
for k in ['server', 'server_port', 'local', 'local_port', 'debug']:
if k not in config['default']:
raise KeyError('Not found field: "{}"'.format(k))
return config
config = load_config('config.ini')