-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
52 lines (41 loc) · 1.44 KB
/
utils.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
"""
Module that provides utilities for the application
"""
import os
import sys
import logging
# Setting logger
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
fmt = logging.Formatter(datefmt="%H:%M:%S",
fmt='%(asctime)s %(levelname)-8s: %(name)s: %(message)s')
sh = logging.StreamHandler()
sh.setFormatter(fmt)
log.addHandler(sh)
class Utils():
"""
Class that implements the utilities for the application
"""
def __init__(self, logLevel=logging.DEBUG):
log.setLevel(logLevel)
if dir(sys).__contains__('frozen'): # Mac bundle
self.json_example_file = "example_input.json"
else:
self.abs_p = os.path.abspath(os.path.join(__file__, os.pardir))
self.json_example_file = os.path.join(self.abs_p, "example_input.json")
log.debug("json_example_file=%s", self.json_example_file)
log.info("%s(%d) logLevel=%d", self.__class__.__name__, id(self), logLevel)
def __read_file(self, fname=None):
output = ""
if not fname is None:
with open(fname, 'r') as f:
output = f.read()
return output
def get_json_example_input(self):
log.debug("get_json_example_input file=%s",self.json_example_file)
return self.__read_file(self.json_example_file)
def run_utils():
u = Utils(logLevel=logging.DEBUG)
u.get_json_example_input()
if __name__ == '__main__':
run_utils()