示例#1
0
def main():
    args = createArgsParser().parse_args()

    tests_list = {}
    with open(args.tests_list, 'r') as file:
        tests_list = json.loads(file.read())

    try:
        os.makedirs(args.output_img_dir)
    except OSError as err:
        main_logger.error(str(err))
        return 1

    for test in tests_list:
        if test['status'] == 'active':
            case_report = RENDER_REPORT_BASE
            case_report.update({
                "original_color_path":
                "Color/" + test['name'] + '.' + args.output_file_ext,
                "original_render_log":
                test['name'] + '.or.log',
                "render_device":
                cpuinfo.get_cpu_info()['brand']
            })

            render_log_path = os.path.join(args.output_dir,
                                           test['name'] + '.or.log')
            case_camera = "persp"
            if "camera" in test.keys() and test['camera']:
                case_camera = test['camera']
            cmd_script = '"{render_path}" -r arnold -log "{log_path}" -rd "{out_dir}" -cam {camera} -im "{img_name}" -of {file_ext} "{scene_path}"'\
                .format(render_path=args.render_path, log_path=render_log_path, out_dir=args.output_img_dir,
                        camera=case_camera, img_name=test['name'], file_ext=args.output_file_ext, scene_path=os.path.join(args.scene_path, test['name']))
            cmd_script_path = os.path.join(args.output_dir,
                                           test['name'] + '.renderArnold.bat')

            try:
                with open(cmd_script_path, 'w') as file:
                    file.write(cmd_script)
                with open(render_log_path, 'w') as file:
                    pass
            except OSError as err:
                main_logger.error("Error while saving bat: {}".format(
                    str(err)))
            else:
                rc = -1
                os.chdir(args.output_dir)
                p = psutil.Popen(cmd_script_path,
                                 shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
                stdout, stderr = p.communicate()

                try:
                    rc = p.wait()
                except psutil.TimeoutExpired as err:
                    main_logger.error("Terminated by simple render. {}".format(
                        str(err)))
                    rc = -1
                    for child in reversed(p.children(recursive=True)):
                        child.terminate()
                    p.terminate()
                # return rc
                if rc == 0:
                    with open(
                            os.path.join(args.output_dir,
                                         test['name'] + '_AI.json'),
                            'w') as file:
                        json.dump([case_report], file, indent=4)
    return 0
示例#2
0
def main():
    args = createArgsParser()

    tests_list = {}
    tests = ""
    with open(args.tests_list, 'r') as file:
        tests_list = json.loads(file.read())

    if not os.path.exists(os.path.join(args.output_dir, 'Color')):
        os.makedirs(os.path.join(args.output_dir, 'Color'))

    tests = []
    for test in tests_list:
        if test['status'] == 'active':
            tests.append(test['name'])

    with open(os.path.join(os.path.dirname(__file__), 'main_template.py'),
              'r') as file:
        py_script = file.read().format(
            tests=tests,
            work_dir=args.output_dir.replace('\\', '/'),
            res_path=args.scene_path.replace('\\', '/'))

    with open(os.path.join(args.output_dir, 'script.py'), 'w') as file:
        file.write(py_script)

    shutil.copyfile(
        os.path.join(os.path.dirname(__file__), 'convertAI2RPR.py'),
        os.path.join(args.output_dir, 'convertAI2RPR.py'))

    cmd_script = '''
    set MAYA_CMD_FILE_OUTPUT=%cd%/renderTool.log
    set PYTHONPATH=%cd%;PYTHONPATH
    set MAYA_SCRIPT_PATH=%cd%;%MAYA_SCRIPT_PATH%
    "{}" -command "python(\\"import script as converter\\"); python(\\"converter.main()\\");" '''.format(
        args.render_path)

    cmd_script_path = os.path.join(args.output_dir, 'renderRPR.bat')

    try:
        with open(cmd_script_path, 'w') as file:
            file.write(cmd_script)
    except OSError as err:
        main_logger.error(str(err))
        return 1
    else:
        rc = -1
        os.chdir(args.output_dir)
        p = psutil.Popen(cmd_script_path,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()

        while True:
            try:
                rc = p.wait(timeout=5)
            except psutil.TimeoutExpired as err:
                fatal_errors_titles = [
                    'maya', 'Student Version File', 'Radeon ProRender Error',
                    'Script Editor'
                ]
                if set(fatal_errors_titles).intersection(get_windows_titles()):
                    rc = -1
                    try:
                        error_screen = pyscreenshot.grab()
                        error_screen.save(
                            os.path.join(args.output_dir,
                                         'error_screenshot.jpg'))
                    except:
                        pass
                    for child in reversed(p.children(recursive=True)):
                        child.terminate()
                    p.terminate()
                    break
            else:
                break

        for test in tests_list:
            if test['status'] == 'active':
                conversion_log_path = os.path.join(args.scene_path,
                                                   test['name'] + '.log')
                if os.path.exists(conversion_log_path):
                    shutil.copyfile(
                        conversion_log_path,
                        os.path.join(args.output_dir,
                                     test['name'] + '.conversion.log'))
        return rc
def main():
    args = createArgsParser().parse_args()

    tests_list = {}
    with open(args.tests_list, 'r') as file:
        tests_list = json.loads(file.read())

    try:
        os.makedirs(args.output_img_dir)
    except OSError as err:
        main_logger.error(str(err))
        return 1

    for test in tests_list:
        if test['status'] == 'active':
            case_report = RENDER_REPORT_BASE
            case_report.update({
                "original_color_path":
                "Color/" + test['name'] + '.' + args.output_file_ext,
                "original_render_log":
                test['name'] + '.or.log'
            })
            render_log_path = os.path.join(args.output_dir,
                                           test['name'] + '.or.log')

            scenes_without_camera1 = [
                'Bump', 'BumpBlender', 'Displacement', 'DisplacementBlender',
                'Fresnel', 'Normal', 'CarPaint', 'Incandescent',
                'SubsurfaceScatter', 'AmbientOcclusion', 'CameraMap', 'Noise',
                'ColorLayer'
            ]
            use_camera1 = " -cam camera1"
            if os.path.basename(args.output_dir) in scenes_without_camera1:
                use_camera1 = ""
            cmd_script = '"{}" -r redshift -proj "{}" -log {} -rd "{}" -im "{}" -of {}{} "{}"' \
                .format(args.render_path, args.scene_path, render_log_path, args.output_img_dir,
                        os.path.join(args.output_img_dir, test['name']), args.output_file_ext, use_camera1,
                        os.path.join(args.scene_path, test['name']))
            cmd_script_path = os.path.join(
                args.output_dir, test['name'] + '.renderRedshift.bat')

            try:
                with open(cmd_script_path, 'w') as file:
                    file.write(cmd_script)
                with open(render_log_path, 'w') as file:
                    pass
            except OSError as err:
                main_logger.error("Error while saving bat: {}".format(
                    str(err)))
            else:
                rc = -1
                os.chdir(args.output_dir)
                p = psutil.Popen(cmd_script_path,
                                 shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
                stdout, stderr = p.communicate()

                try:
                    rc = p.wait()
                except psutil.TimeoutExpired as err:
                    main_logger.error("Terminated by simple render. {}".format(
                        str(err)))
                    rc = -1
                    for child in reversed(p.children(recursive=True)):
                        child.terminate()
                    p.terminate()
                # return rc
                if rc == 0:
                    case_report['render_time'] = get_or_render_time(
                        case_report['original_render_log'])
                    with open(
                            os.path.join(args.output_dir,
                                         test['name'] + '_RS.json'),
                            'w') as file:
                        json.dump([case_report], file, indent=4)
    return 0