-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-check_pypicongpuJSON_directory_name.py
More file actions
35 lines (27 loc) · 1.5 KB
/
3-check_pypicongpuJSON_directory_name.py
File metadata and controls
35 lines (27 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# this python code checks if the directory containing the pypicongpu.json file is presents and if yes removes it before running the simulation as it is a prerequisite for PIConGPU simulation.
import os
import sys
def check_command(message):
print(f"SUCCESS: {message}")
def main():
# Ensure the correct number of arguments are provided
if len(sys.argv) != 3:
print("Error: Please provide both the simulation directory and the pypicongpu JSON directory name.")
sys.exit(1)
# Read the command-line arguments (the directory and JSON directory name)
simulation_directory = sys.argv[1] # First argument is the simulation directory
pypicongpuJSON_directory_name = sys.argv[2] # Second argument is the pypicongpu JSON directory name
# Full path to the pypicongpu JSON directory
pypicongpuJSON_directory_path = os.path.join(simulation_directory, pypicongpuJSON_directory_name)
# Check if the directory exists and remove it if needed
if os.path.exists(pypicongpuJSON_directory_path):
print(f"Removing existing output directory: {pypicongpuJSON_directory_path}")
try:
os.system(f"rm -rf {pypicongpuJSON_directory_path}")
check_command("Removing existing output directory")
except Exception as e:
print(f"ERROR: Failed to remove the directory. {e}")
else:
print(f"Directory {pypicongpuJSON_directory_name} does not exist. Proceeding...")
if __name__ == "__main__":
main()