Skip to content

Commit 13ea7a7

Browse files
committed
fix: nested-files,diff calc,add to gitignore
1 parent 8d0e805 commit 13ea7a7

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

Github-Automation/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ To run the script use following commands
3030

3131
4. Run the python script to listen for changes
3232
```python
33-
python main.py
33+
python ./auto-scripts/main.py
3434
```
3535

36+
***Note:** This script listens to all nested files, ignoring directories like `.git` , `node_modules`. If you want to add custom folders that you want the script to ignore add them in filechange.py like this:*
37+
```python
38+
10 ignoredirs = ['.git' , '.idea' , '__pycache__' , 'node_modules' , 'custom_folder']
39+
```

Github-Automation/diffcalc.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
12
import difflib
23

4+
def getMaxSpaces(file):
5+
max = float('-inf')
6+
for ele in file:
7+
ele = ele.strip()
8+
if(len(ele) > max):
9+
max = len(ele)
10+
return max
11+
312
def calcDiff(firstFile , secondFile):
413
diff = difflib.ndiff(firstFile , secondFile)
5-
delta = ''.join(x[2:] for x in diff if x.startswith('+ '))
6-
deltaNoSpace = delta.split('\n')
7-
print('CHANGED LINES ARE:-\n-----------------')
8-
for ele in deltaNoSpace:
9-
print(ele.strip())
10-
print('-----------------\n')
14+
deltainit = ''.join(x[2:] for x in diff if x.startswith('+ '))
15+
deltainit = deltainit.split('\n')
16+
maxspacesinit = getMaxSpaces(deltainit)
17+
print('CHANGED LINES ARE:-\n' , '-' * maxspacesinit)
18+
for ele in deltainit:
19+
print(str(ele.strip()) , ' ' * (maxspacesinit - len(ele.strip())), '+|')
20+
print('' , '-' * maxspacesinit)
21+

Github-Automation/filechange.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@
55
import time
66
import diffcalc
77
mypath = os.getcwd()
8-
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
8+
nestfiles = []
9+
# add folders that you don't want to listen to
10+
ignoredirs = ['.git' , '.idea' , '__pycache__' , 'node_modules']
11+
# 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)
20+
21+
# Reads and appends the contents of each file
922
def read_file():
1023
filecontent = []
1124
for file in onlyfiles:
@@ -50,6 +63,3 @@ def ischanged(url , branch):
5063
git.push(url , branch)
5164
initial = current
5265

53-
54-
55-

Github-Automation/install.py

+23
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,35 @@
77
if(file.endswith('.py') and file != 'install.py'):
88
files.append(file)
99
print(files)
10+
11+
def checkForIgnore(dst):
12+
return os.path.isfile(os.path.join(dst , '.gitignore'))
13+
14+
def addToIgnore(dst):
15+
with open(os.path.join(dst , '.gitignore') , "a") as f:
16+
f.write('\n/auto-scripts')
17+
f.close()
18+
19+
def makeIgnore(dst):
20+
f = open(os.path.join(dst , '.gitignore') , "x")
21+
f.write('/auto-scripts')
22+
f.close()
23+
1024
def copyfiles(file:str , dst:str):
1125
copy(file , dst)
1226
print('Installation Successful\n')
1327

1428
def installfiles():
1529
location = input('Enter installation directory: ')
30+
if(checkForIgnore(location)):
31+
print('.gitignore found')
32+
addToIgnore(location)
33+
else:
34+
print('.gitignore not found, creating one')
35+
makeIgnore(location)
36+
addToIgnore(location)
37+
os.makedirs(os.path.join(location , 'auto-scripts'))
38+
location = os.path.join(location , 'auto-scripts')
1639
print('Installing Files')
1740
for file in files:
1841
print('Installing %s' % file)

Github-Automation/main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import repoInfo,filechange
32
import gitcommands as git
43
def init():
@@ -19,4 +18,4 @@ def init():
1918
filechange.ischanged(info[0] , info[1])
2019

2120
if __name__ == '__main__':
22-
init()
21+
init()

0 commit comments

Comments
 (0)