def check_texture(self, nuke_path, texture_file, my_log=None): run_path = nuke_path run_path = CLASS_COMMON_UTIL.str_to_unicode(run_path) #print texture_file #print '________',run_path os.environ['HFS'] = run_path _PATH_ORG = os.environ.get('PATH') os.environ['PATH'] = (_PATH_ORG if _PATH_ORG else '') + r';' + run_path #print os.environ['PATH'] lib_path = '%s/lib' % (run_path) # _PATH_New = os.environ.get('PATH') # print '_PATH_New = ' + _PATH_New site_path = '%s/lib/site-packages' % (run_path) if lib_path not in sys.path: sys.path.append(lib_path) if site_path not in sys.path: sys.path.append(site_path) import nuke for i in texture_file: i = i.replace('\\', '/') texture_type = ['avi', 'eps', 'dds', 'bmp', 'vrimg'] if i.split('.')[-1] not in texture_type: #print i readtex = nuke.nodes.Read(file=i.encode('utf-8')) if readtex.metadata() == {}: CLASS_COMMON_UTIL.log_print(my_log, u'File is damaged' + i) else: # print u'ok__________'+i pass else: CLASS_COMMON_UTIL.log_print( my_log, u' This file does not support Nuke do check' + i)
def c4d_cmd_callback(self, my_popen, my_log): while my_popen.poll() == None: render_info = my_popen.stdout.readline().strip() if render_info == "": # self.G_DEBUG_LOG.info(render_info) # r_err = render_info continue CLASS_COMMON_UTIL.log_print(my_log, render_info)
def max_cmd_callback(self,my_popen,my_log): while my_popen.poll()==None: result_line = my_popen.stdout.readline().strip() if result_line=='' : continue CLASS_COMMON_UTIL.log_print(my_log,result_line) if '[_____KILL MAX_____]' in result_line: self.kill_max(my_popen.pid,my_log) CLASS_COMMON_UTIL.log_print(my_log,'\n\n-------------------------------------------End max program-------------------------------------------\n\n')
def c4d_cmd_callback(self, my_popen, my_log): while my_popen.poll()==None: render_info = my_popen.stdout.readline().strip() if render_info == "": continue CLASS_COMMON_UTIL.log_print(my_log, render_info) if '[Rendering successful:]' in str(render_info): CLASS_C4D_UTIL.kill_c4d(my_popen.pid, my_log) CLASS_COMMON_UTIL.log_print(my_log, '\n\n-------------------------------------------End c4d program-------------------------------------------\n\n') break
def main(self,local_path,server_path,my_log=None): nuke_path = r'C:/Program Files/Nuke10.0v4' check_file = self.get_file_size(local_path,server_path,my_log) if not check_file: CLASS_COMMON_UTIL.error_exit_log(my_log,'output have no file!') if platform.system() == 'Linux': pass else: if os.path.exists(nuke_path): try: self.check_texture(nuke_path,check_file,my_log) except Exception as e: CLASS_COMMON_UTIL.log_print(my_log,e)
def maya_cmd_callback(self, my_popen, my_log): index = 0 while my_popen.poll() is None: result_line = my_popen.stdout.readline().strip() result_line = result_line.decode(sys.getfilesystemencoding()) # result_line = result_line.decode('utf-8') if result_line == '': continue CLASS_COMMON_UTIL.log_print(my_log, result_line) if "Reference file not found" in result_line: index += 1 self.writing_error(25009, result_line)
def kill_c4d(self, parent_id, my_log=None): print('parent_id=' + str(parent_id)) cmd_str = 'wmic process where name="CINEMA 4D 64 Bit.exe" get Caption,ParentProcessId,ProcessId' print cmd_str cmdp = subprocess.Popen(cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: buff = cmdp.stdout.readline().strip() if buff == '' and cmdp.poll() != None: break if buff != None and buff != '': CLASS_COMMON_UTIL.log_print(my_log, 'c4d process info...') CLASS_COMMON_UTIL.log_print(my_log, buff) try: buffArr = buff.split() print str(buffArr) if int(buffArr[1]) == parent_id: print 'kill...' + buff os.system("taskkill /f /pid %s" % (buffArr[2])) except Exception, e: CLASS_COMMON_UTIL.log_print( my_log, 'taskkill CINEMA 4D 64 Bit.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e)
def maya_cmd_callback(self, my_popen, my_log): while my_popen.poll() is None: result_line = my_popen.stdout.readline().strip() result_line = result_line.decode('utf-8') if result_line == '': continue CLASS_COMMON_UTIL.log_print(my_log, result_line) if '[_____render end_____]' in result_line: # [_____render end_____][1] frame = re.search('\[(\d+)\]', result_line).group(1) self.multiframe_complete_list.append(frame) end_time = int(time.time()) self.render_record[frame]['end_time'] = end_time self.render_record[str(int(frame) + 1)] = { 'start_time': end_time, 'end_time': -1 }
def maya_cmd_callback(self, my_popen, my_log): while my_popen.poll() is None: result_line = my_popen.stdout.readline().strip() result_line = result_line.decode(sys.getfilesystemencoding()) # result_line = result_line.decode('utf-8') if result_line == '': continue CLASS_COMMON_UTIL.log_print(my_log, result_line) if self.g_one_machine_multiframe is True: if '[_____render end_____]' in result_line: # [_____render end_____][1] frame = re.search('\[(-?\d+)\]', result_line).group(1) self.multiframe_complete_list.append(frame) end_time = int(time.time()) print('[self.render_record]: {}'.format(self.render_record)) self.render_record[frame]['end_time'] = end_time self.render_record[str(int(frame) + int(self.G_CG_BY_FRAME))] = {'start_time': end_time, 'end_time': -1}
def maya_cmd_callback(self, my_popen, my_log): exit_maya_on = 0 while my_popen.poll() is None: result_line = my_popen.stdout.readline().strip() result_line = result_line.decode(sys.getfilesystemencoding()) # result_line = result_line.decode('utf-8') result_line = self.bytes_to_str(result_line) result_line = self.to_gbk(result_line) if result_line == '': continue CLASS_COMMON_UTIL.log_print(my_log, result_line) if self.g_one_machine_multiframe is True: if '[_____render end_____]' in result_line: # [_____render end_____][1] frame = re.search('\[(-?\d+)\]', result_line).group(1) self.multiframe_complete_list.append(frame) end_time = int(time.time()) print('[self.render_record]: {}'.format( self.render_record)) self.render_record[frame]['end_time'] = end_time self.render_record[str( int(frame) + int(self.G_CG_BY_FRAME))] = { 'start_time': end_time, 'end_time': -1 } if "License error" in result_line or "[mtoa] Failed batch render" in result_line or "error checking out license for arnold" in result_line or "No license for product (-1)" in result_line: self.exitcode = -1 # CLASS_MAYA_UTIL.killMayabatch(my_log) return self.exitcode #任务渲染完,强制退出maya completed_key = "Scene %s completed" % ( self.renderSettings["maya_file"]) if completed_key in result_line: exit_maya_on = 1 print("success maya batch end !!!") sys.stdout.flush() time.sleep(1) CLASS_MAYA_UTIL.killMayabatch(my_log) # kill mayabatch.exe return exit_maya_on
def maya_cmd_callback(self, my_popen, my_log): while True: result_line = my_popen.stdout.readline() if result_line: result_line = result_line.strip() if result_line: result_line = result_line.decode( sys.getfilesystemencoding()) CLASS_COMMON_UTIL.log_print(my_log, result_line) if '[_____render end_____]' in result_line: # [_____render end_____][1] frame = re.search('\[(\d+)\]', result_line).group(1) self.multiframe_complete_list.append(frame) end_time = int(time.time()) self.render_record[frame]['end_time'] = end_time self.render_record[str(int(frame) + 1)] = { 'start_time': end_time, 'end_time': -1 } else: break
def get_file_size(self,local_path,server_path,my_log=None): local_path = local_path.replace('\\','/') server_path = server_path.replace('\\','/') local_path = CLASS_COMMON_UTIL.str_to_unicode(local_path) server_path = CLASS_COMMON_UTIL.str_to_unicode(server_path) check_file = [] if os.path.exists(server_path): for root, dirs, files in os.walk(local_path): for file_name in files: if file_name.split('.')[-1]!='db': local_files = os.path.join(root, file_name).replace('\\', '/') local_file_size = os.path.getsize(local_files) server_files = server_path+local_files.split(local_path)[-1].replace('\\','/') if os.path.exists(server_files): server_file_size = os.path.getsize(server_files) if float(local_file_size)/1024>3: if local_file_size != server_file_size: CLASS_COMMON_UTIL.log_print(my_log,'Not the same as the file size:\n'+' local: \"'+str(local_files)+'\" size:'+str(local_file_size)+'\n server: \"'+str(server_files)+'\" size:'+str(server_file_size)+'\n') else: #print 'nuke____',local_files check_file.append(local_files) else: CLASS_COMMON_UTIL.log_print(my_log,'This file \"' + local_files + '\" size abnormal !\n') else: CLASS_COMMON_UTIL.log_print(my_log,'This file \"'+local_files+'\" not in server path !\n') return check_file
def kill_max(self,parent_id=None,my_log=None): print ('parent_id='+str(parent_id)) if parent_id==None: CLASS_COMMON_UTIL.log_print(my_log,'kill all 3dsmaxcmd') try: os.system('taskkill /F /IM 3dsmax.exe /T') except Exception, e: CLASS_COMMON_UTIL.log_print(my_log,'taskkill 3dsmax.exe exeception') CLASS_COMMON_UTIL.log_print(my_log,e)
'taskkill 3dsmax.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) else: cmd_str = 'wmic process where name="3dsmax.exe" get Caption,ParentProcessId,ProcessId' print cmd_str cmdp = subprocess.Popen(cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: buff = cmdp.stdout.readline().strip() if buff == '' and cmdp.poll() != None: break if buff != None and buff != '': CLASS_COMMON_UTIL.log_print(my_log, 'max process info...') CLASS_COMMON_UTIL.log_print(my_log, buff) try: buffArr = buff.split() print str(buffArr) if int(buffArr[1]) == parent_id: print 'kill...' + buff os.system("taskkill /f /pid %s" % (buffArr[2])) except Exception, e: CLASS_COMMON_UTIL.log_print( my_log, 'taskkill 3dsmax.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) try: os.system('taskkill /F /IM 3dsmaxcmd.exe /T')
try: buffArr = buff.split() print str(buffArr) if int(buffArr[1]) == parent_id: print 'kill...' + buff os.system("taskkill /f /pid %s" % (buffArr[2])) except Exception, e: CLASS_COMMON_UTIL.log_print( my_log, 'taskkill CINEMA 4D 64 Bit.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) try: os.system('taskkill /F /IM CINEMA 4D 64 Bit.exe /T') except Exception, e: CLASS_COMMON_UTIL.log_print( my_log, 'taskkill CINEMA 4D 64 Bit.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) CLASS_COMMON_UTIL.log_print(my_log, 'c4dKill...end...\n') @classmethod def c4d_cmd_callback(self, my_popen, my_log): while my_popen.poll() == None: render_info = my_popen.stdout.readline().strip() if render_info == "": # self.G_DEBUG_LOG.info(render_info) # r_err = render_info continue CLASS_COMMON_UTIL.log_print(my_log, render_info)
def kill_max(self, parent_id=None, my_log=None): CLASS_COMMON_UTIL.log_print(my_log, 'parent_id=' + str(parent_id)) if parent_id == None: CLASS_COMMON_UTIL.log_print(my_log, 'kill all 3dsmaxcmd') try: os.system('taskkill /F /IM 3dsmax.exe /T') except Exception as e: CLASS_COMMON_UTIL.log_print(my_log, 'taskkill 3dsmax.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) else: cmd_str = 'wmic process where name="3dsmax.exe" get Caption,ParentProcessId,ProcessId' CLASS_COMMON_UTIL.log_print(my_log, cmd_str) cmdp = subprocess.Popen(cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: buff = cmdp.stdout.readline().strip() buff = buff.decode(sys.getfilesystemencoding()) if buff == '' and cmdp.poll() != None: break if buff != None and buff != '': CLASS_COMMON_UTIL.log_print(my_log, 'max process info...') CLASS_COMMON_UTIL.log_print(my_log, buff) try: buffArr = buff.split() CLASS_COMMON_UTIL.log_print(my_log, str(buffArr)) # if int(buffArr[1])==parent_id: if buffArr[1] == str(parent_id): CLASS_COMMON_UTIL.log_print( my_log, 'kill...' + buff) os.system("taskkill /f /pid %s" % (buffArr[2])) except Exception as e: CLASS_COMMON_UTIL.log_print( my_log, 'taskkill 3dsmax.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) try: os.system('taskkill /F /IM 3dsmaxcmd.exe /T') except Exception as e: CLASS_COMMON_UTIL.log_print(my_log, 'taskkill 3dsmaxcmd.exe exeception') CLASS_COMMON_UTIL.log_print(my_log, e) CLASS_COMMON_UTIL.log_print(my_log, 'maxKill...end...\n')
def RB_RENDER(self): self.format_log('render','start') self.format_log('开始渲染','start') #start... self.G_RENDER_LOG.info('[c4d.RBrender.start.....]') #print ('--------------------remove_pyp_script----------------------------') self.G_DEBUG_LOG.info('[c4d.remove pyp.start.....]') cgv = self.G_CG_VERSION # "CINEMA 4D R19" C4dLoader.remove_pyp_script(cgv) self.G_DEBUG_LOG.info('[c4d.remove pyp.end.....]') print ('----------------------cg_file_info------------------------------') map_dict = self.G_TASK_JSON_DICT['mnt_map'] # use "/" map_dict_reverse = dict(zip(map_dict.values(), map_dict.keys())) print('map_dict_reverse: %s' % map_dict_reverse) # G_INPUT_CG_FILE: os.path.normpath(r'//10.60.100.104/stg_data/input/d/inputdata5/10000000/10000085/c4d/R17_test_ch.c4d') # G_INPUT_USER_PATH: os.path.normpath(r'//10.60.100.104/stg_data/input/d/inputdata5/10000000/10000085') input_cg_file_second_half = self.G_INPUT_CG_FILE[len(self.G_INPUT_USER_PATH):] # \E\test\C4DR17_Vray19_test\Vray_C4DR17_vray19.c4d print('input_cg_file_second_half: ' + input_cg_file_second_half) index = input_cg_file_second_half.find(os.sep, 1) # index begin position:1 input_cg_file_second_half_front = input_cg_file_second_half[:index] # \E input_cg_file_second_half_behind = input_cg_file_second_half[index:] # \test\C4DR17_Vray19_test\Vray_C4DR17_vray19.c4d print('input_cg_file_second_half_behind: ' + input_cg_file_second_half_behind) key = self.G_INPUT_USER_PATH + input_cg_file_second_half_front # \\10.60.100.104\stg_data\input\d\inputdata5\10000000\10000085\E driver = map_dict_reverse.get(key.replace('\\', '/')) # E: print('driver: %s' % driver) get_cg_file = driver + input_cg_file_second_half_behind # local cg file path print(get_cg_file + '[.@KANADA999999999999]') print ('-------------------------cg_version---------------------------------') if 'cg_name' in self.G_CG_CONFIG_DICT: cg_name = self.G_CG_CONFIG_DICT['cg_name'] if 'cg_version' in self.G_CG_CONFIG_DICT: cg_ver = self.G_CG_CONFIG_DICT['cg_version'] my_cg_ver = cg_name + ' ' + cg_ver print (my_cg_ver) # if my_cg_ver.endswith('.64') : # my_cg_ver=my_cg_ver.replace('.64','') # if my_cg_ver.endswith('.32') : # my_cg_ver=my_cg_ver.replace('.32','') print ('-----------------------scene_info_render-------------------------------') if 'scene_info_render' not in self.G_TASK_JSON_DICT: self.G_DEBUG_LOG.info("[ERROR]scene_info_render undefined...") return scene_info_render_common_dict = self.G_TASK_JSON_DICT['scene_info_render']['common'] cmd_render_width = scene_info_render_common_dict['width'] cmd_render_height = scene_info_render_common_dict['height'] cmd_regular_image_format = scene_info_render_common_dict['regular_image_format'] cmd_multipass_format = scene_info_render_common_dict['multi_pass_format'] cmd_multipass_path = scene_info_render_common_dict['multipass_saveimage_path'] cmd_multipass_enabled= scene_info_render_common_dict['multipass_save_enabled'] cmd_regular_image_saveimage_path= scene_info_render_common_dict['regular_image_saveimage_path'] print ('----------------------output_filename------------------------------') if cmd_regular_image_saveimage_path is None: cg_file_name = os.path.basename(self.G_INPUT_CG_FILE) get_filename = os.path.splitext(cg_file_name) cmd_regular_image_saveimage_path = get_filename[0] print((cmd_regular_image_saveimage_path + '[.@KANADA5555555555]')) self.G_JOB_NAME=self.G_JOB_NAME.encode(sys.getfilesystemencoding()) print ('--------------------------render_info----------------------------------') start_time = int(time.time()) self.G_FEE_PARSER.set('render', 'start_time', str(start_time)) if self.g_one_machine_multiframe == None or self.g_one_machine_multiframe == False: #C:\work\render\65368\output\0001.jpg output_file = self.G_WORK_RENDER_TASK_OUTPUT.replace("/", "\\") + "\\" + cmd_regular_image_saveimage_path + '.' + str(cmd_regular_image_format) print(output_file + '4444444444') output_renderlog_file = os.path.join(self.G_LOG_WORK +'/' + self.G_TASK_ID + '\\Render_' + self.G_JOB_ID + '_render.log').replace('/', '\\') print (output_renderlog_file) # cmd c4d_exe = os.path.join(r'"C:\Program Files\MAXON', my_cg_ver, 'CINEMA 4D 64 Bit.exe"') + ' -noopengl -nogui' user_id = ' ' + str(self.G_USER_ID) task_id = ' ' + str(self.G_TASK_ID) + ' ' render_frames = ' -frame ' + self.G_CG_START_FRAME + ' ' + self.G_CG_END_FRAME + ' '+ self.G_CG_BY_FRAME + ' ' render_option = '' if cmd_multipass_enabled == "0" or cmd_multipass_path == None or cmd_multipass_path == "": render_option = render_frames + ' -render "' + get_cg_file.replace("/", "\\") + '" -oresolution "' + str(cmd_render_width) \ + '" "' + str(cmd_render_height) +'" -oformat "' + str(cmd_regular_image_format) + '" -oimage "' + output_file + '"' print('render_option1: %s'%render_option) else: render_option = render_frames + ' -render "' + get_cg_file.replace("/", "\\") + '" -oresolution "' + str(cmd_render_width) \ + '" "' + str(cmd_render_height) +'" -oformat "' + str(cmd_regular_image_format) + '" -oimage "' + output_file + '" -omultipass "' + output_file + '" ' print('render_option2: %s'%render_option) render_cmd = c4d_exe + user_id + task_id + render_option #print("Cmds: %s" % render_cmd) self.G_RENDER_LOG.info("Cmds: %s" % render_cmd) self.G_DEBUG_LOG.info('[.@KANADA]') # 渲染开始时间 render_start_time = int(time.time()) if self.G_RENDER_OS=='Linux': self.RBcmd(render_cmd, True, 1, myLog=True) else: print ('\n\n---------------------------------------Start c4d program---------------------------------\n\n') CLASS_COMMON_UTIL.cmd(render_cmd,my_log=self.G_RENDER_LOG,continue_on_error=True,my_shell=True,callback_func=self.c4d_cmd_callback) # 渲染结束时间 render_end_time = int(time.time()) self.render_record[render_frames] = {'start_time': render_start_time,'end_time': render_end_time} elif self.g_one_machine_multiframe == True: render_frame_list = CLASS_COMMON_UTIL.need_render_from_frame(self.G_CG_FRAMES) for frame in render_frame_list: print("current rendering frame: %s" % frame) #C:\work\render\65368\output\0001\0001.jpg output_file = self.G_WORK_RENDER_TASK_OUTPUT.replace("/", "\\") + "\\" + frame.zfill(4) +"\\" + cmd_regular_image_saveimage_path + '.' + str(cmd_regular_image_format) print(output_file + '4444444444') # cmd c4d_exe = os.path.join(r'"C:\Program Files\MAXON', my_cg_ver, 'CINEMA 4D 64 Bit.exe"') + ' -noopengl -nogui' user_id = ' ' + str(self.G_USER_ID) task_id = ' ' + str(self.G_TASK_ID) + ' ' render_frames = ' -frame ' + frame + ' ' + frame + ' 1 ' render_option = '' if cmd_multipass_enabled == "0" and cmd_multipass_path == None: render_option = render_frames + ' -render "' + get_cg_file.replace("/", "\\") + '" -oresolution "' + str(cmd_render_width) \ + '" "' + str(cmd_render_height) +'" -oformat "' + str(cmd_regular_image_format) + '" -oimage "' + output_file + '"' print('render_option1: %s'%render_option) else: render_option = render_frames + ' -render "' + get_cg_file.replace("/", "\\") + '" -oresolution "' + str(cmd_render_width) \ + '" "' + str(cmd_render_height) +'" -oformat "' + str(cmd_regular_image_format) + '" -oimage "' + output_file + '" -omultipass "' + output_file + '" ' print('render_option2: %s'%render_option) render_cmd = c4d_exe + user_id + task_id + render_option #print("Cmds: %s" % render_cmd) self.G_RENDER_LOG.info("Cmds: %s" % render_cmd) self.G_DEBUG_LOG.info('[.@KANADA]') # 渲染开始时间 render_start_time = int(time.time()) if self.G_RENDER_OS == 'Linux': self.RBcmd(render_cmd, True, 1, myLog=True) else: print ('\n\n---------------------------------------Start c4d program---------------------------------\n\n') CLASS_COMMON_UTIL.cmd(render_cmd,my_log=self.G_DEBUG_LOG,continue_on_error=True,my_shell=True,callback_func=self.c4d_cmd_callback) CLASS_COMMON_UTIL.log_print(self.G_DEBUG_LOG, ("current rendering frame: ", frame)) # 渲染结束时间 render_end_time = int(time.time()) self.render_record[frame] = {'start_time': render_start_time,'end_time': render_end_time} self.multiframe_complete_list.append(frame) #self.G_RENDER_LOG.info('[一机多帧暂时不支持...]') #self.G_DEBUG_LOG.info('[一机多帧暂时不支持...]') end_time = int(time.time()) self.G_FEE_PARSER.set('render', 'end_time', str(end_time)) self.G_RENDER_LOG.info('[C4D.RBrender.end.....]') #end... os.system(r'wmic process where name="rlm.exe" delete') os.system(r'wmic process where name="rlm_c4dtoa.exe" delete') self.format_log('done','end') self.format_log('结束渲染','end')