|
1 | 1 | import json |
2 | 2 | import sys |
3 | 3 | import shutil |
4 | | -from git import Repo |
| 4 | +from git import Repo, GitCommandError |
| 5 | +import time |
5 | 6 | import os |
6 | 7 |
|
7 | 8 | print("Starting cloning setup") |
8 | 9 | try: |
9 | 10 | f = open("./config.json", "r") |
10 | 11 | config = json.load(f) |
| 12 | + RETRY_LIMIT = config["access_modules"]["RETRY_LIMIT"] |
11 | 13 | urls = config["access_modules"]["git_urls"] |
12 | 14 |
|
13 | 15 | for each_access_module in os.listdir('Access/access_modules'): |
|
33 | 35 | folder_name = url.split("/").pop()[:-4] |
34 | 36 | folder_path = "./Access/access_modules/" + folder_name |
35 | 37 | try: |
36 | | - if specified_branch: |
37 | | - Repo.clone_from(url, folder_path, branch=specified_branch) |
38 | | - else: |
39 | | - Repo.clone_from(url, folder_path) |
| 38 | + retry_exception = None |
| 39 | + for i in range(1, RETRY_LIMIT + 1): |
| 40 | + try: |
| 41 | + if specified_branch: |
| 42 | + Repo.clone_from(url, folder_path, branch=specified_branch) |
| 43 | + else: |
| 44 | + Repo.clone_from(url, folder_path) |
| 45 | + except (GitCommandError, Exception) as ex: |
| 46 | + print("error occurred: ", ex) |
| 47 | + print("retry:{1}/{2}".format(ex, i, RETRY_LIMIT)) |
| 48 | + retry_exception = ex |
| 49 | + time.sleep(10 * i) |
| 50 | + print("retrying") |
| 51 | + else: |
| 52 | + retry_exception = None |
| 53 | + break |
| 54 | + if (retry_exception != None): |
| 55 | + print("max retry count reached") |
| 56 | + raise retry_exception |
| 57 | + |
40 | 58 | # move all folders, not files in the cloned repo to the access_modules |
41 | 59 | # folder except the .git, .github and secrets folder |
42 | 60 | for file in os.listdir(folder_path): |
|
52 | 70 | ) |
53 | 71 | except: |
54 | 72 | print("File is already present.") |
55 | | - |
| 73 | + |
56 | 74 | if(file == "requirements.txt"): |
57 | 75 | current_requirements_file = folder_path + "/" + file |
58 | 76 | #Read the requirements |
|
64 | 82 |
|
65 | 83 | # Merge the requirements |
66 | 84 | merged_requirements = list(set(requirements1 + requirements2)) |
67 | | - |
| 85 | + |
68 | 86 | #update the requirements.txt |
69 | 87 | with open(requirements_file, 'w') as out_file: |
70 | 88 | for requirement in sorted(merged_requirements): |
71 | 89 | out_file.write(requirement) |
72 | | - |
| 90 | + |
73 | 91 | print("Cloning successful!") |
74 | 92 | except Exception as e: |
75 | 93 | print("error-->",e) |
|
84 | 102 | except Exception as e: |
85 | 103 | print(e) |
86 | 104 | print("failed to remove " + folder_path + " folder.") |
87 | | - |
| 105 | + |
88 | 106 | except Exception as e: |
89 | 107 | print("Access module cloning failed!") |
90 | 108 | print(str(e)) |
|
0 commit comments