@@ -534,13 +534,35 @@ def copy_to_output(self):
534
534
self .WORK_DIR , self .OUT_DIR )
535
535
try :
536
536
if os .path .exists (self .OUT_DIR ):
537
- if not self .overwrite :
537
+ if self .overwrite :
538
+ # if overwrite flag is true, replace OUT_DIR contents with WORK_DIR
538
539
self .obj .log .error ("%s: '%s' exists, overwriting." ,
539
540
self .obj .full_name , self .OUT_DIR )
540
- shutil .rmtree (self .OUT_DIR )
541
+ shutil .rmtree (self .OUT_DIR )
542
+ shutil .move (self .WORK_DIR , self .OUT_DIR )
543
+ return
544
+ elif not self .overwrite :
545
+ # if ovewrite flag is false, find the next suitable 'MDTF_output.v#' dir to write to
546
+ if not os .path .exists (os .path .join (self .OUT_DIR , 'index.html' )):
547
+ # this will catch the majority of cases
548
+ shutil .rmtree (self .OUT_DIR )
549
+ shutil .move (self .WORK_DIR , self .OUT_DIR )
550
+ return
551
+ # the rest of this if statement is not strictly necessary, but may be useful for fringe edge cases
552
+ # if some reason a index.html already exists in self.OUT_DIR, it will move to the next .v#
553
+ out_main_dir = os .path .abspath (os .path .join (self .OUT_DIR , ".." ))
554
+ v_dirs = [d for d in os .listdir (out_main_dir ) if 'MDTF_output.v' in d ]
555
+ if not v_dirs :
556
+ NEW_BASE = 'MDTF_output.v1'
557
+ v_nums = sorted ([int ('' .join (filter (str .isdigit , d ))) for d in v_dirs ], reverse = True )
558
+ NEW_BASE = f'MDTF_output.v{ v_nums [0 ]+ 1 } '
559
+ self .OUT_DIR = os .path .join (out_main_dir , NEW_BASE )
560
+ if os .path .isdir (self .OUT_DIR ):
561
+ shutil .rmtree (self .OUT_DIR )
562
+ shutil .move (self .WORK_DIR , self .OUT_DIR )
563
+ return
541
564
except Exception :
542
565
raise
543
- shutil .move (self .WORK_DIR , self .OUT_DIR )
544
566
545
567
def verify_pod_links (self , pod ):
546
568
"""Check for missing files linked to from POD's html page.
0 commit comments