Added remove run directory option
@@ -48,6 +48,11 @@ parser.add_argument('tasks', nargs='+')
parser.add_argument('--maxthreads', type=int, default=2,
help="Number of fpga_flow threads to run default = 2," +
"Typically <= Number of processors on the system")
+parser.add_argument('--remove_run_dir', type=str,
+ help="Remove run dir " +
+ "'all' to remove all." +
+ "<int>,<int> to remove specific run dir" +
+ "<int>-<int> To remove range of directory")
parser.add_argument('--config', help="Override default configuration")
parser.add_argument('--test_run', action="store_true",
help="Dummy run shows final generated VPR commands")
@@ -84,6 +89,8 @@ def main():
logger.info("Currently running task %s" % eachtask)
eachtask = eachtask.replace("\\", "/").split("/")
job_run_list = generate_each_task_actions(eachtask)
+ if args.remove_run_dir:
+ continue
eachtask = "_".join(eachtask)
if not args.test_run:
run_actions(job_run_list)
@@ -111,6 +118,40 @@ def validate_command_line_arguments():
logger.info("Set up to run %d Parallel threads", args.maxthreads)
+def remove_run_dir():
+ remove_dir = []
+ try:
+ argval = args.remove_run_dir.lower()
+ if argval == "all":
+ for eachRun in glob.glob("run*"):
+ remove_dir += [eachRun]
+ elif "-" in argval:
+ minval, maxval = map(int, argval.split("-"))
+ if minval > maxval:
+ raise Exception("Enter valid range to remove")
+ for eachRun in glob.glob("run*"):
+ if minval <= int(eachRun[-3:]) <= maxval:
+ remove_dir += [eachRun]
+ elif "," in argval:
+ for eachRun in argval.split(","):
+ remove_dir += ["run%03d" % int(eachRun)]
+ else:
+ logger.error("Unknow argument to --remove_run_dir")
+ except:
+ logger.exception("Failed to parse remove rund_dir options")
+
+ try:
+ for eachdir in remove_dir:
+ logger.info('Removing run_dir %s' % (eachdir))
+ if os.path.exists('latest'):
+ if eachdir == os.readlink('latest'):
+ remove_dir += ["latest"]
+ shutil.rmtree(eachdir, ignore_errors=True)
+ except:
+ logger.exception("Failed to remove %s run directory" %
+ (eachdir or "Unknown"))
+
+
def generate_each_task_actions(taskname):
"""
This script generates all the scripts required for each benchmark
@@ -130,6 +171,9 @@ def generate_each_task_actions(taskname):
# Create run directory for current task run ./runxxx
run_dirs = [int(os.path.basename(x)[-3:]) for x in glob.glob('run*[0-9]')]
curr_run_dir = "run%03d" % (max(run_dirs+[0, ])+1)
+ if args.remove_run_dir:
+ remove_run_dir()
+ return
try:
os.mkdir(curr_run_dir)
if os.path.islink('latest') or os.path.exists('latest'):
