Skip to content

Commit

Permalink
Move parsers into __main__
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Jun 16, 2023
1 parent 7a49078 commit c79d121
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 53 deletions.
75 changes: 36 additions & 39 deletions src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup
from mx_bluesky.I24.serial.write_nexus import call_nexgen

usage = "%(prog)s command [options]"
logger = logging.getLogger("I24ssx.extruder")


Expand All @@ -34,7 +35,7 @@ def flush_print(text):
sys.stdout.flush()


def initialise_extruderi24():
def initialise_extruderi24(args):
name = inspect.stack()[0][3]
print("Initialise Parameters for extruder data collection")
logger.info("%s I24 extruder initialisation" % name)
Expand All @@ -59,7 +60,8 @@ def initialise_extruderi24():
logger.info("%s Initialsation complete" % name)


def moveto(place):
def moveto(args):
place = args.place
name = inspect.stack()[0][3]
logger.info("%s Move to %s" % (name, place))

Expand Down Expand Up @@ -200,7 +202,7 @@ def scrape_parameter_file(param_path: Path | str = PARAM_FILE_PATH):
)


def run_extruderi24():
def run_extruderi24(args):
print("Starting i24")
name = inspect.stack()[0][3]
logger.info("%s" % name)
Expand Down Expand Up @@ -445,42 +447,37 @@ def run_extruderi24():
return 1


usage = "%(prog)s command [options]"
parser = argparse.ArgumentParser(usage=usage, description=__doc__)
subparsers = parser.add_subparsers(
help="Choose command.",
required=True,
dest="sub-command",
)

parser_init = subparsers.add_parser(
"initialise",
description="Initialise extruder on beamline I24.",
)
parser_init.set_defaults(func=initialise_extruderi24)
parser_run = subparsers.add_parser(
"run",
description="Run extruder on I24.",
)
parser_run.set_defaults(func=run_extruderi24)
parser_mv = subparsers.add_parser(
"moveto",
description="Move extruder to requested setting on I24.",
)
parser_mv.add_argument(
"place",
type=str,
choices=["laseron", "laseroff", "enterhutch"],
help="Requested setting.",
)
parser_mv.set_defaults(func=moveto)


def main():
if __name__ == "__main__":
setup_logging()
args = parser.parse_args()
args.func(args)

parser = argparse.ArgumentParser(usage=usage, description=__doc__)
subparsers = parser.add_subparsers(
help="Choose command.",
required=True,
dest="sub-command",
)

if __name__ == "__main__":
main()
parser_init = subparsers.add_parser(
"initialise",
description="Initialise extruder on beamline I24.",
)
parser_init.set_defaults(func=initialise_extruderi24)
parser_run = subparsers.add_parser(
"run",
description="Run extruder on I24.",
)
parser_run.set_defaults(func=run_extruderi24)
parser_mv = subparsers.add_parser(
"moveto",
description="Move extruder to requested setting on I24.",
)
parser_mv.add_argument(
"place",
type=str,
choices=["laseron", "laseroff", "enterhutch"],
help="Requested setting.",
)
parser_mv.set_defaults(func=moveto)

args = parser.parse_args()
args.func(args)
29 changes: 15 additions & 14 deletions src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
logger = logging.getLogger("I24ssx.fixed_target")

usage = "%(prog)s [options]"
parser = argparse.ArgumentParser(usage=usage, description=__doc__)
parser.add_argument(
"-l",
"--loc",
type=str,
choices=["i24", "SACLA"],
default="i24",
help="Location of collection.",
)


def setup_logging():
Expand Down Expand Up @@ -693,10 +684,7 @@ def finish_sacla():
return end_time


def main():
setup_logging()
args = parser.parse_args()

def main(args):
location = args.loc
print("Location is", location, "Starting")
# ABORT BUTTON
Expand Down Expand Up @@ -895,4 +883,17 @@ def main():


if __name__ == "__main__":
main()
setup_logging()

parser = argparse.ArgumentParser(usage=usage, description=__doc__)
parser.add_argument(
"-l",
"--loc",
type=str,
choices=["i24", "SACLA"],
default="i24",
help="Location of collection.",
)

args = parser.parse_args()
main(args)

0 comments on commit c79d121

Please sign in to comment.