コード例 #1
0
ファイル: views.py プロジェクト: it-innovation/MServe
def stats(request, baseid=None):
    from jobservice.models import Job
    job_json = Job.get_job_plots(request, baseid=baseid)
    mfile_json = MFile.get_mfile_plots(request, baseid=baseid)
    usage_json = Usage.get_usage_plots(request, baseid=baseid)
    json = job_json + mfile_json + usage_json
    if json == None:
        return HttpResponseNotFound()
    _json = simplejson.dumps(json)
    return HttpResponse(_json, mimetype="application/json")
コード例 #2
0
def post_save_handler( sender, instance=False, **kwargs):
    try:
        logging.debug("Prestoprime POST save handler %s %s" % (instance, instance.file))

        # Record Additional Usage
        if instance.name is not None and not instance.initial_usage_recorded and instance.name.endswith(".mxf"):
            logging.debug("Prestoprime POST save handler %s id:'%s' " % (instance,instance.id))

            mxfframecounttask = mxfframecount.subtask([[instance.id],[]])

            #count = result["frames"]
            #logging.info("Recording ingest usage %s " % (count))
            #usage_store.record(instance.id,pp_mxfframe_ingested_metric,count)

            job = Job(name="Prestoprime Tasks",mfile=instance)
            job.save()

            output = JobOutput(name="Job Output",job=job,mimetype="text/plain")
            output.save()

            ## Do Post Processing
            mfiled10check = MFileD10Check(mfile=instance)
            
            temp_handle = StringIO()
            temp_handle.seek(0)

            suf = SimpleUploadedFile("checkfile", temp_handle.read())
            mfiled10check.checkfile.save(suf.name+'.txt', suf, save=False)
            mfiled10check.save()

            d10mxfchecksumtask = d10mxfchecksum.subtask([[instance.id],[output]])

            ts = TaskSet(tasks=[d10mxfchecksumtask,mxfframecounttask])
            tsr = ts.apply_async()
            tsr.save()

            
            job.taskset_id=tsr.taskset_id
            job.save()
            
            logging.debug("Prestoprime task %s  " % task  )

    except Exception as e:
        logging.error("Prestoprime POST save handler failed %s " % e)
コード例 #3
0
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