예제 #1
0
def parse_sessions(cp_file, tools):
    """
    :param cp_file:
    :param tools:
    -> Parse all sessions in the 'control_panel.xml' file given.
    -> Except an incorrect XML format and raise ERROR.
    """
    sessions = {}
    try:
        cp_tree = Et.parse(cp_file)
        sessions_tags = cp_tree.findall(SESSION_TAG_REF)
        for session_tag in sessions_tags:
            session_name = session_tag.get(NAME_REF)
            session_programs = {}
            for program_tag in session_tag:
                program_name = program_tag.get(NAME_REF)
                command = tools[program_name].command
                options = []
                for option_tag in program_tag:
                    option = parse_arg_option(option_tag)
                    options.append(option)
                program_object = db.Program(program_name, command, options)
                session_programs[program_name] = program_object
            session_object = db.Session(session_name, session_programs)
            sessions[session_name] = session_object

    except Et.ParseError as msg:
        LOGGER.error(
            "ERROR in syntax of XML file : '%s'. "
            "Original message : '%s'.", cp_file, msg)
    return sessions
예제 #2
0
def parse_tools(cp_file):
    """
    :param cp_file:
    -> Parse all tools in the 'control_panel' file given.
    -> Except an incorrect XML format and raise ERROR.
    """
    tools = {}
    try:
        cp_tree = Et.parse(cp_file)
        tools_tags = cp_tree.findall(PROGRAM_TAG_REF)
        for tool_tag in tools_tags:
            tool_name = tool_tag.get(NAME_REF)
            tool_command = tool_tag.get(COMMAND_REF)
            options = []
            for option_tag in tool_tag:
                option = parse_arg_option(option_tag)
                options.append(option)
            tool_object = db.Program(tool_name, tool_command, options)
            tools[tool_name] = tool_object

    except Et.ParseError as msg:
        LOGGER.error(
            "ERROR in syntax of XML file : '%s'. "
            "Original message : '%s'.", cp_file, msg)
    return tools
예제 #3
0
def parse_tools(tools_path):
    """
    :param tools_path:
    -> Parse all tools files in the 'tools_path' directory.
    -> Except an incorrect XML format and raise ERROR.
    """
    tools = {}
    blacklisted_tools = []
    blacklist = tools_path + "/" + "blacklisted"
    if os.path.exists(blacklist):
        with open(blacklist, 'r') as blacklist_fic:
            for line in blacklist_fic:
                line = line.strip()
                if line != "" and line[0] != "#":
                    blacklisted_tools.append(line)

    for file in os.listdir(tools_path):
        if file.endswith(".xml"):
            file_path = tools_path + "/" + file
            try:
                tree = Et.parse(file_path)
                tool_tag = tree.getroot()
                if tool_tag.tag == PROGRAM_REF:
                    tool_name = tool_tag.get(NAME_REF)
                    tool_command = tool_tag.get(COMMAND_REF)
                    icon = tool_tag.get(ICON_REF)
                    fav = tool_tag.get(FAVORITE_REF)
                    favorite = fav if fav is None else (fav
                                                        not in STRINGS_FALSE)

                    options = []
                    for option_tag in tool_tag:
                        option = parse_arg_option(option_tag)
                        options.append(option)
                    blacklisted = True if tool_name in blacklisted_tools else False
                    tool_object = db.Program(tool_name,
                                             tool_command,
                                             options,
                                             icon,
                                             favorite=favorite,
                                             blacklisted=blacklisted)
                    tools[tool_name] = tool_object

            except Et.ParseError as msg:
                LOGGER.error(
                    "ERROR in syntax of XML file : '%s'. "
                    "Original message : '%s'.", file, msg)
    return tools
예제 #4
0
OPTION_REF = "arg"

SESSION_TAG_REF = "/".join((SECTION_REF, SESSION_REF))

CONTROL_PANEL_STRUCTURE = [(CONTROL_PANEL, [NAME_REF], [
    (SECTION_REF, [NAME_REF], [(PROGRAM_REF, [NAME_REF, COMMAND_REF], [
        (OPTION_REF, [FLAG_REF, CONSTANT_REF], [])
    ])]),
    (SECTION_REF, [NAME_REF], [(SESSION_REF, [NAME_REF], [
        (PROGRAM_REF, [NAME_REF], [(OPTION_REF, [FLAG_REF, CONSTANT_REF], [])])
    ])])
])]

# DEFAULT SESSIONS :
SIMULATOR_OBJECT = db.Program("Simulator", "sw/simulator/pprzsim-launch",
                              [("-a", "@AIRCRAFT"),
                               ("-t", "@TARGET"), "--boot", "--norc"])
GCS_OBJECT = db.Program("GCS", "sw/ground_segment/cockpit/gcs", [])
SERVER_OBJECT = db.Program("Server", "sw/ground_segment/tmtc/server", ["-n"])
PLAYER_OBJECT = db.Program("Log File Player", "sw/logalizer/play", [])

SIMULATION_NAME = "Simulation"
SIMULATION_SESSION = db.Session(
    SIMULATION_NAME, {
        SIMULATOR_OBJECT.name: SIMULATOR_OBJECT,
        GCS_OBJECT.name: GCS_OBJECT,
        SERVER_OBJECT.name: SERVER_OBJECT
    })
SESSIONS_COMBO_SEP = " - - - - - - - - - - "
REPLAY_NAME = "Replay"
REPLAY_SESSION = db.Session(