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 740c176

Browse files
refac: extracted utility functions to utils.py
1 parent 8c5314e commit 740c176

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

‎Github-Automation/diffcalc.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
from colors import logcolors
2+
from difflib import ndiff
3+
from utils import getMaxSpaces
14

2-
import difflib
35

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
116

12-
def calcDiff(firstFile , secondFile):
13-
diff = difflib.ndiff(firstFile , secondFile)
7+
def calcDiff(firstFile, secondFile):
8+
# calculate raw diff
9+
diff = ndiff(firstFile, secondFile)
10+
# calculate unique lines in secondfile
1411
deltainit = ''.join(x[2:] for x in diff if x.startswith('+ '))
12+
# reformat the lines
1513
deltainit = deltainit.split('\n')
1614
maxspacesinit = getMaxSpaces(deltainit)
17-
print('CHANGED LINES ARE:-\n' , '-' * maxspacesinit)
15+
print(f'{logcolors.BOLD}CHANGED LINES ARE{logcolors.ENDC}\n',
16+
f'{logcolors.BOLD}-{logcolors.ENDC}' * maxspacesinit)
17+
1818
for ele in deltainit:
19-
print(str(ele.strip()) , ' ' * (maxspacesinit - len(ele.strip())), '+|')
20-
print('' , '-' * maxspacesinit)
21-
19+
print(f'{logcolors.SUCCESS} {str(ele.strip())} {logcolors.ENDC}',
20+
' ' * (maxspacesinit - len(ele.strip())), '+')
21+
22+
print('', f'{logcolors.BOLD}-{logcolors.ENDC}' * maxspacesinit)
23+
return deltainit

‎Github-Automation/gitcommands.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from subprocess import call
22
from sys import platform as _platform
3+
from colors import logcolors
4+
5+
36
def init():
47
call('git init')
5-
# git add <filename>
8+
9+
610
def createReadme():
711
if _platform == "linux" or _platform == "linux2":
812
call('touch README.md')
@@ -12,38 +16,50 @@ def createReadme():
1216
call('type nul>README.md')
1317

1418

15-
# Windows
1619
def add(filelist):
1720
for file in filelist:
1821
# perform git add on file
19-
print("Adding" , file)
22+
print(f"{logcolors.SUCCESS}Adding{logcolors.ENDC}",
23+
file.split('\\')[-1])
2024
call(('git add ' + file))
2125

2226
# git commit -m "passed message"
23-
def commit(filelist):
27+
28+
29+
def commit(filelist,*args,**kwargs):
30+
diffarr = kwargs.get('diffarr' , -1)
2431
for file in filelist:
2532
# ask user for commit message
26-
msg = str(input('Enter the commit message for ' + file + ' or enter -r to reject commit'))
33+
msg = str(input(f'{logcolors.BOLD}Enter the commit message for{logcolors.ENDC} ' +
34+
file.split('\\')[-1] + f' {logcolors.BOLD}or enter {logcolors.ERROR}-r{logcolors.ENDC} to reject commit{logcolors.ENDC}'))
2735
# if msg == -r reject commit
2836
if(msg == '-r'):
37+
print(f'{logcolors.ERROR}commit rejected{logcolors.ENDC}')
38+
if(diffarr != -1):
39+
diffarr.remove(diffarr[filelist.index(file)])
2940
filelist.remove(file)
30-
print('commit rejected')
3141
call('cls', shell=True)
3242
return False
3343
# else execute git commit for the file
34-
#added a comment
44+
#added a comment
3545
else:
36-
filelist.remove(file)
3746
call('git commit -m "' + msg + '"')
38-
call('cls' , shell=True)
39-
47+
call('cls', shell=True)
48+
print(
49+
f'Commited {logcolors.CYAN}{file}{logcolors.ENDC} with msg: {logcolors.BOLD}{msg}{logcolors.ENDC}')
50+
51+
4052
def setremote(url):
4153
call('git remote add origin ' + url)
42-
54+
55+
4356
def setBranch(branch):
4457
call('git branch -M ' + branch)
45-
58+
4659
# git push
47-
def push(url , branch):
60+
61+
62+
def push(url, branch):
4863
call('git push -u ' + url + ' ' + branch)
49-
#added a comment
64+
call('cls', shell=True)
65+
print(f'{logcolors.SUCCESS}Successfully Pushed Changes{logcolors.ENDC}')

‎Github-Automation/install.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
from shutil import copy , copyfile
22
import os
33
dir = os.getcwd()
4-
files = []
5-
# files = ['diffcalc.py' , 'main.py' , 'filechange.py' , 'gitcommands.py' , 'repoInfo.py']
6-
for file in os.listdir(dir):
7-
if(file.endswith('.py') and file != 'install.py'):
8-
files.append(file)
9-
print(files)
104

5+
files = [file for file in os.listdir(dir) if file.endswith('.py') and file != 'install.py']
6+
files.append('tmp.json')
7+
print(files)
118
def checkForIgnore(dst):
129
return os.path.isfile(os.path.join(dst , '.gitignore'))
1310

1411
def addToIgnore(dst):
1512
with open(os.path.join(dst , '.gitignore') , "a") as f:
16-
f.write('\n/auto-scripts')
13+
f.write('\nauto-scripts\n.idea\n__pycache__\n.git')
1714
f.close()
1815

1916
def makeIgnore(dst):
2017
f = open(os.path.join(dst , '.gitignore') , "x")
21-
f.write('/auto-scripts')
18+
f.write('auto-scripts\n.idea\n__pycache__\n.git')
2219
f.close()
2320

2421
def copyfiles(file:str , dst:str):
@@ -33,7 +30,6 @@ def installfiles():
3330
else:
3431
print('.gitignore not found, creating one')
3532
makeIgnore(location)
36-
addToIgnore(location)
3733
os.makedirs(os.path.join(location , 'auto-scripts'))
3834
location = os.path.join(location , 'auto-scripts')
3935
print('Installing Files')

0 commit comments

Comments
(0)

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