1
+ import os
2
+ import subprocess
3
+
4
+ # Get the current working directory
5
+ cwd = os .getcwd ()
6
+
7
+ # Function to check if a directory contains any .out file
8
+ def has_out_file (dir_path ):
9
+ for file in os .listdir (dir_path ):
10
+ if file .endswith ('.out' ):
11
+ return True
12
+ return False
13
+
14
+ # Iterate over all items in the cwd
15
+ for item in os .listdir (cwd ):
16
+ item_path = os .path .join (cwd , item )
17
+
18
+ # Check if it's a directory and not "1_cluster"
19
+ if os .path .isdir (item_path ) and item != "1_cluster" :
20
+ # Path to 2_analysis
21
+ analysis_dir = os .path .join (item_path , "2_analysis" )
22
+
23
+ # Check if 2_analysis exists
24
+ if os .path .exists (analysis_dir ) and os .path .isdir (analysis_dir ):
25
+ # Path to 1_cluster inside 2_analysis
26
+ cluster_dir = os .path .join (analysis_dir , "1_cluster" )
27
+
28
+ # Check if 1_cluster exists
29
+ if os .path .exists (cluster_dir ) and os .path .isdir (cluster_dir ):
30
+ # Iterate over subdirectories in 1_cluster
31
+ for sub_item in os .listdir (cluster_dir ):
32
+ sub_item_path = os .path .join (cluster_dir , sub_item )
33
+
34
+ # Check if it's a directory
35
+ if os .path .isdir (sub_item_path ):
36
+ # Path to cluster.sh
37
+ sh_file = os .path .join (sub_item_path , "cluster.sh" )
38
+
39
+ # Check if cluster.sh exists
40
+ if os .path .exists (sh_file ):
41
+ # Check for .out files
42
+ if has_out_file (sub_item_path ):
43
+ # Prompt user
44
+ response = input (f"Job might be running in { sub_item_path } . Resubmit? (y/N): " ).strip ().lower ()
45
+ if response != 'y' :
46
+ print (f"Skipping resubmission for { sub_item_path } " )
47
+ continue
48
+
49
+ # Submit the job
50
+ try :
51
+ result = subprocess .run (['sbatch' , sh_file ], capture_output = True , text = True , cwd = sub_item_path )
52
+ if result .returncode == 0 :
53
+ print (f"Submitted job for { sub_item_path } : { result .stdout .strip ()} " )
54
+ else :
55
+ print (f"Error submitting job for { sub_item_path } : { result .stderr .strip ()} " )
56
+ except Exception as e :
57
+ print (f"Exception submitting job for { sub_item_path } : { str (e )} " )
58
+ else :
59
+ print (f"cluster.sh not found in { sub_item_path } " )
60
+ else :
61
+ print (f"1_cluster not found in { analysis_dir } " )
62
+ else :
63
+ print (f"2_analysis not found in { item_path } " )
0 commit comments