コード例 #1
0
def insertTemplateImage(params):
    for i, name in enumerate(params['templatelist']):
        if os.path.basename(name) != name:
            apDisplay.printError(
                "please contact an appion developer, because the database insert is wrong"
            )

        #check if template exists
        templateq = appiondata.ApTemplateImageData()
        templateq['path'] = appiondata.ApPathData(
            path=os.path.abspath(params['rundir']))
        templateq['templatename'] = name
        templateId = templateq.query(results=1)
        if templateId:
            apDisplay.printWarning(
                "template already in database.\nNot reinserting")
            continue

        #check if duplicate template exists
        temppath = os.path.join(params['rundir'], name)
        md5sum = apFile.md5sumfile(temppath)
        templateq2 = appiondata.ApTemplateImageData()
        templateq2['md5sum'] = md5sum
        templateId = templateq2.query(results=1)
        if templateId:
            apDisplay.printWarning(
                "template with the same check sum already exists in database.\nNot reinserting"
            )
            continue

        #insert template to database if doesn't exist
        print "Inserting", name, "into the template database"
        templateq['apix'] = params['apix']
        templateq['diam'] = params['diam']
        templateq['md5sum'] = md5sum
        if 'alignid' in params and params['alignid'] is not None:
            templateq['alignstack'] = appiondata.ApAlignStackData.direct_query(
                params['alignid'])
        if 'clusterid' in params and params['clusterid'] is not None:
            templateq[
                'clusterstack'] = appiondata.ApClusteringStackData.direct_query(
                    params['clusterid'])
        if 'stackid' in params and params['stackid'] is not None:
            templateq['stack'] = appiondata.ApStackData.direct_query(
                params['stackid'])
        if 'imgnums' in params and params['imgnums'] is not None:
            imgnums = params['imgnums'].split(",")
            templateq['stack_image_number'] = int(imgnums[i])
        templateq['description'] = params['description']
        templateq['REF|projectdata|projects|project'] = params['projectId']
        ## PHP web tools expect 'hidden' field, set it to False initially
        templateq['hidden'] = False
        if params['commit'] is True:
            time.sleep(2)
            templateq.insert()
        else:
            apDisplay.printWarning("Not commiting template to DB")
    return
コード例 #2
0
def isTemplateInDB(md5sum):
    templq = appiondata.ApTemplateImageData()
    templq['md5sum'] = md5sum
    templd = templq.query(results=1)
    if templd:
        return True
    return False
コード例 #3
0
	def getMostRecentTemplates(self, num=3):
		templateq = appiondata.ApTemplateImageData()
		templatedatas = templateq.query(results=num)
		if not templatedatas:
			apDisplay.printError("No templates found")
		templateids = []
		for templatedata in templatedatas:
			templateids.append(templatedata.dbid)
		return templateids