11"""Import modules"""
2- # pylint: disable=W0511,R0912,R0915
3- # TODO: Restructure the code to align with what Pylint wants ^
2+ # pylint: disable=R0912,R0915
43import os
54from datetime import datetime
65import sys
@@ -17,17 +16,17 @@ class Archive():
1716 parser = argparse .ArgumentParser (
1817 description = 'A powerful script to concurrently clone your entire' +
1918 'GitHub instance or save it as an archive.' )
20- parser .add_argument ('-uc' , '--user_clone ' , action = 'store_true' ,
19+ parser .add_argument ('-uc' , '--user-clone ' , action = 'store_true' ,
2120 help = 'Clone personal repos.' )
22- parser .add_argument ('-up' , '--user_pull ' , action = 'store_true' ,
21+ parser .add_argument ('-up' , '--user-pull ' , action = 'store_true' ,
2322 help = 'Pull personal repos' )
24- parser .add_argument ('-gc' , '--gists_clone ' , action = 'store_true' ,
23+ parser .add_argument ('-gc' , '--gists-clone ' , action = 'store_true' ,
2524 help = 'Clone personal gists' )
26- parser .add_argument ('-gp' , '--gists_pull ' , action = 'store_true' ,
25+ parser .add_argument ('-gp' , '--gists-pull ' , action = 'store_true' ,
2726 help = 'Pull personal gists.' )
28- parser .add_argument ('-oc' , '--orgs_clone ' , action = 'store_true' ,
27+ parser .add_argument ('-oc' , '--orgs-clone ' , action = 'store_true' ,
2928 help = 'Clone organization repos.' )
30- parser .add_argument ('-op' , '--orgs_pull ' , action = 'store_true' ,
29+ parser .add_argument ('-op' , '--orgs-pull ' , action = 'store_true' ,
3130 help = 'Pull organization repos.' )
3231 parser .add_argument ('-b' , '--branch' , default = 'master' ,
3332 help = 'Which branch to pull from.' )
@@ -153,6 +152,7 @@ def main():
153152 preamble = f'{ start_message } \n { start_time } \n '
154153 print (preamble )
155154 Archive .logs (preamble )
155+ thread_list = []
156156
157157 # Iterate over each personal repo and concurrently start cloning
158158 if Archive .args .user_clone is True :
@@ -164,8 +164,10 @@ def main():
164164 time .sleep (Archive .BUFFER )
165165 path = os .path .join (
166166 Archive .LOCATION , 'repos' , repo .owner .login , repo .name )
167- Thread (target = Archive .clone_repos , args = (
168- repo , path ,)).start ()
167+ repo_thread = Thread (target = Archive .clone_repos , args = (
168+ repo , path ,))
169+ thread_list .append (repo_thread )
170+ repo_thread .start ()
169171 else :
170172 data = '## Skipping cloning user repos... ##'
171173 print (data )
@@ -181,8 +183,10 @@ def main():
181183 time .sleep (Archive .BUFFER )
182184 path = os .path .join (
183185 Archive .LOCATION , 'repos' , repo .owner .login , repo .name )
184- Thread (target = Archive .pull_repos , args = (
185- repo , path ,)).start ()
186+ repo_thread = Thread (target = Archive .pull_repos , args = (
187+ repo , path ,))
188+ thread_list .append (repo_thread )
189+ repo_thread .start ()
186190 else :
187191 data = '## Skipping pulling user repos...## '
188192 print (data )
@@ -197,8 +201,10 @@ def main():
197201 time .sleep (Archive .BUFFER )
198202 path = os .path .join (
199203 Archive .LOCATION , 'gists' , gist .id )
200- Thread (target = Archive .clone_gists , args = (
201- gist , path ,)).start ()
204+ repo_thread = Thread (target = Archive .clone_gists , args = (
205+ gist , path ,))
206+ thread_list .append (repo_thread )
207+ repo_thread .start ()
202208 else :
203209 data = '## Skipping cloning gists... ##'
204210 print (data )
@@ -213,8 +219,10 @@ def main():
213219 time .sleep (Archive .BUFFER )
214220 path = os .path .join (
215221 Archive .LOCATION , 'gists' , gist .id )
216- Thread (target = Archive .pull_gists , args = (
217- gist , path ,)).start ()
222+ repo_thread = Thread (target = Archive .pull_gists , args = (
223+ gist , path ,))
224+ thread_list .append (repo_thread )
225+ repo_thread .start ()
218226 else :
219227 data = '## Skipping pulling gists... ##'
220228 print (data )
@@ -238,8 +246,10 @@ def main():
238246 time .sleep (Archive .BUFFER )
239247 path = os .path .join (
240248 Archive .LOCATION , 'repos' , repo .owner .login , repo .name )
241- Thread (target = Archive .clone_repos , args = (
242- repo , path ,)).start ()
249+ repo_thread = Thread (target = Archive .clone_repos , args = (
250+ repo , path ,))
251+ thread_list .append (repo_thread )
252+ repo_thread .start ()
243253 else :
244254 data = '## Skipping cloning org repos... ##'
245255 print (data )
@@ -257,15 +267,17 @@ def main():
257267 time .sleep (Archive .BUFFER )
258268 path = os .path .join (
259269 Archive .LOCATION , 'repos' , repo .owner .login , repo .name )
260- Thread (target = Archive .pull_repos , args = (
261- repo , path ,)).start ()
270+ repo_thread = Thread (target = Archive .pull_repos , args = (
271+ repo , path ,))
272+ thread_list .append (repo_thread )
273+ repo_thread .start ()
262274 else :
263275 data = '## Skipping pulling org repos... ##'
264276 print (data )
265277 Archive .logs (data )
266278
267- # TODO: Use threading.wait to check if all processes are finished
268- time . sleep ( 6 )
279+ for thread in thread_list :
280+ thread . join ( )
269281 execution_time = f'Execution time: { datetime .now () - start_time } .'
270282 finish_message = f'GitHub Archive complete! { execution_time } '
271283 print (finish_message )
0 commit comments