-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguipull.py
86 lines (66 loc) · 2.57 KB
/
guipull.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
## PySimpleGUI installing instructions:
## Run one of these commands:
## - py -m pip install pysimplegui
## - pip install pysimplegui
## - pip3 install pysimplegui
## If there's Tkinter error afterwards, install `python-tk` or `python3-tk` from your package manager
import os
from typing import List
try:
import PySimpleGUI as sg
except ModuleNotFoundError:
print("PySimpleGUI was not installed properly. See installing instructions in the script.")
exit()
def createWindow():
sg.theme("DarkBlack")
optionColumn = [
[sg.Text('✦Git Recursive Puller✦', font='Atari-Regular 30')],
[sg.Text('Command to run: '), sg.InputText(default_text="git pull", focus=False)],
[sg.Text('Path to executing directory: '), sg.InputText()],
[sg.Text('Excluding paths: '), sg.InputText()],
]
layout = [
[
sg.Column(optionColumn),
sg.VSeparator(),
sg.Column([[sg.Output(size=(40,15))]])
],
[sg.Button('Run'), sg.Button('Cancel')]
]
window = sg.Window('Git Puller', layout)
return window
def recursivePull(directories: List[str], exclude: List[str], command: str) -> None:
def changeDirectory(r_path):
ack = 1
try:
root = os.path.dirname(__file__)
rel_path = os.path.join("..", r_path)
abs_path = os.path.join(root, rel_path)
os.chdir(abs_path)
ack = 0
except Exception as details:
print('[%] Problem to get to the path '+r_path+' (0001) : ' + str(details))
return ack
print(f"[@] Working with configurations:\n- Executing directories: {directories}\n- Excluding: {exclude}\n- Command: {command}\n\n[!] Operation started\n")
for directory in directories:
for root, dirs, files in os.walk(directory, topdown=True):
if '.git' in dirs and root.split('/')[-1] not in exclude:
print(f"[*] Running {command} on {root}")
changeDirectory(root)
print(os.popen(command).read())
dirs[:] = [d for d in dirs if d not in ['.git']]
print("[+] Operation successfully completed\n")
def main():
window = createWindow()
while True:
event, values = window.read()
if event in [sg.WIN_CLOSED, 'Cancel']:
break
command = values[0]
directories = values[1].split()
exclude = values[2].split()
recursivePull(directories, exclude, command)
window.close()
if __name__ == '__main__':
main()