def worker_func(idx): global exit_code java_options = "" if len(options.java_options) > 0: java_options += ' "-{0}"'.format('" "-'.join(options.java_options)) if len(xconv_options['java_options']) > 0: java_options += ' "{0}"'.format('" "'.join(xconv_options[ 'java_options'])) pexec = None if not options.test: pexec = Popen( 'java {0} -jar "{1}" --stdin'.format( java_options, xconv_options['xresloader_path']), stdin=PIPE, stdout=None, stderr=None, shell=True) while True: cmd_picker_lock.acquire() if len(cmd_list) <= 0: cmd_picker_lock.release() break pexec.stdin.write(cmd_list.pop().encode(console_encoding)) cmd_picker_lock.release() pexec.stdin.write(os.linesep.encode(console_encoding)) pexec.stdin.flush() pexec.stdin.close() cmd_exit_code = pexec.wait() exit_code = exit_code + cmd_exit_code else: this_thd_cmds = [] while True: cmd_picker_lock.acquire() if len(cmd_list) <= 0: cmd_picker_lock.release() break # python2 must use encode string to bytes or there will be messy code # python3 must not use encode methed because it will transform string to bytes if sys.version_info.major < 3: this_thd_cmds.append(cmd_list.pop().encode(console_encoding)) else: this_thd_cmds.append(cmd_list.pop()) cmd_picker_lock.release() cprintf_stdout([print_style.FC_GREEN], ( 'java {0} -jar "{1}" --stdin' + os.linesep + '\t>{2}' + os.linesep ).format(java_options, xconv_options['xresloader_path'], (os.linesep + '\t>').join(this_thd_cmds)))
def worker_func(idx): global exit_code java_options = ['java'] if len(options.java_options) > 0: for java_option in options.java_options: java_options.append('-{0}'.format(java_option)) if len(xconv_options['java_options']) > 0: for java_option in xconv_options['java_options']: java_options.append(java_option) java_options.append("-Dfile.encoding={0}".format(java_encoding)) java_options.append('-jar') java_options.append(xconv_options['xresloader_path']) java_options.append('--stdin') once_pick_count = len(xconv_options['output_matrix']['outputs']) if once_pick_count <= 1: once_pick_count = 1 pexec = None if not options.test: pexec = Popen(java_options, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False) worker_thd_print_stdout = threading.Thread(target=print_stdout_func, args=[pexec]) worker_thd_print_stderr = threading.Thread(target=print_stderr_func, args=[pexec]) worker_thd_print_stdout.start() worker_thd_print_stderr.start() while True: cmd_picker_lock.acquire() if len(cmd_list) <= 0: cmd_picker_lock.release() break for _ in range(0, once_pick_count): if not cmd_list: break pexec.stdin.write(' '.join( cmd_list.pop()).encode(java_encoding)) pexec.stdin.write(os.linesep.encode(java_encoding)) cmd_picker_lock.release() pexec.stdin.flush() pexec.stdin.close() for output_line in pexec.stdout.readlines(): print(output_line.decode(java_encoding)) cmd_exit_code = pexec.wait() worker_thd_print_stdout.join() worker_thd_print_stderr.join() exit_code = exit_code + cmd_exit_code else: this_thd_cmds = [] while True: cmd_picker_lock.acquire() if len(cmd_list) <= 0: cmd_picker_lock.release() break for _ in range(0, once_pick_count): if not cmd_list: break # python2 must use encode string to bytes or there will be messy code # python3 must not use encode methed because it will transform string to bytes if sys.version_info.major < 3 and not conv_compat_py2_write_buffer: this_thd_cmds.append(' '.join( cmd_list.pop()).encode(console_encoding)) else: this_thd_cmds.append(' '.join(cmd_list.pop())) cmd_picker_lock.release() cprintf_stdout([print_style.FC_GREEN], ('"{0}"' + os.linesep + '\t>{1}' + os.linesep).format( '" "'.join(java_options), (os.linesep + '\t>').join(this_thd_cmds)))
else: print('[ERROR] unknown global configure ' + tag_name) if xconv_xml_global_nodes and len(xconv_xml_global_nodes) > 0: load_global_options(xconv_xml_global_nodes) # ----------------------------------------- 全局配置解析 ----------------------------------------- conv_list_dir = os.path.dirname(xconv_options['conv_list']) if conv_list_dir: os.chdir(conv_list_dir) os.chdir(xconv_options['work_dir']) cprintf_stdout([print_style.FC_YELLOW], '[NOTICE] start to run conv cmds on dir: {0}' + os.linesep, os.getcwd()) if not os.path.exists(xconv_options['xresloader_path']): cprintf_stderr([print_style.FC_RED], '[ERROR] xresloader not found.({0})' + os.linesep, xconv_options['xresloader_path']) exit(-4) # ========================================= 转换表配置解析 ========================================= # 转换项配置解析/合并 def load_list_item_nodes(lis): for item in lis: conv_item_obj = { 'file': False,
if xconv_xml_global_nodes and len(xconv_xml_global_nodes) > 0: load_global_options(xconv_xml_global_nodes) # ----------------------------------------- 全局配置解析 ----------------------------------------- # conv_list_dir = os.path.dirname(xconv_options['conv_list']) # if conv_list_dir: # os.chdir(conv_list_dir) os.chdir(xconv_options['work_dir']) conv_start_msg = ('[NOTICE] start to run conv cmds on dir: {0}' + os.linesep).format(os.getcwd()) if sys.version_info.major >= 3: cprintf_stdout([print_style.FC_YELLOW], conv_start_msg) else: conv_compat_py2_write_buffer = False try: cprintf_stdout([print_style.FC_YELLOW], conv_start_msg.decode(console_encoding)) except Exception as _e: conv_compat_py2_write_buffer = True cprintf_stdout([print_style.FC_YELLOW], conv_start_msg) if not os.path.exists(xconv_options['xresloader_path']): print(os.getcwd()) cprintf_stderr([print_style.FC_RED], '[ERROR] xresloader not found.({0})' + os.linesep, xconv_options['xresloader_path']) exit(-4)