Last active
January 3, 2016 07:09
-
-
Save webmaster128/8427456 to your computer and use it in GitHub Desktop.
A script to pull all git repositories in sub directories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import threading | |
import glob | |
import os.path | |
import time | |
class myThread (threading.Thread): | |
def __init__(self, threadID, name, repo): | |
threading.Thread.__init__(self) | |
self.threadID = threadID | |
self.name = name | |
self.repo = repo | |
def run(self): | |
print("Starting " + self.name) | |
# Get lock to synchronize threads | |
threadLock.acquire() | |
pull_repo(self.name, self.repo) | |
# Free lock to release next thread | |
threadLock.release() | |
def pull_repo(threadName, repo): | |
os.system('bash -c "cd ' + repo + ' && git pull"') | |
directories = glob.glob('./*') | |
repos = [x for x in directories if os.path.isdir(x) and os.path.isdir(x + "/.git")] | |
threadLock = threading.Lock() | |
threads = [] | |
for i in range(len(repos)): | |
while threading.activeCount() > 3: | |
time.sleep(0.05) | |
t = myThread(i, "Job " + str(i), repos[i]) | |
t.start() | |
threads.append(t) | |
# Wait for all threads to complete | |
for t in threads: | |
t.join() | |
print("Done. Have a nice day!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment