|
1 | 1 | import os |
2 | 2 | import yaml |
| 3 | +from filelock import FileLock |
3 | 4 |
|
4 | 5 | # This is a default path for localizing all the benchmark related files |
5 | 6 | libero_config_path = os.environ.get( |
@@ -52,45 +53,25 @@ def get_libero_path(query_key): |
52 | 53 |
|
53 | 54 | def set_libero_default_path(custom_location=os.path.dirname(os.path.abspath(__file__))): |
54 | 55 | print( |
55 | | - f"[Warning] You are changing the default path for Libero config. This will affect all the paths in the config file." |
| 56 | + "[Warning] You are changing the default path for Libero config. This will affect all the paths in the config file." |
56 | 57 | ) |
57 | 58 | new_config = get_default_path_dict(custom_location) |
58 | 59 | with open(config_file, "w") as f: |
59 | 60 | yaml.dump(new_config, f) |
60 | 61 |
|
61 | | - |
62 | | -if not os.path.exists(libero_config_path): |
63 | | - os.makedirs(libero_config_path) |
| 62 | +with FileLock(".config_lock"): |
| 63 | + if not os.path.exists(libero_config_path): |
| 64 | + os.makedirs(libero_config_path) |
64 | 65 |
|
65 | 66 | if not os.path.exists(config_file): |
66 | 67 | # Create a default config file |
67 | 68 |
|
68 | 69 | default_path_dict = get_default_path_dict() |
69 | | - answer = input( |
70 | | - "Do you want to specify a custom path for the dataset folder? (Y/N): " |
71 | | - ).lower() |
72 | | - if answer == "y": |
73 | | - # If the user wants to specify a custom storage path, prompt them to enter it |
74 | | - custom_dataset_path = input( |
75 | | - "Enter the path where you want to store the datasets: " |
76 | | - ) |
77 | | - full_custom_dataset_path = os.path.join( |
78 | | - os.path.abspath(os.path.expanduser(custom_dataset_path)), "datasets" |
79 | | - ) |
80 | | - # Check if the custom storage path exists, and create if it doesn't |
81 | | - |
82 | | - print("The full path of the custom storage path you entered is:") |
83 | | - print(full_custom_dataset_path) |
84 | | - print("Do you want to continue? (Y/N)") |
85 | | - confirm_answer = input().lower() |
86 | | - if confirm_answer == "y": |
87 | | - if not os.path.exists(full_custom_dataset_path): |
88 | | - os.makedirs(full_custom_dataset_path) |
89 | | - default_path_dict["datasets"] = full_custom_dataset_path |
90 | 70 | print("Initializing the default config file...") |
91 | 71 | print(f"The following information is stored in the config file: {config_file}") |
92 | 72 | # write all the paths into a yaml file |
93 | | - with open(config_file, "w") as f: |
94 | | - yaml.dump(default_path_dict, f) |
95 | | - for key, value in default_path_dict.items(): |
96 | | - print(f"{key}: {value}") |
| 73 | + with FileLock(".config_lock"): |
| 74 | + with open(config_file, "w") as f: |
| 75 | + yaml.dump(default_path_dict, f) |
| 76 | + for key, value in default_path_dict.items(): |
| 77 | + print(f"{key}: {value}") |
0 commit comments