Skip to content

Commit

Permalink
Adding basic argument parsing to start script
Browse files Browse the repository at this point in the history
  • Loading branch information
grf14003 committed Feb 18, 2020
1 parent f39005f commit f34a53c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
12 changes: 0 additions & 12 deletions bfs/scripts/log.txt

This file was deleted.

56 changes: 50 additions & 6 deletions bfs/scripts/startbfs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

import os
import multiprocessing as mp
import argparse
import subprocess
import multiprocessing as mp

os.chdir(os.path.dirname(__file__))


def start_program(program):
if not isinstance(program, str):
raise ValueError("Argument passed to start_program_sync() should be a string")
return os.system("cmd /c " + program)
return os.system("START /wait \""+ program +"\" CMD /c " + program)


def start_program_async(program):
Expand All @@ -19,11 +22,52 @@ def start_program_async(program):
return p


def flatten_list(lst):
flat = []
for l in lst:
if isinstance(l, list):
flat.extend(flatten_list(l))
else:
flat.append(l)
return flat


def get_exe_names(algo_args, io_proc_args, config_file):
names = []

if algo_args is not None:
names.append(algo_args)

if io_proc_args is not None:
names.extend(flatten_list(io_proc_args))

return names


def main():
a = start_program_async("..\\bin\\AlgoBreadcrumbs.exe")
io = start_program_async("..\\bin\\VirtualOutputIOProcessor.exe")
a.join()
io.join()
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--algorithm", default=None,
help="""Specify the name of the algorithm .exe file to run in a separate process. Specifying
an algorithm like this eliminates the ability for the user to specify a specify configuration for this algorithm.
the created algorithm process will use the configuration file located in it's default config directory.""")
parser.add_argument("-p", "--io_processor", action='append', nargs='+', default=None,
help="""Specify the name of the IO Processor .exe file to run in a separate process. Specifying
an IO Processor like this eliminates the ability for the user to specify a specify configuration for this IO Processor.
the created IO Processor process will use the configuration file located in it's default config directory.""")
parser.add_argument("-c", "--config", default=None,
help="""Specify the configuration file to use. This can specify the algorithm and IO
processors to run. It can also specify settings for the individual IO Processors and algorithm themselves. The
config file will be divided up into smaller config files (one for each process run) that the respective processes
will read and adjust their settings accordingly. That way, each process only has access to their own config settings.
Note: this can be used in conjunction with -a and -p, but care is necessary to not produce any duplicate proceses.""")
args = parser.parse_args()

binary_path = os.path.abspath("..\\bin")
exe_ending = ".exe"
exe_names = get_exe_names(args.algorithm, args.io_processor, args.config)
procs = [start_program_async(os.path.join(binary_path, x) + exe_ending) for x in exe_names]
[proc.join() for proc in procs]

print("DONE")


Expand Down

0 comments on commit f34a53c

Please sign in to comment.