Example #1
0
def removeVersion(endpoint):

    va = sandVersion(endpoint)
    vb = lastVersion(endpoint, -1)

    if va == vb:
        return (False, 'no more removable versions')

    # check exposed version
    if not checkOldSynthax(endpoint):
        return (False, 'Unable to fix service-version.txt')

    ndir = wkd + '/' + endpoint
    if os.path.isfile(ndir + '/service-version.txt'):

        versions = []
        f = open(ndir + '/service-version.txt', 'r')
        versions = f.readlines()
        f.close()

        del versions[-1]
        f = open(ndir + '/service-version.txt', 'w')
        for vi in versions:
            f.write(vi)
        f.close()

    # remove directory
    try:
        shutil.rmtree(vb, ignore_errors=True)
    except:
        return (False, 'unable to remove ' + vb)

    return (True, 'version ' + vb + ' removed OK')
Example #2
0
def removeVersion (endpoint):

    va = sandVersion (endpoint)
    vb = lastVersion (endpoint,-1)

    if va == vb:
        return (False, 'no more removable versions')

    # check exposed version
    if not checkOldSynthax (endpoint):
        return (False, 'Unable to fix service-version.txt')

    ndir = wkd +'/'+endpoint
    if os.path.isfile (ndir+'/service-version.txt'):

        versions = []
        f = open (ndir+'/service-version.txt','r')
        versions = f.readlines()
        f.close()

        del versions[-1]
        f = open (ndir+'/service-version.txt','w')
        for vi in versions:
            f.write (vi)
        f.close()   

    # remove directory
    try:
        shutil.rmtree (vb, ignore_errors=True)
    except:
        return (False, 'unable to remove '+vb)
    
    return (True,'version '+vb+' removed OK')
Example #3
0
def exposeVersion (endpoint, ver, pubver):
    edir = wkd +'/'+endpoint
    
    # check if there is already a tree for this endpoint
    if not os.path.isdir (edir):
        return (False, 'This endpoint does not exists')

    vdir = edir+'/version%0.4d'%ver
    if not os.path.isdir (vdir):
        return (False, 'This model version does not exists')

    # backwards compatibility fix 
    if not checkOldSynthax (endpoint):
        return (False, 'Unable to fix service-version.txt')
    
    t = []
    # read table
    if os.path.isfile (edir+'/service-version.txt'):

        f = open (edir+'/service-version.txt','r')
        while True:
            line = f.readline()
            if line == '' : break
            l = line.split('\t')
            if len (l) < 2:
                return (False, 'Wrong synthax in file service-version.txt. Fix or remove this file')
            t.append(( int(l[0]), int(l[1])))
        f.close()


    #check if this version exists already
    if pubver != 0:
        for ti in t:
            if ti[1] == pubver:
                return (False, 'This public version number has already been asigned. Please unset it firts')

    # edit table
    try:
        t[ver]= ( (ver, pubver) )
    except:
        return (False, 'This model version does not exists')

    # write table
    try:
        f = open (edir+'/service-version.txt','w')
        for ti in t:
            f.write(str(ti[0])+'\t'+str(ti[1])+'\n')
        f.close()
    except:
        return (False, 'unable to create public version file')

    # copy licensing status of this version 
    if os.path.isfile (vdir+'/licensing-status.txt'):
        shutil.copy(vdir+'/licensing-status.txt',edir)
        
        os.chmod(vdir+'/licensing-status.txt',0664)
        os.chmod(edir+'/licensing-status.txt',0664)

    return (True, 'version exposed OK')
Example #4
0
def info(endpoint, ver, style):

    items = []

    itemswkd = os.listdir(wkd)
    itemswkd.sort()
    for iendpoint in itemswkd:

        if not os.path.isdir(wkd + '/' + iendpoint): continue

        if endpoint:
            if iendpoint != endpoint: continue

        tag = ''
        try:
            f = open(wkd + '/' + iendpoint + '/service-label.txt', 'r')
            tag = f.readline()[:-1]
            f.close()
        except:
            pass


##        wsID = -999
##        try:
##            f = open (wkd+'/'+iendpoint+'/service-version.txt','r')
##            wsID = int(f.readline ())
##        except:
##            pass

        pubver = []
        try:
            if not checkOldSynthax(iendpoint):
                raise Exception

            f = open(wkd + '/' + iendpoint + '/service-version.txt', 'r')
            while True:
                line = f.readline()
                if line == '': break
                l = line.split('\t')
                pubver.append(int(l[1]))
            f.close()

        except:
            for i in range(len(itemd)):
                pubver.append(0)

        #print pubver

        print 78 * '-'
        print iendpoint + ' [' + tag + ']'

        itemend = os.listdir(wkd + '/' + iendpoint)
        itemend.sort()

        vi = -99
        for iversion in itemend:

            if not os.path.isdir(wkd + '/' + iendpoint + '/' + iversion):
                continue
            if not iversion.startswith('version'): continue
            vi = int(iversion[-4:])
            if ver > -99:
                if vi != ver: continue

            inform = infoVersion(iendpoint, vi, style, pubver[vi])
            items.append(inform)

        if ver == -1:
            if vi == -99: break  # in case no version was found exit
            inform = infoVersion(iendpoint, vi, style, pubver[vi])
            items.append(inform)

        #print 78*'-'

    correct = 0
    for i in items:
        if i[0]: correct += 1

    if correct == len(items):
        return (True, 'All requested models informed OK')
    else:
        return (False, '%d models found, %d reported correctly' %
                (len(items), correct))
