|
8 | 8 | f = open("./config.json", "r")
|
9 | 9 | config = json.load(f)
|
10 | 10 | urls = config["access_modules"]["git_urls"]
|
| 11 | + |
| 12 | + requirements_file = 'Access/access_modules/requirements.txt' |
| 13 | + if not os.path.exists(requirements_file): |
| 14 | + open(requirements_file, 'w').close() |
| 15 | + |
11 | 16 | for url in urls:
|
12 | 17 | folder_name = url.split("/").pop()[:-4]
|
13 | 18 | folder_path = "./Access/access_modules/" + folder_name
|
14 | 19 | try:
|
15 |
| - if os.path.exists(folder_path): |
16 |
| - Repo(folder_path).remotes.origin.pull() |
17 |
| - else: |
18 |
| - Repo.clone_from(url, folder_path) |
19 |
| - # move all folders, not files in the cloned repo to the access_modules |
20 |
| - # folder except the .git, .github and secrets folder |
21 |
| - for file in os.listdir(folder_path): |
22 |
| - if ( |
| 20 | + Repo.clone_from(url, folder_path) |
| 21 | + # move all folders, not files in the cloned repo to the access_modules |
| 22 | + # folder except the .git, .github and secrets folder |
| 23 | + for file in os.listdir(folder_path): |
| 24 | + if ( |
23 | 25 | os.path.isdir(folder_path + "/" + file)
|
24 | 26 | and file != ".git"
|
25 | 27 | and file != ".github"
|
26 | 28 | and file != "secrets"
|
27 |
| - ): |
| 29 | + ) : |
| 30 | + try : |
28 | 31 | os.rename(
|
29 | 32 | folder_path + "/" + file, "./Access/access_modules/" + file
|
30 | 33 | )
|
| 34 | + except: |
| 35 | + print("File is already present.") |
| 36 | + |
| 37 | + if(file == "requirements.txt"): |
| 38 | + current_requirements_file = folder_path + "/" + file |
| 39 | + #Read the requirements |
| 40 | + with open(requirements_file, 'r') as f1: |
| 41 | + requirements1 = f1.readlines() |
31 | 42 |
|
32 |
| - # remove the cloned repo folder entirely with all its contents which |
33 |
| - # includes folders and files using shutil.rmtree() |
34 |
| - # shutil.rmtree() sometimes throws an error on windows, |
35 |
| - # so we use try and except to ignore the error |
36 |
| - try: |
37 |
| - shutil.rmtree(folder_path) |
38 |
| - except Exception as e: |
39 |
| - print(e) |
40 |
| - print("failed to remove " + folder_path + " folder.") |
| 43 | + with open(current_requirements_file, 'r') as f1: |
| 44 | + requirements2 = f1.readlines() |
41 | 45 |
|
| 46 | + # Merge the requirements |
| 47 | + merged_requirements = list(set(requirements1 + requirements2)) |
| 48 | + |
| 49 | + #update the requirements.txt |
| 50 | + with open(requirements_file, 'w') as out_file: |
| 51 | + for requirement in sorted(merged_requirements): |
| 52 | + out_file.write(requirement) |
| 53 | + |
42 | 54 | print("Cloning successful!")
|
| 55 | + except Exception as e: |
| 56 | + print("error-->",e) |
| 57 | + print("failed cloning " + folder_name + ".") |
43 | 58 |
|
| 59 | + # remove the cloned repo folder entirely with all its contents which |
| 60 | + # includes folders and files using shutil.rmtree() |
| 61 | + # shutil.rmtree() sometimes throws an error on windows, |
| 62 | + # so we use try and except to ignore the error |
| 63 | + try: |
| 64 | + shutil.rmtree(folder_path) |
44 | 65 | except Exception as e:
|
45 | 66 | print(e)
|
46 |
| - print("failed cloning " + folder_name + ".") |
| 67 | + print("failed to remove " + folder_path + " folder.") |
| 68 | + |
47 | 69 | except Exception as e:
|
48 | 70 | print("Access module cloning failed!")
|
49 | 71 | print(str(e))
|
|
0 commit comments