Exemplo n.º 1
0
 def __str__(self):
     """
     """
     ascii_command = FRAMES.keys()[FRAMES.values().index(type(self))] + '\n'
     ascii_headers = ''
     ascii_msg = ''
     for k, v in self.headers.iteritems():
         ascii_headers += replace_all(ESCAPE, str(k)) + ':' + replace_all(
             ESCAPE, str(v)) + '\n'
     ascii_headers += '\n'
     if self.msg is not None:
         ascii_msg = self.msg
     ascii_frame = ascii_command + ascii_headers + ascii_msg + (
         NULL if NULL not in ascii_msg else '')
     return ascii_frame
Exemplo n.º 2
0
def load_native(config: Mapping[str, Any]) -> None:
    runtime_exe_path = build_runtime(config, "exe")
    data_path = pathify(config["data"], root_dir, cache_path, True, True)
    demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True)
    plugin_paths = threading_map(
        lambda plugin_config: build_one_plugin(config, plugin_config),
        [
            plugin_config
            for plugin_group in config["plugin_groups"]
            for plugin_config in plugin_group["plugin_group"]
        ],
        desc="Building plugins",
    )
    command_str = config["loader"].get("command", "%a")
    main_cmd_lst = [str(runtime_exe_path), *map(str, plugin_paths)]
    command_lst_sbst = list(
        flatten1(
            replace_all(
                unflatten(shlex.split(command_str)),
                {("%a",): main_cmd_lst, ("%b",): [shlex.quote(shlex.join(main_cmd_lst))]},
            )
        )
    )
    subprocess_run(
        command_lst_sbst,
        env_override=dict(ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path)),
    )
Exemplo n.º 3
0
def HtmlValueToWorkbook(f_path, output_ws, col_range, row_range):
    result = None

    htmlFile = codecs.open(f_path, 'r', 'utf-8')
    document = bs(htmlFile.read(), features='lxml')
    tds = document.find_all('td', {'class':'style10'})

    # Html 루프를 돌면서 정보를 옮기기 위한 변수들
    tds_index = 0
    rep = {' ' : '', '원' : '', ',' : ''}

    for x in range(row_range[0], row_range[1]):
        row_index = str(x)
        for y in range(util.string_colnum(col_range[0]), util.string_colnum(col_range[1])):
            col_index = util.colnum_string(y)

            value = tds[tds_index].text

            # 숫자 문자열은 int로 변환
            if value.isdecimal():
                value = int(value)
            # '원' 이 포함된 돈관련 숫자를 int로 변환
            elif '원' in value:     
                value = int(util.replace_all(value, rep))

            output_ws[col_index + row_index] = value
            tds_index += 1
    result = output_ws
    
    return result
Exemplo n.º 4
0
def load_native(config: Mapping[str, Any]) -> None:
    runtime_exe_path = build_runtime(config, "exe")
    data_path = pathify(config["data"], root_dir, cache_path, True, True)
    demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True)
    enable_offload_flag = config["enable_offload"]
    enable_alignment_flag = config["enable_alignment"]
    realsense_cam_string = config["realsense_cam"]
    plugin_paths = threading_map(
        lambda plugin_config: build_one_plugin(config, plugin_config),
        [plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"]],
        desc="Building plugins",
    )
    actual_cmd_str = config["action"].get("command", "$cmd")
    illixr_cmd_list = [str(runtime_exe_path), *map(str, plugin_paths)]
    env_override = dict(
        ILLIXR_DATA=str(data_path),
        ILLIXR_DEMO_DATA=str(demo_data_path),
        ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag),
        ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag),
        ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]),
        ILLIXR_RUN_DURATION=str(config["action"].get("ILLIXR_RUN_DURATION", 60)),
        ILLIXR_ENABLE_PRE_SLEEP=str(config["enable_pre_sleep"]),
        KIMERA_ROOT=config["action"]["kimera_path"],
        AUDIO_ROOT=config["action"]["audio_path"],
        REALSENSE_CAM=str(realsense_cam_string),
    )
    env_list = [f"{shlex.quote(var)}={shlex.quote(val)}" for var, val in env_override.items()]
    actual_cmd_list = list(
        flatten1(
            replace_all(
                unflatten(shlex.split(actual_cmd_str)),
                {
                    ("$env_cmd",): [
                        "env",
                        "-C",
                        Path(".").resolve(),
                        *env_list,
                        *illixr_cmd_list,
                    ],
                    ("$cmd",): illixr_cmd_list,
                    ("$quoted_cmd",): [shlex.quote(shlex.join(illixr_cmd_list))],
                    ("$env",): env_list,
                },
            )
        )
    )
    log_stdout_str = config["action"].get("log_stdout", None)
    log_stdout_ctx = cast(
        ContextManager[Optional[BinaryIO]],
        (open(log_stdout_str, "wb") if (log_stdout_str is not None) else noop_context(None)),
    )
    with log_stdout_ctx as log_stdout:
        subprocess_run(
            actual_cmd_list,
            env_override=env_override,
            stdout=log_stdout,
            check=True,
        )
Exemplo n.º 5
0
def run(command):
    if util.valid_ip():
        result_success = subprocess.check_output([command],
                                                 stderr=subprocess.STDOUT,
                                                 shell=True,
                                                 universal_newlines=True)
        return util.replace_all(result_success, util.get_replace_dic())
    else:
        return message.error_404_msg
Exemplo n.º 6
0
 def preprocess_para_texts(self, para_texts):
     """Run a list of paragraphs through preprocess.
     """
     # Temporarily intersperse an XML tag <SKIP/> between
     # paragraphs so that we can use just one call to preprocess,
     # but still have them split at the right points.
     replacements = [("<", "&lt;"),
                     (">", "&gt;"),
                     ('\n', ' '),]
     sanitized = (util.replace_all(replacements, p)
                  for p in para_texts)
     return self.ext_preprocess("\n<SKIP/>".join(sanitized)).split("<SKIP/>")
Exemplo n.º 7
0
def run_async(command, exec_time_in_seconds):
    if util.valid_ip():
        try:
            temp_out_file_name = tempfile.NamedTemporaryFile().name
            with open(temp_out_file_name, "w") as fout:
                proc = subprocess.Popen(command, shell=True, stdout=fout)
                # wait for a few seconds
                time.sleep(exec_time_in_seconds)
                # stop the process
                proc.kill()

            # read contents of the file
            with open(temp_out_file_name, "rb") as fin:
                output = fin.read()

            # remove the temp file
            util.delete_file(temp_out_file_name)
            return util.replace_all(output, util.get_replace_dic())
        except subprocess.SubprocessError:
            proc.kill()
            outs, errs = proc.communicate()
            return errs
    else:
        return message.error_404_msg