Example #5
0
def publishVersion(endpoint, tag):
    """Top level buildind function

       molecules:  SDFile containing the collection of 2D structures to be predicted
       verID:      version of the model that will be used. Value -1 means the last one

    """

    # clone directory
    va = sandVersion(endpoint)
    vb = nextVersion(endpoint)

    if not va:
        return (False, "No versions directory found")

    if not checkOldSynthax(endpoint):
        return (False, 'Unable to fix service-version.txt')

    shutil.copytree(va, vb)

    if os.path.isfile(wkd + '/' + endpoint + '/service-version.txt'):
        f = open(wkd + '/' + endpoint + '/service-version.txt', 'a')
        f.write(str(int(vb[-4:])) + '\t0\n')
        f.close()

    if os.path.isfile(va + '/info.pkl'):
        modelInfo = open(vb + '/info.pkl', 'rb')
        infoID = pickle.load(modelInfo)
        infoSeries = pickle.load(modelInfo)
        infoMD = pickle.load(modelInfo)
        infoModel = pickle.load(modelInfo)
        infoResult = pickle.load(modelInfo)
        try:
            infoLocal = pickle.load(modelInfo)
        except:
            infoLocal = []
        modelInfo.close()

        for i in range(len(infoID)):
            if infoID[i][0] == 'version':
                infoID.remove(infoID[i])
                infoID.insert(i, ('version', int(vb[-4:])))

        # add the type of endpoint (quantitative or qualitative) after the tag
        # this is needed by views2 to publish appropriately the model type
        ndir = wkd + '/' + endpoint

        if not os.path.isfile(ndir + '/service-label.txt'):
            return (False, 'unable to open service-label.txt file')

        f = open(ndir + '/service-label.txt', 'r')
        tag = f.readline()
        f.close()

        if not tag: tag = 'none'
        infoID.append(('tag', tag[:-1]))

        modelInfo = open(vb + '/info.pkl', 'wb')
        pickle.dump(infoID, modelInfo)
        pickle.dump(infoSeries, modelInfo)
        pickle.dump(infoMD, modelInfo)
        pickle.dump(infoModel, modelInfo)
        pickle.dump(infoResult, modelInfo)
        pickle.dump(infoLocal, modelInfo)
        modelInfo.close()

        f = open(ndir + '/service-label.txt', 'w')
        f.write(tag)
        ytype = 'undefined'
        for i in infoID:
            if 'dependent' in i:
                ytype = i[1]
        f.write(ytype + '\n')
        f.close()

    else:
        ##return (False,"No suitable model found")
        pass

    return (True, vb)
Example #6
0
def exposeVersion(endpoint, ver, pubver):
    edir = wkd + '/' + endpoint

    # check if there is already a tree for this endpoint
    if not os.path.isdir(edir):
        return (False, 'This endpoint does not exists')

    vdir = edir + '/version%0.4d' % ver
    if not os.path.isdir(vdir):
        return (False, 'This model version does not exists')

    # backwards compatibility fix
    if not checkOldSynthax(endpoint):
        return (False, 'Unable to fix service-version.txt')

    t = []
    # read table
    if os.path.isfile(edir + '/service-version.txt'):

        f = open(edir + '/service-version.txt', 'r')
        while True:
            line = f.readline()
            if line == '': break
            l = line.split('\t')
            if len(l) < 2:
                return (
                    False,
                    'Wrong synthax in file service-version.txt. Fix or remove this file'
                )
            t.append((int(l[0]), int(l[1])))
        f.close()

    #check if this version exists already
    if pubver != 0:
        for ti in t:
            if ti[1] == pubver:
                return (
                    False,
                    'This public version number has already been asigned. Please unset it firts'
                )

    # edit table
    try:
        t[ver] = ((ver, pubver))
    except:
        return (False, 'This model version does not exists')

    # write table
    try:
        f = open(edir + '/service-version.txt', 'w')
        for ti in t:
            f.write(str(ti[0]) + '\t' + str(ti[1]) + '\n')
        f.close()
    except:
        return (False, 'unable to create public version file')

    # copy licensing status of this version
    if os.path.isfile(vdir + '/licensing-status.txt'):
        shutil.copy(vdir + '/licensing-status.txt', edir)
    os.chmod(vdir + '/licensing-status.txt', 0664)
    os.chmod(edir + '/licensing-status.txt', 0664)

    return (True, 'version exposed OK')
