def analyze(self, an_uri): stdoutdata, stderrdata, returncode = run_blender( an_uri, script_path(__file__) ) if returncode != 0: raise AnalyzerException('BlendAnalyzer failed with returncode "%s"' % returncode) LOG.debug(stdoutdata) LOG.debug(stderrdata) data = str(stdoutdata).split('-**-')[1] for old, replace in [('\n', ''), ('\r', ''), ("b'", ''), ("'", '')]: data = data.replace(old, replace) data = binascii.unhexlify(data) file_descr = DeserializeThriftMsg( FileDescription(), data, TBinaryProtocol.TBinaryProtocol ) return file_descr
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) abs_file_path = os.path.join(dest_path, path_template) abs_file_path_txt = abs_file_path+'.txt' arguments = ['--', asset_id.mimetype, asset_id.subname, abs_file_path_txt] logger.debug(abs_file_path) stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code arguments = ['convert', '-pointsize', '26', '-resize', str(options['size'][0]), abs_file_path_txt+'[0]', abs_file_path] print arguments pro = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdoutdata, stderrdata = pro.communicate() logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(pro.returncode) return [path_template]
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) arguments = [ '--', file_descr.file.filename, asset_id.subname, path_template ] arguments.append('--format=PNG') #TODO arguments.append('--width=' + str(options['size'][0])) arguments.append('--height=' + str(options['size'][1])) stdoutdata, stderrdata, returncode = run_blender( os.path.join(os.path.dirname(__file__), 'BlenderMaterialPreviewScenes.blend'), script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code return path_template
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): file_path = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) full_path = os.path.join(dest_path, file_path) arguments = ['--', asset_id.subname, full_path] stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments) #print(stdoutdata) #print(stderrdata) #print(returncode) #Todo: check return code try: im = Image.open(full_path) except IOError: print("Cannot open: %s" % full_path) return False if tuple(options['size']) != (-1,-1): im.thumbnail(options['size']) if im.mode == 'P': im = im.convert('RGB') im.save(full_path) return [file_path]
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) arguments = ['--', asset_id.subname, path_template] stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code return path_template
def analyze(self, an_uri): stdoutdata, stderrdata, returncode = run_blender(an_uri, script_path(__file__)) if returncode != 0: raise AnalyzerException('BlendAnalyzer failed with %s'%(returncode)) logger.debug(stdoutdata) logger.debug(stderrdata) data = str(stdoutdata).split('-**-')[1].replace('\n', '').replace('\r', '').replace("b'", '').replace("'", '') data = binascii.unhexlify(data) file_descr = DeserializeThriftMsg(FileDescription(), data, TBinaryProtocol.TBinaryProtocol) return file_descr
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) arguments = ["--", asset_id.subname, path_template] arguments.append("--format=PNG") # TODO arguments.append("--width=" + str(options["size"][0])) arguments.append("--height=" + str(options["size"][1])) stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) # print(returncode) #Todo: check return code return path_template
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): angles = options['angles'] del options['angles'] path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) file_paths = [] for angle in angles: opts = dict(options) opts['angles'] = angle file_path = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **opts) file_paths.append(file_path) if asset_id.mimetype == 'application/x-blender.mesh': datatype = 'mesh' elif asset_id.mimetype == 'application/x-blender.group': datatype = 'group' else: datatype = 'object' arguments = ['--', datatype, asset_id.subname, path_template] arguments.extend(list(map(str, angles))) arguments.append('--format=PNG') # TODO arguments.append('--camera_type=PERSPECTIVE') arguments.append('--width=' + str(options['size'][0])) arguments.append('--height=' + str(options['size'][1])) stdoutdata, stderrdata, returncode = run_blender( file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) # print(returncode) #Todo: check return code return file_paths
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): angles = options['angles'] del options['angles'] path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) file_paths = [] for angle in angles: opts = dict(options) opts['angles'] = angle file_path = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **opts) file_paths.append(file_path) if asset_id.mimetype == 'application/x-blender.mesh': datatype = 'mesh' elif asset_id.mimetype == 'application/x-blender.group': datatype = 'group' else: datatype = 'object' arguments = ['--', datatype, asset_id.subname, path_template] arguments.extend(map(str, angles)) arguments.append('--format=PNG')#TODO arguments.append('--camera_type=PERSPECTIVE') arguments.append('--width='+str(options['size'][0])) arguments.append('--height='+str(options['size'][1])) stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code return file_paths
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) abs_file_path = os.path.join(dest_path, path_template) abs_file_path_txt = abs_file_path + '.txt' arguments = [ '--', asset_id.mimetype, asset_id.subname, abs_file_path_txt ] logger.debug(abs_file_path) stdoutdata, stderrdata, returncode = run_blender( file_descr.file.filename, script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code arguments = [ 'convert', '-pointsize', '26', '-resize', str(options['size'][0]), abs_file_path_txt + '[0]', abs_file_path ] # print arguments pro = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdoutdata, stderrdata = pro.communicate() logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(pro.returncode) return [path_template]
def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options): path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options) path_template = os.path.join(dest_path, path_template) arguments = ['--', file_descr.file.filename, asset_id.subname, path_template] arguments.append('--format=PNG')#TODO arguments.append('--width='+str(options['size'][0])) arguments.append('--height='+str(options['size'][1])) stdoutdata, stderrdata, returncode = run_blender(os.path.join(os.path.dirname(__file__), 'BlenderMaterialPreviewScenes.blend'), script_path(__file__), arguments) logger.debug(stdoutdata) logger.debug(stderrdata) logger.debug(returncode) #print(returncode) #Todo: check return code return path_template