Пример #1
0
 def testIsRootDirectory(self):
     self.assertTrue( isRootDirectory("linkNmrStarData/"))
     self.assertTrue( isRootDirectory("linkNmrStarData//"))
     self.assertFalse( isRootDirectory("linkNmrStarData/ccp/"))
     self.assertFalse( isRootDirectory("linkNmrStarData/ccp//"))
Пример #2
0
def initCyana(project, cyanaFolder, modelCount = None, convention=None, coordinateConvention=None, autoDetectFormat=True):
    """
    Return True on success or None on failure
    cyanaFolder can be a directory or a .tgz.
    """
#    nTdebug("In %s found convention %s" % ( getCallerName(), convention))
    if not cyanaFolder:
        nTerror("cyanaFolder not specified")
        return None
    # end if
    if not os.path.exists( cyanaFolder ):
        nTerror('initCyana: cyanaFolder "%s" does not exist', cyanaFolder)
        return None
    # end if    
    if os.path.isfile(cyanaFolder) and ( cyanaFolder.endswith(".tgz") or cyanaFolder.endswith(".tar.gz")):
        try: # If present the target will be removed so it doesn't need to be overwritten.
            rmtree(project.name)
            nTmessage("Removed directory: %s" % project.name)
        except:
            pass
        # Get a TarFile class.
        cyanaRootDirectory = None
        tar = tarfile.open(cyanaFolder, "r:gz")
        tarFileNames = []
        for itar in tar:
#            nTdebug("working on: " + itar.name)
            if os.path.exists(itar.name):
                nTerror("Will not untar %s by overwriting current copy" % itar.name)
                return None
            if itar.name.count('._'):
#                nTdebug("Skipping special hidden file: " + itar.name)
                continue
            tar.extract(itar.name, '.') # itar is a TarInfo object
            if not cyanaRootDirectory: # pick only the first one.
                tarFileNames.append(itar.name)
                if isRootDirectory(itar.name):
                    cyanaRootDirectory = itar.name.replace("/", '')
                    if not cyanaRootDirectory:
                        nTerror("Skipping potential cyanaRootDirectory")
                    # end if            
                # end if            
            # end if            
        # end for
        tar.close()        
        if not cyanaRootDirectory:
            # in python 2.6 tarfile class doesn't append '/' in root dir anymore
            # sorting by length and taking the shortest, likely the root dir.
            tarFileNames.sort()
            cyanaRootDirectory = tarFileNames[0]
            if not os.path.isdir(cyanaRootDirectory):
                nTerror("No cyanaRootDirectory found in gzipped tar file: %s" % cyanaFolder)
                nTerror("First listed directory after sorting: %s" % cyanaRootDirectory)
                return None
            # end if
        # end if                
        if cyanaRootDirectory != project.name:
            nTmessage("Moving Cyana directory from [%s] to [%s]" % (cyanaRootDirectory, project.name))
            move(cyanaRootDirectory, project.name)
        # end if
        cyanaFolder = project.name # Now it is a folder.
    # end if
    if not os.path.exists(cyanaFolder):
        nTerror("cyanaFolder '%s' not found", cyanaFolder)
        return None
    # end if
    if not os.path.isdir(cyanaFolder):
        nTerror("cyanaFolder '%s' not not a directory", cyanaFolder)
        return None
    # end if
    sourceList = cyana2cing( project, cyanaFolder, 
                             convention=convention, coordinateConvention=coordinateConvention, 
                             useAllInDirectory=True, autoDetectFormat=autoDetectFormat)    
    return sourceList
Пример #3
0
 def testIsRootDirectory(self):
     self.assertTrue(isRootDirectory("linkNmrStarData/"))
     self.assertTrue(isRootDirectory("linkNmrStarData//"))
     self.assertFalse(isRootDirectory("linkNmrStarData/ccp/"))
     self.assertFalse(isRootDirectory("linkNmrStarData/ccp//"))