def connect(self): if not os.path.isdir(self.MainDir): raise __QS_Error__("不存在主目录: %s!" % self.MainDir) AllTables = listDirDir(self.MainDir) _TableFactorDict = {} if not os.path.isfile(self.MainDir + os.sep + "LockFile"): open(self.MainDir + os.sep + "LockFile", mode="a").close() self._LockFile = self.MainDir + os.sep + "LockFile" self._DataLock = fasteners.InterProcessLock(self._LockFile) with self._DataLock: for iTable in AllTables: iTablePath = self.MainDir + os.sep + iTable iFactors = set(listDirFile(iTablePath, suffix=self._Suffix)) if not iFactors: continue try: iDataType = readNestedDictFromHDF5( iTablePath + os.sep + "_TableInfo.h5", "/DataType") except: iDataType = None if (iDataType is None) or (iFactors != set(iDataType.index)): iDataType = {} for ijFactor in iFactors: with h5py.File(iTablePath + os.sep + ijFactor + "." + self._Suffix, mode="r") as ijDataFile: iDataType[ijFactor] = ijDataFile.attrs["DataType"] iDataType = pd.Series(iDataType) writeNestedDict2HDF5(iDataType, iTablePath + os.sep + "_TableInfo.h5", "/DataType") _TableFactorDict[iTable] = iDataType self._TableFactorDict = _TableFactorDict self._isAvailable = True return 0
def connect(self): if not os.path.isdir(self.MainDir): raise __QS_Error__("不存在主目录: %s!" % self.MainDir) AllTables = listDirDir(self.MainDir) _TableFactorDict = {} with self._DataLock: for iTable in AllTables: iTablePath = self.MainDir+os.sep+iTable iZTable = zarr.open(iTablePath, mode="r") iDataType = pd.Series(iZTable.attrs.get("DataType", {})).sort_index() if iDataType.shape[0]==0: continue _TableFactorDict[iTable] = iDataType self._TableFactorDict = _TableFactorDict self._isAvailable = True return 0
def TableNames(self): return sorted(listDirDir(self.MainDir))