forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
63 lines (56 loc) · 2.07 KB
/
logger.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
55
56
57
58
59
60
61
62
63
import json
import os
from colors import logcolors
import filechange
jsonpath = os.path.join(os.getcwd(), 'auto-scripts', 'tmp.json')
buffer = []
def writedata(*args, **kwargs):
data = {}
global buffer
updatedbuffer = kwargs.get('buffer', -1)
path = kwargs.get('path', None)
diff = kwargs.get('diff', None)
if (updatedbuffer != -1):
buffer = updatedbuffer
with open(jsonpath, 'w') as file:
json.dump([obj for obj in buffer], file, indent=4)
elif (path and diff):
data['path'] = path
data['changes'] = diff
buffer.append(data)
with open(jsonpath, 'w') as file:
json.dump([obj for obj in buffer], file, indent=4)
def updatedata(filename, diffarr):
if (os.path.getsize(jsonpath) > 0):
with open(jsonpath, 'r') as file:
readdata = json.load(file)
if (len(readdata) == 0):
print('No changed file left')
else:
tmpdata, tmpfile, tmpdiff = readdata.copy(), filename.copy(
), diffarr.copy()
print('Found some changed files')
for file, diff in zip(filename, diffarr):
print(f'Removing {str(file)} from json file')
for obj in readdata:
if obj['path'] == file and obj['changes'] == diff:
tmpdata.remove(obj)
tmpfile.remove(file)
tmpdiff.remove(diff)
# make the original lists empty without changing address
del filename[:], diffarr[:]
writedata(buffer=tmpdata)
else:
print('No data to read')
def checkdata(url, branch):
if (os.path.getsize(jsonpath) > 0):
with open(jsonpath, 'r') as file:
initdata = json.load(file)
if (len(initdata) == 0):
print(f'{logcolors.SUCCESS}Change tree clean{logcolors.ENDC}')
else:
filechange.ischanged(url, branch, initbuffer=initdata)
else:
print(
f'{logcolors.ERROR}No changes found from previous session{logcolors.ENDC}'
)