Example #7
0
def info (endpoint,ver,style):

    items = []
    
    itemswkd = os.listdir(wkd)
    itemswkd.sort()
    for iendpoint in itemswkd:
       
        if not os.path.isdir(wkd+'/'+iendpoint): continue
        
        if endpoint:
            if iendpoint != endpoint: continue

        tag = ''
        try:
            f = open (wkd+'/'+iendpoint+'/service-label.txt','r')
            tag = f.readline ()[:-1]
            f.close()
        except:
            pass

##        wsID = -999     
##        try:
##            f = open (wkd+'/'+iendpoint+'/service-version.txt','r')
##            wsID = int(f.readline ())
##        except:
##            pass

        pubver = []
        try:
            if not checkOldSynthax (iendpoint):
                raise Exception
            
            f = open (wkd+'/'+iendpoint+'/service-version.txt','r')
            while True:
                line = f.readline()
                if line == '' : break
                l = line.split('\t')
                pubver.append(int(l[1]))
            f.close()
            
        except:
            for i in range (len (itemd)):
                pubver.append(0)

        #print pubver
            
        print 78*'-'
        print iendpoint+' ['+tag+']'
        
        itemend = os.listdir(wkd+'/'+iendpoint)
        itemend.sort()

        vi = -99
        for iversion in itemend:
            
            if not os.path.isdir(wkd+'/'+iendpoint+'/'+iversion): continue
            if not iversion.startswith('version'): continue
            vi = int (iversion[-4:])
            if ver>-99:
                if vi != ver: continue
            
            inform = infoVersion(iendpoint, vi, style, pubver[vi])
            items.append (inform)
            
        if ver == -1:
            if vi == -99 : break # in case no version was found exit
            inform = infoVersion(iendpoint, vi, style, pubver[vi])
            items.append (inform)

        #print 78*'-'

    correct = 0
    for i in items:
        if i[0] : correct+=1

    if correct == len(items):
        return (True, 'All requested models informed OK')
    else:
        return (False, '%d models found, %d reported correctly' % (len(items), correct))
Example #8
0
def publishVersion (endpoint, tag):
    """Top level buildind function

       molecules:  SDFile containing the collection of 2D structures to be predicted
       verID:      version of the model that will be used. Value -1 means the last one

    """

    # clone directory
    va = sandVersion (endpoint)
    vb = nextVersion (endpoint)
    
    if not va:
        return (False,"No versions directory found")

    if not checkOldSynthax (endpoint):
            return (False, 'Unable to fix service-version.txt')
        
    shutil.copytree(va,vb)

    if os.path.isfile (wkd +'/'+endpoint+'/service-version.txt'):      
        f = open (wkd +'/'+endpoint+'/service-version.txt','a')
        f.write (str(int(vb[-4:]))+'\t0\n')
        f.close()   

    if os.path.isfile(va+'/info.pkl'):
        modelInfo = open (vb+'/info.pkl','rb')
        infoID = pickle.load(modelInfo)
        infoSeries = pickle.load(modelInfo)
        infoMD = pickle.load(modelInfo)
        infoModel = pickle.load(modelInfo)
        infoResult = pickle.load(modelInfo)        
        try:
            infoLocal=pickle.load(modelInfo)            
        except:
            infoLocal = []             
        modelInfo.close()
        
        for i in range(len(infoID)):
            if infoID[i][0]=='version': 
                infoID.remove (infoID[i])
                infoID.insert (i,('version', int (vb[-4:])))

        # add the type of endpoint (quantitative or qualitative) after the tag
        # this is needed by views2 to publish appropriately the model type
        ndir = wkd +'/'+endpoint

        if not os.path.isfile(ndir+'/service-label.txt'):
            return (False, 'unable to open service-label.txt file')
        
        f = open (ndir+'/service-label.txt','r')
        tag = f.readline()        
        f.close()
        
        if not tag: tag = 'none'
        infoID.append (('tag',tag[:-1]))

        modelInfo = open (vb+'/info.pkl','wb')
        pickle.dump(infoID, modelInfo)
        pickle.dump(infoSeries, modelInfo)
        pickle.dump(infoMD, modelInfo)
        pickle.dump(infoModel, modelInfo)
        pickle.dump(infoResult, modelInfo)
        pickle.dump(infoLocal, modelInfo)
        modelInfo.close()

        f = open (ndir+'/service-label.txt','w')
        f.write (tag)
        ytype='undefined'
        for i in infoID:
            if 'dependent' in i:
                    ytype = i[1]
        f.write (ytype+'\n')
        f.close()

    else:        
        ##return (False,"No suitable model found")
        pass

    return (True, vb)