Esempio n. 1
0
def setup_argument_parser():
    """Sets up teh parser with the required arguments

    :return: The parser object
    """
    default_config_path = filesystem.get_default_config_path()
    default_log_path = filesystem.get_default_log_path()

    filesystem.create_path(default_config_path)
    filesystem.create_path(default_log_path)

    parser = core_singletons.argument_parser
    parser.add_argument('-n', '--new', action='store_true', help=_("whether to create a new state-machine"))
    parser.add_argument('-o', '--open', action='store', nargs='*', type=parse_state_machine_path,
                        dest='state_machine_paths', metavar='path',
                        help=_("specify directories of state-machines that shall be opened. Paths must contain a "
                               "statemachine.json file"))
    parser.add_argument('-c', '--config', action='store', type=config_path, metavar='path', dest='config_path',
                        default=default_config_path, nargs='?', const=default_config_path,
                        help=_("path to the configuration file config.yaml. Use 'None' to prevent the generation of a "
                               "config file and use the default configuration. Default: {0}"
                               "").format(default_config_path))
    parser.add_argument('-g', '--gui_config', action='store', type=config_path, metavar='path', dest='gui_config_path',
                        default=default_config_path, nargs='?', const=default_config_path,
                        help=_("path to the configuration file gui_config.yaml. "
                               "Use 'None' to prevent the generation of a config file and use the default "
                               "configuration. Default: {0}").format(default_config_path))
    parser.add_argument('-d', '--design_config', action='store', type=config_path, metavar='path',
                        dest='design_config_path', default=None, nargs='?', const=default_config_path,
                        help=_("path to the configuration file design_config.yaml. "
                               "Use 'None' to prevent the generation of a config file and use the default "
                               "configuration. Default: {0}").format(default_config_path))
    parser.add_argument('-r', '--runtime_config', action='store', type=config_path, metavar='path', dest='runtime_config_path',
                        default=default_config_path, nargs='?', const=default_config_path,
                        help=_("path to the configuration file runtime_config.yaml. "
                               "Use 'None' to prevent the generation of a config file and use the default "
                               "configuration. Default: {0}").format(default_config_path))
    parser.add_argument('-ss', '--start_state_machine', dest='start_state_machine_flag', action='store_true',
                        help=_("a flag to specify if the first state machine of -o should be started after opening"))
    parser.add_argument('-s', '--start_state_path', metavar='path', dest='start_state_path', default=None, nargs='?',
                        help=_("path within a state machine to the state that should be launched which consists of "
                               "state ids e.g. QPOXGD/YVWJKZ where QPOXGD is the root state and YVWJKZ its child states"
                               " to start from"))
    parser.add_argument('-q', '--quit', dest='quit_flag', action='store_true',
                        help=_("a flag to specify if the gui should quit after launching a state machine"))
    parser.add_argument('-mp', '--memory-profiling', dest='memory_profiling', action='store_true',
                        help=_("a flag to specify if the gui should enable memory profiling"))
    parser.add_argument('-mpp', '--memory-profiling-path', action='store', type=config_path, metavar='path', dest='memory_profiling_path',
                        default=default_log_path, nargs='?', const=default_log_path,
                        help=_("path to the memory profiling log memoy_profiling.log").format(default_log_path))
    parser.add_argument('-mpi', '--memory-profiling-interval', dest='memory_profiling_interval', action='store', default=10,
                        help=_("The interval between snapshots creaton for memory profiling in seconds"))
    parser.add_argument('-mppr', '--memory-profiling-print', dest='memory_profiling_print', action='store_true',
                        help=_("a flag to specify if the memory profiling results should be printed"))

    return parser
Esempio n. 2
0
def setup_argument_parser():
    """Sets up teh parser with the required arguments

    :return: The parser object
    """
    default_config_path = filesystem.get_default_config_path()
    default_log_path = filesystem.get_default_log_path()

    filesystem.create_path(default_config_path)
    filesystem.create_path(default_log_path)

    parser = core_singletons.argument_parser
    parser.add_argument(
        '-o',
        '--open',
        type=parse_state_machine_path,
        dest='state_machine_path',
        metavar='path',
        nargs='+',
        help="specify directories of state-machines that shall be opened. The path must "
        "contain a statemachine.json file")
    parser.add_argument(
        '-c',
        '--config',
        type=config_path,
        metavar='path',
        dest='config_path',
        default=default_config_path,
        nargs='?',
        const=default_config_path,
        help="path to the configuration file config.yaml. Use 'None' to prevent the generation of "
        "a config file and use the default configuration. Default: {0}".format(
            default_config_path))
    parser.add_argument('-r', '--remote', action='store_true', help="remote control mode")
    parser.add_argument(
        '-s',
        '--start_state_path',
        metavar='path',
        dest='start_state_path',
        default=None,
        nargs='?',
        help="path within a state machine to the state that should be launched. The state path "
        "consists of state ids (e.g. QPOXGD/YVWJKZ whereof QPOXGD is the root state and YVWJKZ "
        "it's child state to start from).")
    parser.add_argument('-mp', '--memory-profiling', dest='memory_profiling', action='store_true',
                        help=_("a flag to specify if the gui should enable memory profiling"))
    parser.add_argument('-mpp', '--memory-profiling-path', action='store', type=config_path, metavar='path', dest='memory_profiling_path',
                        default=default_log_path, nargs='?', const=default_log_path,
                        help=_("path to the memory profiling log memoy_profiling.log").format(default_log_path))
    parser.add_argument('-mpi', '--memory-profiling-interval', dest='memory_profiling_interval', action='store', default=10,
                        help=_("The interval between snapshots creaton for memory profiling in seconds"))
    parser.add_argument('-mppr', '--memory-profiling-print', dest='memory_profiling_print', action='store_true',
                        help=_("a flag to specify if the memory profiling results should be printed"))
    return parser
