def mfile_get_handler( sender, mfile=False, **kwargs): logging.info("In Prestoprime handler" ) try: if mfile.file.name.endswith(".mxf"): mfiled10check=MFileD10Check.objects.get(mfile=mfile) tmpfile = tempfile.NamedTemporaryFile(mode="w") d10mxfchecksum([mfile.file.path],[tmpfile.name]) if not filecmp.cmp(tmpfile.name,mfiled10check.checkfile.path): lines1 = open(tmpfile.name).readlines() lines2 = open(mfiled10check.checkfile.path).readlines() # TODO: Make this a celery task corrupted = 0 i = 0 frames = [] job = Job(name="Extract Corrupted Frames",service=mfile.service) job.save() tasks = [] for line1 in lines1: line2 = lines2[i] if line1 != line2: split = line1.split("\t") frameS = split[0] try: frame = int(frameS) frames.append(frame) logging.info("frame %s corrupted " % frame ) output = JobOutput(name="Job 'Corrupted Frame %s'"%frame,job=job,mimetype="image/png") output.save() fname = "%s.%s" % ("corruptedframe","png") outputpath = os.path.join( str(job.id) , fname) output.file = outputpath thumbfolder = os.path.join( settings.THUMB_ROOT, str(job.id)) if not os.path.exists(thumbfolder): os.makedirs(thumbfolder) (head,tail) = os.path.split(output.file.path) if not os.path.isdir(head): os.makedirs(head) thumbfile= os.path.join( thumbfolder , "%s%s" % (fname,".thumb.png")) thumbpath = os.path.join( str(job.id) , "%s%s" % (fname,".thumb.png")) output.thumb = thumbpath output.save() thumboptions = {"width":settings.thumbsize[0],"height":settings.thumbsize[1]} callback = thumbimage.subtask([output,thumbfile,thumboptions]) logging.info("Creating task %s %s " % (mfile.file.path,output.file.path)) inputs = [mfile.file.path] outputs = [output.file.path] options = {"frame":frame} callbacks = [callback] task = extractd10frame.subtask([inputs,outputs,options],callbacks=callbacks) tasks.append(task) logging.info("task created %s" % task) corrupted += 1 except ValueError as e: logging.info("PP handler %s " % e) i = i+1 if len(tasks) > 0: logging.info("tasks to execute created %s" % task) job.save() ts = TaskSet(tasks=tasks) tsr = ts.apply_async() tsr.save() job.taskset_id=tsr.taskset_id job.name="Extract Corrupted Frames %s" % frames job.save() else: job.delete() if corrupted > 0: usage_store.record(mfile.id,pp_mxfframe_corrupted_metric,corrupted) logging.info("Lines Corrupted = %s " % corrupted) else: logging.info("Files are same") except MFileD10Check.DoesNotExist: logging.info("Prestoprime mfile_get_handler ") except Exception as e: logging.info("Prestoprime mfile get handler failed %s " % e) logging.info("Done Prestoprime handler" ) return