-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproto.py
55 lines (38 loc) · 1.09 KB
/
proto.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
53
54
from logger import putlog
import json
import os
log = putlog(__file__)
def readFile(filename):
content = ""
try:
with open(filename, 'r') as fileContent:
content = fileContent.read()
except Exception as Err:
log.error("{}".format(Err))
return content
def readJson(filename):
content = {}
try:
content = json.loads(readFile(filename))
except Exception as Err:
log.error("{}".format(Err),exc_info=True)
return content
def writeFile(filename, content):
os.makedirs(os.path.dirname(filename), exist_ok=True)
status = "success"
try:
with open(filename, 'w') as fileSource:
fileSource.write(content)
except Exception as Err:
log.error("{}".format(Err))
status = "failed"
return status
def writeJson(filename, content):
status = "Success"
try:
contentDump = json.dumps(content, indent=4, sort_keys=True)
writeFile(filename, contentDump)
except Exception as Err:
log.error("{}".format(Err))
status = "Failed"
return status