예제 #1
0
파일: models.py 프로젝트: bmerrison/mreorg
 def get_current_checksum(self):
     return mreorg.get_file_sha1hash(self.full_filename)
예제 #2
0
    def write_to_database( cls, sim_run_info):
        output_file_dir = mreorg.MReOrgConfig.get_image_store_dir()

        print 'Saving details from script: ', sim_run_info.script_name

        # We don't neeed to update this file every time:
        if mreorg.MReOrgConfig.is_non_curated_file(sim_run_info.script_name):
            return

        try:
            simfile = SimFile.get_tracked_sims( full_filename=sim_run_info.script_name)
        except: # DoesNotExistError,e :
            simfile = SimFile.create( full_filename=sim_run_info.script_name, tracked=True)
            simfile.save()


        # Create a simulation result object:
        simres = SimFileRun(
            simfile = simfile,
            execution_date = datetime.datetime.now(),
            execution_time = sim_run_info.time_taken,
            return_code = sim_run_info.return_code,
            std_out = sim_run_info.std_out,
            std_err = sim_run_info.std_err,
            exception_type = sim_run_info.exception_details[0],
            exception_traceback = str(sim_run_info.exception_details[2]),
            simulation_sha1hash = get_file_sha1hash(simfile.full_filename),
            library_sha1hash = '00000', 
            runconfig = RunConfiguration.objects.get(id=int(os.environ['_MREORG_RUNCONFIGID'])) 
            )

        simres.save()

        output_file_dir = mreorg.MReOrgConfig.get_image_store_dir()
        # Create the images
        for image_filename in sim_run_info.output_images:
            if not image_filename.endswith('svg'):
                continue

            # Copy the output file:
            try:
                hashstr = mreorg.get_file_sha1hash( image_filename)
            except:
                hashstr=None
            
            if hashstr == None:
                continue

            opfile1 = output_file_dir + '/' + hashstr + '.svg'
            shutil.copyfile(image_filename, opfile1)

            f_thumb = image_filename.replace(".svg","thumb.png")
            os.system('convert %s -resize 400x300 %s'%(
                         pipes.quote(image_filename),pipes.quote(f_thumb)))
            hashstr = hashlib.md5( open(f_thumb).read() ).hexdigest()
            hashstr = mreorg.get_file_sha1hash( f_thumb)
            opfile2 = output_file_dir + '/' + hashstr + ".png"
            shutil.copyfile(f_thumb, opfile2)
            im_obj = SimFileRunOutputImage(
                    original_name = image_filename,
                    hash_name = opfile1,
                    hash_thumbnailname = opfile2,
                    simulation = simres
                    )


            im_obj.save()
예제 #3
0
    def write_to_database(cls, sim_run_info):
        output_file_dir = mreorg.MReOrgConfig.get_image_store_dir()

        print 'Saving details from script: ', sim_run_info.script_name

        # We don't neeed to update this file every time:
        if mreorg.MReOrgConfig.is_non_curated_file(sim_run_info.script_name):
            return


        simfile = SimFile.get_or_make(full_filename=sim_run_info.script_name, make_kwargs={'tracking_status':TrackingStatus.Tracked})
        

        import time

        # Create a simulation result object:
        simres = SimFileRun(
            simfile=simfile,
            execution_date=datetime.datetime.now(),
            execution_time=sim_run_info.time_taken,
            return_code=sim_run_info.return_code,
            std_out=sim_run_info.std_out,
            std_err=sim_run_info.std_err,
            exception_type=sim_run_info.exception_details[0],
            exception_traceback=str(sim_run_info.exception_details[2]),
            simulation_sha1hash=get_file_sha1hash(simfile.full_filename),
            library_sha1hash='00000',
            runconfig=RunConfiguration.objects.get(id=int(os.environ['_MREORG_RUNCONFIGID'])),
            )

        simres.save()

        with transaction.commit_on_success():
            output_file_dir = mreorg.MReOrgConfig.get_image_store_dir()
            # Create the images
            for image_filename in sim_run_info.output_images:
                if not image_filename.endswith('svg'):
                    continue

                # Copy the output file:
                try:
                    hashstr = mreorg.get_file_sha1hash(image_filename)
                except:
                    hashstr = None

                if hashstr == None:
                    continue

                opfile1 = output_file_dir + '/' + hashstr + '.svg'
                shutil.copyfile(image_filename, opfile1)

                f_thumb = image_filename.replace('.svg', 'thumb.png')
                os.system('convert %s -resize 400x300 %s' % (pipes.quote(image_filename),pipes.quote(f_thumb)))
                time.sleep(5) # Sometimes, its not ready!
                #hashstr = hashlib.md5(open(f_thumb).read()).hexdigest()
                hashstr = mreorg.get_file_sha1hash(f_thumb)
                opfile2 = output_file_dir + '/' + hashstr + ".png"
                shutil.copyfile(f_thumb, opfile2)
                im_obj = SimFileRunOutputImage(
                        original_name=image_filename,
                        hash_name=opfile1,
                        hash_thumbnailname=opfile2,
                        simulation=simres)


                im_obj.save()
예제 #4
0
파일: models.py 프로젝트: mikehulluk/mreorg
 def get_current_checksum(self):
     return mreorg.get_file_sha1hash(self.full_filename)