def save_result(self, runjob, mei_document): result = taskutil.init_result(runjob) temp_mei_path = taskutil.create_temp_path(ext='mei') pymei.write(mei_document, temp_mei_path) taskutil.save_result(result, temp_mei_path) result.result_type = settings.MEI taskutil.save_instance(result) return result
def real_inner(result_ids, **kwargs): input_types = (inputs,) if isinstance(inputs, str) else inputs #storing as tuples to avoid extra db lookups results_pages = [(Result.objects.get(pk=result_id), Page.objects.get(result=result_id)) for result_id in result_ids] # storing pages in seperate ds for sorting independently of the order in results_pages target_pages = [result_page[1] for result_page in results_pages] # always sort pages based on sequence no matter the input target_pages.sort(key=lambda page: page.sequence) input_paths_matrix = map(lambda input_type: [page.get_latest_file_path(input_type) for page in target_pages], input_types) other_inputs_matrix = map(lambda other_type: [other_input_mapping[other_type](page) for page in target_pages], others) args = input_paths_matrix + other_inputs_matrix outputs = f(*args, **kwargs) # Loop through all the outputs and write them to disk for output_type, output_content in outputs.iteritems(): for result_page in results_pages: result = result_page[0] page = result_page[1] output_path = page.get_job_path(result.job_item.job, output_type) create_dirs(output_path) # Change the extension if output_type == 'mei': pymei.write(output_content, output_path) else: fp = open(output_path, 'w') fp.write(output_content) fp.close() result.create_file(output_path, output_type) #update parameters and end times of all results and start next auto jobs for result_page in results_pages: result = result_page[0] page = result_page[1] result.update_end_total_time() result.save_parameters(**kwargs) page.start_next_automatic_job(result.user)
def real_inner(result_id, **kwargs): input_types = (inputs,) if isinstance(inputs, str) else inputs result = Result.objects.get(pk=result_id) page = result.page # Figure out the paths to the requested input files # For one input, pass in a string; for multiple, a tuple input_paths = map(page.get_latest_file_path, input_types) other_inputs = [other_input_mapping[other](page) for other in others] args = input_paths + other_inputs outputs = f(*args, **kwargs) # Loop through all the outputs and write them to disk for output_type, output_content in outputs.iteritems(): output_path = page.get_job_path(result.job_item.job, output_type) create_dirs(output_path) # Change the extension if output_type == 'tiff': # Write it with gamera (it's an image) if isinstance(output_content, gamera.core.Image) or isinstance(output_content, gamera.core.SubImage): gamera.core.save_image(output_content, output_path) elif isinstance(output_content, PIL.Image.Image): output_content.save(output_path) else: print "The output_content was not recognized.\n" # Create thumbnails for the image as well create_thumbnails(output_path, result) elif output_type == 'vips': image_filepath, compression, tile_size = output_content # All pyramidal tiff images must be saved in the same dir vips_output = page.get_pyramidal_tiff_path() # Used for debugging only (should really be done after project creation) print "creating directories" create_dirs(vips_output) # Needs to be converted to a string (can't handle unicode) image = VImage(str(image_filepath)) image.vips2tiff("{0}:{1},tile:{2}x{2},pyramid".format(vips_output, compression, tile_size)) elif output_type == 'mei': pymei.write(output_content.md, output_path) elif output_type == 'xml': output_content.write_filename(output_path) else: fp = open(output_path, 'w') fp.write(output_content) fp.close() result.create_file(output_path, output_type) # Mark the job as finished, and save the parameters result.update_end_total_time() result.save_parameters(**kwargs) # If the next job is automatic, start that too! page.start_next_automatic_job(result.user)
def write_mei(self, output_path): if self._meidoc: pymei.write(self._meidoc, output_path)