1
1
import os
2
- from os import listdir
3
- from os .path import isfile , join
4
2
import gitcommands as git
5
- import time
6
3
import diffcalc
4
+ from ignore import getIgnoreFiles
5
+ import logger
6
+ from utils import getNestedFiles ,read_file ,commitAndUpdate
7
+ from colors import logcolors
7
8
mypath = os .getcwd ()
8
- nestfiles = []
9
- # add folders that you don't want to listen to
10
- ignoredirs = ['.git' , '.idea' , '__pycache__' , 'node_modules' ]
9
+
10
+ ignoredirs = getIgnoreFiles ()
11
+ print (ignoredirs )
12
+
11
13
# gets the list of all nested files
12
- def getNestedFiles (rootDir ):
13
- for path , subdirs , files in os .walk (rootDir ):
14
- if (all (ele not in path for ele in ignoredirs )):
15
- for name in files :
16
- nestfiles .append (join (path , name ))
17
- return nestfiles
18
-
19
- onlyfiles = getNestedFiles (mypath )
14
+ onlyfiles = getNestedFiles (mypath ,ignoredirs )
20
15
21
- # Reads and appends the contents of each file
22
- def read_file ():
23
- filecontent = []
24
- for file in onlyfiles :
25
- with open (onlyfiles [onlyfiles .index (file )], "r" ) as f :
26
- filecontent .append (f .readlines ())
27
- return filecontent
28
16
29
- def ischanged (url , branch ):
17
+
18
+ def ischanged (url , branch ,* args ,** kwargs ):
30
19
changedfile = []
20
+ diffarr = []
21
+ # if uncommited data found perform git commands on them
22
+ initbuffer = kwargs .get ('initbuffer' , - 1 )
23
+ if (initbuffer != - 1 ):
24
+ for obj in initbuffer :
25
+ file = obj ['path' ]
26
+ diff = obj ['changes' ]
27
+ diffarr .append (diff )
28
+ changedfile .append (file )
29
+
30
+ # Performing Git Commands for changed files
31
+ commitAndUpdate (changedfile ,diffarr ,url ,branch )
31
32
print ('Listening for changes....' )
32
- initial = list (read_file ())
33
+ initial = list (read_file (onlyfiles ))
33
34
while True :
34
- current = list (read_file ())
35
+ current = list (read_file (onlyfiles ))
35
36
changeditem = []
36
37
previtem = []
37
38
if (current != initial ):
@@ -45,21 +46,19 @@ def ischanged(url , branch):
45
46
if ele not in initial :
46
47
changeditem .append (ele )
47
48
# calculating changed file's name
48
- for i in range (0 , len (changeditem )):
49
- print ('loop :-' , i )
49
+ for i in range (0 , len (changeditem )):
50
+ print ('loop :-' , i )
50
51
changedfile .append (onlyfiles [current .index (changeditem [i ])])
51
- print ('Changed file is:-' , changedfile ,'\n ' )
52
+ print (f"Changed file is { logcolors .BOLD } { changedfile } { logcolors .ENDC } \n " )
53
+
52
54
# Calculating Diff for previous and changed version of file
53
- diffcalc .calcDiff (previtem , changeditem [0 ])
55
+ diff = diffcalc .calcDiff (previtem , changeditem [0 ])
56
+ diffarr .append (diff )
57
+ for file in changedfile :
58
+ logger .writedata (path = file , diff = diff )
54
59
55
- # Performing Git Commands For Changed File
56
- # Performing Git Add
57
- git .add (changedfile )
58
- # Performing Git Commit
59
- if (git .commit (changedfile ) == False ):
60
- print ('Reverting Push' )
61
- # Performing Git Push
62
- elif (len (changedfile ) == 0 ):
63
- git .push (url , branch )
64
- initial = current
60
+ # Performing Git Commands for changed files
61
+ commitAndUpdate (changedfile ,diffarr ,url ,branch )
65
62
63
+ initial = current
64
+ # time.sleep(5)
0 commit comments