Skip to content

Instantly share code, notes, and snippets.

@egemenyildiz
Last active October 31, 2018 08:35
Show Gist options
  • Save egemenyildiz/1b152a6307dfc2320b358a7f31aa5841 to your computer and use it in GitHub Desktop.
Save egemenyildiz/1b152a6307dfc2320b358a7f31aa5841 to your computer and use it in GitHub Desktop.
python script to fetch/update all project files from git under a directory
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import argparse
import subprocess
def update_projects(directory):
files = os.listdir(directory)
for f in files:
new_path = os.path.join(directory, f)
if os.path.isdir(new_path):
print "Fetching {project}...".format(project=f)
files_inside = os.listdir(new_path)
if '.git' in files_inside:
run_command('cd {path} && git fetch --all && git pull'.format(path=new_path))
else:
print "\nDone!"
def run_command(command, shell=True):
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=shell)
proc_stdout = process.communicate()[0].strip()
return proc_stdout
def main():
parser = argparse.ArgumentParser()
parser.add_argument("dir", help="parent dir to update project(s)",
type=lambda s: unicode(s, 'utf8'))
args = parser.parse_args()
update_projects(args.dir)
if __name__ == '__main__':
main()
@safaktrgt
Copy link

imho, this should be named gottafetchemall.py , but idk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment