# # Make sure it saves the information in the projectDir # To do this on the Python level you have to reset the path # for the urls that indicate the directory locations for the # saved files... # # Alternatively create the project in the right directory to # start with - see convertCns2Pdb # for repository in ccpnProject.repositories: if repository.name in ('userData','backup'): (oldUrlPath,baseName) = uniIo.splitPath((repository.url.path)) newUrlPath = uniIo.joinPath(projectDir,baseName) repository.url = Implementation.Url(path = newUrlPath) # # Create main Tk window for popups # gui = Tkinter.Tk() # # Create an NmrView class and read in the files... create an experiment # for the peak list beforehand and pass in the parameters. #
def getObjDirName(self, metaObj, absoluteName=True): fileName = self.getObjFileName(metaObj, absoluteName=absoluteName) dirName = uniIo.splitPath(fileName)[0] return dirName
# # Make sure it saves the information in the projectDir # To do this on the Python level you have to reset the path # for the urls that indicate the directory locations for the # saved files... # # Alternatively create the project in the right directory to # start with - see convertCns2Pdb # for repository in ccpnProject.repositories: if repository.name in ('userData', 'backup'): (oldUrlPath, baseName) = uniIo.splitPath(repository.url.path) newUrlPath = uniIo.joinPath(projectDir, baseName) repository.url = Implementation.Url(path=newUrlPath) # # Open a Tk window for handling the popups... # root = Tkinter.Tk() # # Create the FormatConverter CnsFormat object # cnsFormat = CnsFormat(ccpnProject, root)
def findDataStoringFromFilepath(project, fullFilePath, preferDataUrls=None, dataLocationStore=None, keepDirectories=1): """ Get DataUrl and relative filePath from normalised absolute filePath Uses heuristics to select compatible DataUrl from existing ones. sisterObjects is a collection of objects with a dataStore link - DataUrls in use for sisterObjects are given preference in the heuristics. uses dataLocationStore or current dataLocationStore If no compatible DataUrl is found the routine returns dataUrl None and the file name plus the lowest keepDirectories directories as the filePath """ # NB fullFilePath *must* be absolute her for code to work properly # if not os.path.isabs(fullFilePath): raise ApiError( "findDataStoringFromFilepath called with non-absolute file name %s" % fullFilePath) # get DataLocationStore if not dataLocationStore: setCurrentStore(project, 'DataLocationStore') dataLocationStore = project.currentDataLocationStore # get DataUrl that match fullFilePath dataUrls = [] for dataUrl in dataLocationStore.dataUrls: dirPath = uniIo.normalisePath(dataUrl.url.path) if fullFilePath.startswith(dirPath): lenPath = len(dirPath) ss = fullFilePath while len(ss) > lenPath: ss, junk = uniIo.splitPath(ss) if ss == dirPath: # DataUrl path matches file path dataUrls.append(dataUrl) # process result if dataUrls: if preferDataUrls: # look for DataUrls that are in use with related objects ll = [x for x in dataUrls if x in preferDataUrls] if ll: dataUrls = ll if len(dataUrls) == 1: # only one DataUrl - use it dataUrl = dataUrls[0] else: # use DataUrl with longest path ll = [(len(dataUrl.url.path), dataUrl) for dataUrl in dataUrls] ll.sort() dataUrl = ll[-1][1] # get filePath ss = uniIo.joinPath(dataUrl.url.path, '') # removes file separator from end filePath = fullFilePath[len(ss) + 1:] else: dataUrl = None ll = [] ss = fullFilePath for dummy in range(keepDirectories + 1): ss, name = os.path.split(ss) ll.append(name) ll.reverse() filePath = uniIo.joinPath(*ll) # return (dataUrl, filePath)