-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.py
More file actions
68 lines (56 loc) · 1.88 KB
/
Common.py
File metadata and controls
68 lines (56 loc) · 1.88 KB
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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os, sys, logging
def we_are_frozen():
"""Returns whether we are frozen via py2exe.
This will affect how we find out where we are located."""
return hasattr(sys, "frozen")
def module_path():
""" This will get us the program's directory,
even if we are frozen using py2exe"""
if we_are_frozen():
return os.path.dirname(sys.executable)
return os.path.dirname(__file__)
VERSION = "2.0.6"
DIR_PATH = module_path()
DEF_CONF_FILE = os.path.join(DIR_PATH, 'setting.conf')
def loadSetting(path = DEF_CONF_FILE):
config = {}
# read config file
try:
fp = open(path, "r")
except IOError:
# use default parameters
return config
# parse user defined parameters
while True:
line = fp.readline()
if line == "":
# end line
break
line = line.strip()
if line == "":
continue
if line.startswith("#"):
continue
(name, sep, value) = line.partition("=")
if sep == "=":
name = name.strip().lower()
value = value.strip()
config.update({name:value})
fp.close()
return config
def getLogger(loggerName):
logger = logging.getLogger(loggerName)
#import inspect
#this_file = inspect.getfile(inspect.currentframe())
#dirpath = os.path.abspath(os.path.dirname(this_file)) # "c:\windows\system32\" same as os.getcwd()
handler = logging.FileHandler(os.path.join(DIR_PATH, loggerName + ".log"))
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
return logger
if __name__ == "__main__":
pass
# empty