def run(self, build_id=None, release_name=None, release_number=None, run_name=None, reference_sha1sum=None, run_sha1sum=None, heartbeat=None): output_path = tempfile.mkdtemp() try: ref_path = os.path.join(output_path, 'ref') ref_resized_path = os.path.join(output_path, 'ref_resized') run_path = os.path.join(output_path, 'run') diff_path = os.path.join(output_path, 'diff.png') log_path = os.path.join(output_path, 'log.txt') yield heartbeat('Fetching reference and run images') yield [ release_worker.DownloadArtifactWorkflow( build_id, reference_sha1sum, result_path=ref_path), release_worker.DownloadArtifactWorkflow( build_id, run_sha1sum, result_path=run_path) ] max_attempts = FLAGS.pdiff_task_max_attempts yield heartbeat('Resizing reference image') returncode = yield ResizeWorkflow( log_path, ref_path, run_path, ref_resized_path) if returncode != 0: raise PdiffFailedError( max_attempts, 'Could not resize reference image to size of new image') yield heartbeat('Running perceptual diff process') returncode = yield PdiffWorkflow( log_path, ref_resized_path, run_path, diff_path) diff_success = returncode == 0 # Check for a successful run or a known failure. if os.path.isfile(log_path): log_data = open(log_path).read() if 'all: 0 (0)' in log_data: diff_path = None elif 'image widths or heights differ' in log_data: # Give up immediately max_attempts = 1 yield heartbeat('Reporting diff status to server') yield release_worker.ReportPdiffWorkflow( build_id, release_name, release_number, run_name, diff_path, log_path, diff_success) if not diff_success: raise PdiffFailedError( max_attempts, 'Comparison failed. returncode=%r' % returncode) finally: shutil.rmtree(output_path, True)
def run(self, build_id=None, release_name=None, release_number=None, run_name=None, reference_sha1sum=None, run_sha1sum=None, heartbeat=None): output_path = tempfile.mkdtemp() try: ref_path = os.path.join(output_path, 'ref') ref_resized_path = os.path.join(output_path, 'ref_resized') run_path = os.path.join(output_path, 'run') diff_path = os.path.join(output_path, 'diff.png') log_path = os.path.join(output_path, 'log.txt') yield heartbeat('Fetching reference and run images') yield [ release_worker.DownloadArtifactWorkflow( build_id, reference_sha1sum, result_path=ref_path), release_worker.DownloadArtifactWorkflow( build_id, run_sha1sum, result_path=run_path) ] max_attempts = FLAGS.pdiff_task_max_attempts yield heartbeat('Resizing reference image') returncode = yield ResizeWorkflow( log_path, ref_path, run_path, ref_resized_path) if returncode != 0: raise PdiffFailedError( max_attempts, 'Could not resize reference image to size of new image') yield heartbeat('Running perceptual diff process') returncode = yield PdiffWorkflow( log_path, ref_resized_path, run_path, diff_path) # ImageMagick returns 1 if the images are different and 0 if # they are the same, so the return code is a bad judge of # successfully running the diff command. Instead we need to check # the output text. diff_failed = True # Check for a successful run or a known failure. distortion = None if os.path.isfile(log_path): log_data = open(log_path).read() if 'all: 0 (0)' in log_data: diff_path = None diff_failed = False elif 'image widths or heights differ' in log_data: # Give up immediately max_attempts = 1 else: # Try to find the image magic normalized root square # mean and grab the first one. r = DIFF_REGEX.findall(log_data) if len(r) > 0: diff_failed = False distortion = r[0] yield heartbeat('Reporting diff result to server') yield release_worker.ReportPdiffWorkflow( build_id, release_name, release_number, run_name, diff_path, log_path, diff_failed, distortion) if diff_failed: raise PdiffFailedError( max_attempts, 'Comparison failed. returncode=%r' % returncode) finally: shutil.rmtree(output_path, True)