-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
executable file
·38 lines (27 loc) · 1.01 KB
/
config.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
from __future__ import print_function
import os
import sys
import time
import logging
if sys.version_info[0] < 3:
import ConfigParser as configparser
else:
import configparser
config = configparser.ConfigParser()
get = config.get
config_dir = os.path.dirname(__file__)
def parser_config():
config_file = os.path.join(config_dir, "conf")
if not os.path.exists(config_file):
sys.stderr.write("Error: Unable to find the config file!\n")
sys.exit(1)
# parse the configuration
global config
config.read_file(open(config_file))
parser_config()
logging.basicConfig(level=logging.INFO, filename=os.path.join(config_dir, time.strftime("%Y%m%d-%H%M%S") + ".log"), filemode="w",
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s',
datefmt='%Y/%m/%d %H:%M:%S')
ErrorHandler = logging.StreamHandler()
ErrorHandler.setFormatter(logging.Formatter(
'%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s'))