Esempio n. 3
0
def setup_argument_parser():
    """Sets up teh parser with the required arguments

    :return: The parser object
    """
    default_config_path = filesystem.get_default_config_path()
    filesystem.create_path(default_config_path)

    parser = core_singletons.argument_parser
    parser.add_argument(
        '-o',
        '--open',
        type=parse_state_machine_path,
        dest='state_machine_path',
        metavar='path',
        nargs='+',
        help=
        "specify directories of state-machines that shall be opened. The path must "
        "contain a statemachine.json file")
    parser.add_argument(
        '-c',
        '--config',
        type=config_path,
        metavar='path',
        dest='config_path',
        default=default_config_path,
        nargs='?',
        const=default_config_path,
        help=
        "path to the configuration file config.yaml. Use 'None' to prevent the generation of "
        "a config file and use the default configuration. Default: {0}".format(
            default_config_path))
    parser.add_argument('-r',
                        '--remote',
                        action='store_true',
                        help="remote control mode")
    parser.add_argument(
        '-s',
        '--start_state_path',
        metavar='path',
        dest='start_state_path',
        default=None,
        nargs='?',
        help=
        "path within a state machine to the state that should be launched. The state path "
        "consists of state ids (e.g. QPOXGD/YVWJKZ whereof QPOXGD is the root state and YVWJKZ "
        "it's child state to start from).")
    return parser
    def __init__(self):

        default_config_path = filesystem.get_default_config_path()

        argument_parser.add_argument(
            '-nc',
            '--net_config',
            action='store',
            type=config_path,
            metavar='path',
            dest='net_config_path',
            default=default_config_path,
            nargs='?',
            const=default_config_path,
            help=
            "path to the configuration file net_config.yaml. Use 'None' to prevent the generation of "
            "a config file and use the default configuration. Default: {0}".
            format(default_config_path))

        self.endpoint = None
        self.endpoint_initialized = False
        self.config = None
        self.config_flag = False
Esempio n. 5
0
def convert(config_path, source_path, target_path=None, gui_config_path=None):
    logger.info("RAFCON launcher")
    rafcon.gui.start.setup_l10n(logger)
    from rafcon.gui.controllers.main_window import MainWindowController
    from rafcon.gui.views.main_window import MainWindowView

    setup_environment()

    gui_config_path = gui_config_path or get_default_config_path()

    setup_config = {}
    setup_config["config_path"] = config_path
    setup_config["gui_config_path"] = gui_config_path
    setup_config["source_path"] = [source_path]
    if not target_path:
        setup_config["target_path"] = [source_path]
    else:
        setup_config["target_path"] = [target_path]

    global_config.load(path=setup_config['config_path'])
    global_gui_config.load(path=setup_config['gui_config_path'])
    global_runtime_config.load(path=setup_config['gui_config_path'])

    # Initialize library
    core_singletons.library_manager.initialize()

    # Create the GUI
    main_window_view = MainWindowView()

    if setup_config['source_path']:
        if len(setup_config['source_path']) > 1:
            logger.error("Only one state machine is supported yet")
            exit(-1)
        for path in setup_config['source_path']:
            try:
                state_machine = gui_helper_state_machine.open_state_machine(
                    path)
            except Exception as e:
                logger.error("Could not load state machine {0}: {1}".format(
                    path, e))
    else:
        logger.error(
            "You need to specify exactly one state machine to be converted!")

    sm_manager_model = gui_singletons.state_machine_manager_model

    main_window_controller = MainWindowController(sm_manager_model,
                                                  main_window_view)

    if not os.getenv("RAFCON_START_MINIMIZED", False):
        main_window = main_window_view.get_top_widget()
        size = global_runtime_config.get_config_value("WINDOW_SIZE", None)
        position = global_runtime_config.get_config_value("WINDOW_POS", None)
        if size:
            main_window.resize(size[0], size[1])
        if position:
            position = (max(0, position[0]), max(0, position[1]))
            screen_width = Gdk.Screen.width()
            screen_height = Gdk.Screen.height()
            if position[0] < screen_width and position[1] < screen_height:
                main_window.move(position[0], position[1])

    wait_for_gui()
    thread = threading.Thread(target=trigger_gui_signals,
                              args=[
                                  sm_manager_model, main_window_controller,
                                  setup_config, state_machine
                              ])
    thread.start()

    Gtk.main()
    logger.debug("Gtk main loop exited!")
    logger.debug("Conversion done")