Created
August 9, 2017 21:30
-
-
Save arozellia/b7474099ee3295259332cc473d962900 to your computer and use it in GitHub Desktop.
Check the git status of multiple directories. Raw
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
""" | |
This script checks all directories in a given location for a git folder and runs git status. | |
Update debug IP to set to your local server IP for testing if on a development machine. | |
""" | |
import os | |
import sys | |
import socket | |
import git | |
DEBUG_IPS = {''} | |
SERVER_WEB_DIR = "/var/www/html" | |
LOCAL_WEB_DIR = "c:\\apache\\htdocs" | |
def main(): | |
web_dir = SERVER_WEB_DIR | |
current_ip = socket.gethostbyname(socket.gethostname()) | |
if current_ip in DEBUG_IPS: | |
web_dir = LOCAL_WEB_DIR | |
print("In debug mode. IP: " + current_ip + ".") | |
if not os.path.isdir(web_dir): | |
print("\nWeb directory does not exist: " + web_dir + ". Please check your configuration.") | |
sys.exit() | |
for item in os.listdir(web_dir): | |
if os.path.isdir(os.path.join(web_dir, item)): | |
check_dir = os.path.join(web_dir, item) | |
for git_dir in os.listdir(check_dir): | |
if git_dir == '.git': | |
print("\nChecking directory: " + check_dir + "\n") | |
repo = git.Repo(check_dir) | |
print(repo.git.status()) | |
continue; | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment