Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed9b38d

Browse files
feat:log/remove files from json
1 parent f3e325f commit ed9b38d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

‎Github-Automation/logger.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
from colors import logcolors
4+
import filechange
5+
jsonpath = os.path.join(os.getcwd(), 'auto-scripts' , 'tmp.json')
6+
buffer = []
7+
8+
9+
def writedata(*args, **kwargs):
10+
data = {}
11+
global buffer
12+
updatedbuffer = kwargs.get('buffer', -1)
13+
path = kwargs.get('path', None)
14+
diff = kwargs.get('diff', None)
15+
if(updatedbuffer != -1):
16+
buffer = updatedbuffer
17+
with open(jsonpath, 'w') as file:
18+
json.dump([obj for obj in buffer], file, indent=4)
19+
elif(path and diff):
20+
data['path'] = path
21+
data['changes'] = diff
22+
buffer.append(data)
23+
with open(jsonpath, 'w') as file:
24+
json.dump([obj for obj in buffer], file, indent=4)
25+
26+
27+
def updatedata(filename, diffarr):
28+
if(os.path.getsize(jsonpath) > 0):
29+
with open(jsonpath, 'r') as file:
30+
readdata = json.load(file)
31+
if(len(readdata) == 0):
32+
print('No changed file left')
33+
else:
34+
tmpdata,tmpfile,tmpdiff = readdata.copy(),filename.copy(),diffarr.copy()
35+
print('Found some changed files')
36+
for file,diff in zip(filename,diffarr):
37+
print(f'Removing {str(file)} from json file')
38+
for obj in readdata:
39+
if obj['path'] == file and obj['changes'] == diff:
40+
tmpdata.remove(obj)
41+
tmpfile.remove(file)
42+
tmpdiff.remove(diff)
43+
# make the original lists empty without changing address
44+
del filename[:],diffarr[:]
45+
writedata(buffer=tmpdata)
46+
47+
else:
48+
print('No data to read')
49+
50+
51+
def checkdata(url , branch):
52+
if(os.path.getsize(jsonpath) > 0):
53+
with open(jsonpath, 'r') as file:
54+
initdata = json.load(file)
55+
if(len(initdata) == 0):
56+
print(f'{logcolors.SUCCESS}Change tree clean{logcolors.ENDC}')
57+
else:
58+
filechange.ischanged(url , branch , initbuffer = initdata)
59+
else:
60+
print(f'{logcolors.ERROR}No changes found from previous session{logcolors.ENDC}')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /