Last active
July 16, 2021 11:37
-
-
Save debajyoti-thetaonelab/aa2cd2b3b8fa527f5ff901ca3ac1db90 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sys | |
| import os | |
| import subprocess | |
| GIT_ROOT=os.getenv('GIT_ROOT') or '/Users/earthdan/dev/' | |
| if __name__ == '__main__': | |
| cloneURL = sys.argv[1] | |
| if cloneURL.startswith('git+'): | |
| cloneURL = cloneURL[len('git+'):] | |
| try: | |
| print('Cloning', cloneURL) | |
| dirParts = [] | |
| repoName = '' | |
| if '@' in cloneURL and ':' in cloneURL: | |
| atIndex = cloneURL.index('@') | |
| dirParts = cloneURL[atIndex+1:].split(':') | |
| _part = [] | |
| for p in dirParts: | |
| _t = [_p for _p in p.split('/') if len(_p) > 0] | |
| _part.extend(_t) | |
| dirParts = _part[:-1] | |
| repoName = _part[-1] | |
| else: | |
| if not cloneURL.startswith('http'): | |
| cloneURL = 'https://' + cloneURL | |
| dirParts = [part for part in cloneURL.split('/') if len(part) > 0][1:] | |
| repoName = dirParts[-1] | |
| dirParts = dirParts[:-1] | |
| for i in range(len(dirParts)): | |
| dirP = dirParts[i] | |
| if dirP == 'Thetaonelab': | |
| dirParts[i] = dirP.lower() | |
| # repoName = repoName[:repoName.lindex('.')] if '.' in repoName else repoName | |
| path = os.path.join(GIT_ROOT, *dirParts) | |
| repoPath = os.path.join(path, repoName) | |
| os.makedirs(path, exist_ok=True) | |
| os.chdir(path) | |
| print('to ', repoPath) | |
| subprocess.run('git clone ' + cloneURL, shell=True) | |
| except KeyboardInterrupt: | |
| pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment