forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilechange.py
65 lines (57 loc) · 2.14 KB
/
filechange.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
64
65
import os
import gitcommands as git
import diffcalc
from ignore import getIgnoreFiles
import logger
from utils import getNestedFiles, read_file, commitAndUpdate
from colors import logcolors
mypath = os.getcwd()
ignoredirs = getIgnoreFiles()
print(ignoredirs)
# gets the list of all nested files
onlyfiles = getNestedFiles(mypath, ignoredirs)
def ischanged(url, branch, *args, **kwargs):
changedfile = []
diffarr = []
# if uncommited data found perform git commands on them
initbuffer = kwargs.get('initbuffer', -1)
if (initbuffer != -1):
for obj in initbuffer:
file = obj['path']
diff = obj['changes']
diffarr.append(diff)
changedfile.append(file)
# Performing Git Commands for changed files
commitAndUpdate(changedfile, diffarr, url, branch)
print('Listening for changes....')
initial = list(read_file(onlyfiles))
while True:
current = list(read_file(onlyfiles))
changeditem = []
previtem = []
if (current != initial):
# Calculating Previous Version of File
for ele in initial:
if ele not in current:
for item in ele:
previtem.append(item)
# Calculating New Version of File
for ele in current:
if ele not in initial:
changeditem.append(ele)
# calculating changed file's name
for i in range(0, len(changeditem)):
print('loop :-', i)
changedfile.append(onlyfiles[current.index(changeditem[i])])
print(
f"Changed file is {logcolors.BOLD}{changedfile}{logcolors.ENDC}\n"
)
# Calculating Diff for previous and changed version of file
diff = diffcalc.calcDiff(previtem, changeditem[0])
diffarr.append(diff)
for file in changedfile:
logger.writedata(path=file, diff=diff)
# Performing Git Commands for changed files
commitAndUpdate(changedfile, diffarr, url, branch)
initial = current
# time.sleep(5)