1+ #!/usr/bin/env python3
2+
3+ ## PySimpleGUI installing instructions:
4+ ## Run one if these commands:
5+ ## - py -m pip install pysimplegui
6+ ## - pip install pysimplegui
7+ ## - pip3 install pysimplegui
8+ ## If there's Tkinter error afterwards, install `python-tk` or `python3-tk` from your package manager
9+
10+ import os
11+ from typing import List
12+
13+ try :
14+ import PySimpleGUI as sg
15+ except ModuleNotFoundError :
16+ print ("PySimpleGUI was not installed properly. See installing instructions in the script." )
17+ exit ()
18+
19+
20+ def createWindow ():
21+ sg .theme ("DarkBlack" )
22+
23+ optionColumn = [
24+ [sg .Text ('✦Git Recursive Puller✦' , font = 'Atari-Regular 30' )],
25+ [sg .Text ('Command to run: ' ), sg .InputText (default_text = "git pull" , focus = False )],
26+ [sg .Text ('Path to executing directory: ' ), sg .InputText ()],
27+ [sg .Text ('Excluding paths: ' ), sg .InputText ()],
28+ ]
29+ layout = [
30+ [
31+ sg .Column (optionColumn ),
32+ sg .VSeparator (),
33+ sg .Column ([[sg .Output (size = (40 ,15 ))]])
34+ ],
35+ [sg .Button ('Run' ), sg .Button ('Cancel' )]
36+ ]
37+ window = sg .Window ('Git Puller' , layout )
38+ return window
39+
40+
41+ def recursivePull (directories : List [str ], exclude : List [str ], command : str ) -> None :
42+ def changeDirectory (r_path ):
43+ ack = 1
44+ try :
45+ root = os .path .dirname (__file__ )
46+ rel_path = os .path .join (".." , r_path )
47+
48+ abs_path = os .path .join (root , rel_path )
49+ os .chdir (abs_path )
50+ ack = 0
51+ except Exception as details :
52+ print ('problem to get to the path ' + r_path + ' (0001) : ' + str (details ))
53+ return ack
54+
55+ print (f"[@] Working with configurations:\n - Executing directories: { directories } \n - Excluding: { exclude } \n - Command: { command } \n " )
56+ print ("[!] Operation started\n " )
57+
58+ for directory in directories :
59+ for root , dirs , files in os .walk (directory , topdown = True ):
60+
61+ if '.git' in dirs and root .split ('/' )[- 1 ] not in exclude :
62+ print (f"[*] Running { command } on { root } " )
63+ changeDirectory (root )
64+ print (os .popen (command ).read ())
65+
66+ dirs [:] = [d for d in dirs if d not in ['.git' ]]
67+
68+ print ("[+] Operation successfully completed" )
69+
70+
71+ def main ():
72+ window = createWindow ()
73+ while True :
74+ event , values = window .read ()
75+ if event in [sg .WIN_CLOSED , 'Cancel' ]:
76+ break
77+
78+ command = values [0 ]
79+ directories = values [1 ].split ()
80+ exclude = values [2 ]
81+ recursivePull (directories , exclude , command )
82+
83+ window .close ()
84+
85+
86+ if __name__ == '__main__' :
87+ main ()
0 commit comments