Created
January 16, 2020 21:09
-
-
Save fkirc/2e7dfdf3a82e1d62880a829e24966fd2 to your computer and use it in GitHub Desktop.
Small Python template for shell operations
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
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