Skip to content

Instantly share code, notes, and snippets.

@fkirc
Created January 16, 2020 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fkirc/2e7dfdf3a82e1d62880a829e24966fd2 to your computer and use it in GitHub Desktop.
Save fkirc/2e7dfdf3a82e1d62880a829e24966fd2 to your computer and use it in GitHub Desktop.
Small Python template for shell operations
import os
import subprocess
def sh(cmd):
print('sh: ' + cmd)
ret = subprocess.run(cmd, shell=True, env=os.environ, executable='/bin/bash')
if ret.returncode != 0:
exit(ret.returncode)
def is_git_repo(dir):
return os.path.exists(os.path.join(dir, '.git'))
def checkout_repo(dir):
sh('cd \'' + dir + '\' && git fetch origin')
def main():
for inode in os.listdir('.'):
if os.path.isfile(inode):
continue
if not is_git_repo(dir=inode):
continue
checkout_repo(dir=inode)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment