|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import pathlib |
| 4 | +import argparse |
| 5 | + |
| 6 | +from .parse_config import parse_project, parse_machine |
| 7 | +from .utils import check_minimum_python_version, GoodFormatter |
| 8 | + |
| 9 | +check_minimum_python_version(3, 4) |
| 10 | + |
| 11 | +############################################################################### |
| 12 | +def print_mach_env(): |
| 13 | +############################################################################### |
| 14 | + from . import __version__ # Import __version__ here to avoid circular import |
| 15 | + |
| 16 | + args = vars(parse_command_line(sys.argv, __doc__, __version__)) |
| 17 | + |
| 18 | + project = parse_project(args['config_file'],args['root_dir']) |
| 19 | + machine = parse_machine(args['config_file'],project,args['machine_name']) |
| 20 | + |
| 21 | + print(" && ".join(machine.env_setup)) |
| 22 | + |
| 23 | + sys.exit(0) |
| 24 | + |
| 25 | +############################################################################### |
| 26 | +def parse_command_line(args, description, version): |
| 27 | +############################################################################### |
| 28 | + parser = argparse.ArgumentParser( |
| 29 | + usage="""\n{0} <ARGS> [--verbose] |
| 30 | +OR |
| 31 | +{0} --help |
| 32 | +
|
| 33 | +\033[1mEXAMPLES:\033[0m |
| 34 | + \033[1;32m# Get the env setup command for machine 'foo' using config file my_config.yaml \033[0m |
| 35 | + > ./{0} foo -f my_config.yaml |
| 36 | +""".format(pathlib.Path(args[0]).name), |
| 37 | + description=description, |
| 38 | + formatter_class=GoodFormatter |
| 39 | + ) |
| 40 | + |
| 41 | + parser.add_argument("-f","--config-file", default=f"{os.getcwd()}/cacts.yaml", |
| 42 | + help="YAML file containing valid project/machine settings") |
| 43 | + |
| 44 | + parser.add_argument("-r", "--root-dir", default=f"{os.getcwd()}", |
| 45 | + help="The root directory of the project, where the main CMakeLists.txt file is located") |
| 46 | + |
| 47 | + parser.add_argument("machine_name", help="The machine name for which you want the scream env") |
| 48 | + |
| 49 | + return parser.parse_args(args[1:]) |
0 commit comments