Created
December 18, 2020 10:21
-
-
Save dgrant/dcaf944813e8dc4bcea5fef761c5f4aa to your computer and use it in GitHub Desktop.
Run `mr register` on all git folders
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 argparse | |
import os | |
import subprocess | |
def mr_register(root): | |
dirs = os.listdir(root) | |
for _dir in dirs: | |
if not os.path.isdir(_dir): | |
continue | |
os.chdir(_dir) | |
try: | |
print('registering', _dir) | |
process = subprocess.run(['mr', 'register'], capture_output=True) | |
if process.returncode == 2 and process.stderr.decode().strip() == 'mr register: unknown repository type': | |
continue | |
elif process.returncode != 0: | |
raise Exception('process failed, process:', process) | |
finally: | |
os.chdir('..') | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--dir', default='.', help='the directory to register all sub-directories in mr') | |
args = parser.parse_args() | |
mr_register(args.dir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment