def run(FileName):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.ImportTestCommand")
    plLogger.LogDebug(" FileName: " + FileName)

    stc_sys = CStcSystem.Instance()
    common_data_path = stc_sys.GetApplicationCommonDataPath()
    test_meth_dir = os.path.join(common_data_path,
                                 mgr_const.MM_TEST_METH_DIR)
    if not os.path.exists(test_meth_dir):
        plLogger.LogDebug("Adding testMeth directory: " + str(test_meth_dir))
        os.mkdir(test_meth_dir)

    # Unzip to temp directory
    nice_ts = txml_utils.get_timestamp_ymd_hms()
    temp_dir = os.path.join(test_meth_dir,
                            "temp_" + str(nice_ts))

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    with zipfile.ZipFile(FileName, "r") as z:
        z.extractall(temp_dir)

    meta_file = os.path.join(temp_dir, mgr_const.MM_TEST_CASE_SUBDIR,
                             mgr_const.MM_META_FILE_NAME)
    seq_file = os.path.join(temp_dir,
                            mgr_const.MM_SEQUENCER_FILE_NAME)

    if not os.path.isfile(meta_file):
        plLogger.LogError("Unable to extract TXML file!")
        return False
    if not os.path.isfile(seq_file):
        plLogger.LogError("Unable to extract sequencer file!")
        return False

    # Read the TXML file for the test name
    test_name = txml_utils.extract_methodology_name_from_file(meta_file)
    if not test_name:
        plLogger.LogError("ERROR: Could not extract test methodology name from the TXML file!")
        return False
    plLogger.LogDebug("test_name: " + test_name)

    if not validate_command_on_disk(seq_file):
        return False

    test_meth_test_dir = os.path.join(test_meth_dir, test_name)
    test_meth_test_case_dir = os.path.join(test_meth_test_dir,
                                           mgr_const.MM_TEST_CASE_SUBDIR)
    plLogger.LogDebug(" test_meth_test_dir: " + str(test_meth_test_dir))
    plLogger.LogDebug(" test_meth_test_case_dir: " + str(test_meth_test_case_dir))

    if not os.path.exists(test_meth_test_dir):
        os.makedirs(test_meth_test_dir)
    if not os.path.exists(test_meth_test_case_dir):
        os.makedirs(test_meth_test_case_dir)

    # FIXME:
    # Need to handle multiple copies of the TXML file
    shutil.copy(seq_file, test_meth_test_dir)
    shutil.copy(meta_file, test_meth_test_case_dir)

    # Add BLL objects
    meth_man_utils.build_test_methodology(test_meth_test_dir, use_txml=True)

    # Clean up
    # Delete the temporary directory and its contents
    os.remove(meta_file)
    os.rmdir(os.path.join(temp_dir, mgr_const.MM_TEST_CASE_SUBDIR))
    os.remove(seq_file)
    os.rmdir(temp_dir)

    plLogger.LogDebug("end.run.ImportTestCommand")
    return True
def run(StmMethodology, StmTestCase, InputJson, EnableTieCheck):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.LoadTestMethodologyCommand")
    stc_sys = CStcSystem.Instance()

    # Keep this in to prevent PEP8 errors as the ParentConfig
    # of the LoadFromXmlCommand is commented out or uncommented out.
    plLogger.LogDebug("InputJson: " + str(InputJson))
    hnd_reg = CHandleRegistry.Instance()
    ctor = CScriptableCreator()

    # validate() already checks the existence of StmMethodology and StmTestCase
    # No need to do the checking again here
    stm_meth = meth_man_utils.get_stm_methodology_from_handle(StmMethodology)
    plLogger.LogDebug("stm_meth: " + stm_meth.Get("TestMethodologyName"))
    test_meth_path = stm_meth.Get("Path")
    plLogger.LogDebug("test_meth_path: " + str(test_meth_path))

    stm_test_case = None

    # If NO StmTestCase is provided, then assume it's the "original"
    if StmTestCase == 0:
        plLogger.LogDebug("stm_test_case: original")
        test_case_path = test_meth_path
    else:
        hnd_reg = CHandleRegistry.Instance()
        stm_test_case = hnd_reg.Find(StmTestCase)
        plLogger.LogDebug("stm_test_case: " + stm_test_case.Get("TestCaseName"))
        test_case_path = stm_test_case.Get("Path")
        if EnableTieCheck:
            # In the worst case, a profile test won't fit.  If the test isn't
            # profile based, we currently have no way of determining if it will
            # run successfully or not.
            can_run = check_tie_for_profile_based_test(InputJson, stm_test_case)

    plLogger.LogDebug("test_case_path: " + str(test_case_path))

    if not validate_command_on_disk(os.path.join(test_case_path,
                                                 mgr_const.
                                                 MM_SEQUENCER_FILE_NAME)):
        plLogger.LogError("validate_command_on_disk failed for: " +
                          test_meth_path + "/" +
                          mgr_const.MM_SEQUENCER_FILE_NAME)
        return False

    # Non profile-based tests can always run....  This is kind of a
    # strange check until we figure out how to validate non
    # profile-based tests.
    can_run = True

    # Load
    if can_run:
        loadCmd = ctor.CreateCommand("LoadFromXml")
        loadCmd.Set("FileName",
                    os.path.join(test_case_path,
                                 mgr_const.MM_SEQUENCER_FILE_NAME))
        # FIXME !!!!!!
        # If the ParentConfig is set to empty string (""), then the GUI works and TCL crashes.
        # If the ParentConfig is set to project, then the GUI crashes and TCL works
        # loadCmd.Set("ParentConfig", project.GetObjectHandle())
        loadCmd.Execute()
        if StmTestCase == 0:
            # Can only do this if we're loading a real test case, not the original
            meth_man_utils.set_active_test_case(stm_test_case)
    else:
        # FIXME:
        # We obviously need more information here.
        plLogger.LogError("ERROR: Can not load Test Methodology")
        return False

    # Process the ports (now that the config is loaded)
    # Break the JSON into ports and params sections
    ports_json = None
    params_json = None
    portgroups_json = None
    if InputJson != "":
        input_json = json.loads(InputJson)
        if "portgroups" in input_json.keys():
            portgroups_json = input_json["portgroups"]
        if "params" in input_json.keys():
            params_json = input_json["params"]

    plLogger.LogDebug("calling relocate and bring ports online")

    # Relocate and bring ports online as necessary
    if portgroups_json is not None:
        process_portgroups(portgroups_json)
    else:
        process_ports(ports_json)

    if params_json is not None:
        plLogger.LogDebug("params_json: " + json.dumps(params_json))

        # Fill in the input JSON if it exists
        sequencer = stc_sys.GetObject("Sequencer")
        cmd_list = sequencer.GetCollection("CommandList")
        for cmd_hnd in cmd_list:
            cmd = hnd_reg.Find(cmd_hnd)
            if cmd is None:
                continue
            if cmd.IsTypeOf("spirent.methodology.manager.MethodologyGroupCommand"):
                cmd.Set("InputJson", json.dumps(params_json))
                break

    plLogger.LogDebug("end.run.LoadTestMethodologyCommand")
    return True