Skip to content
Snippets Groups Projects
Commit 1c80b680 authored by sveseli's avatar sveseli
Browse files

added replacement of storage directory with data directory for the purpose of...

added replacement of storage directory with data directory for the purpose of comparing original and storage file directory
parent 838fe8c7
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ class GridftpFileTransferPlugin(FileTransferPlugin): ...@@ -48,7 +48,7 @@ class GridftpFileTransferPlugin(FileTransferPlugin):
ftpUtility = SftpUtility(storageHost) ftpUtility = SftpUtility(storageHost)
self.logger.debug("STORAGE DIR: %s", storageDirectory) self.logger.debug("STORAGE DIR: %s", storageDirectory)
self.logger.debug("STORAGE HOST: %s", storageHost) self.logger.debug("STORAGE HOST: %s", storageHost)
storageFilePathsDict = ftpUtility.getFiles(storageDirectory, {}) storageFilePathsDict = ftpUtility.getFiles(storageDirectory, {}, dataDIrectory)
self.logger.debug("STORAGE PATHS: %s", storageFilePathsDict) self.logger.debug("STORAGE PATHS: %s", storageFilePathsDict)
self.logger.debug("ORIG PATHS: %s", filePathsDict) self.logger.debug("ORIG PATHS: %s", filePathsDict)
pluginFilePathsDict = {} pluginFilePathsDict = {}
......
...@@ -92,21 +92,24 @@ class FtpUtility: ...@@ -92,21 +92,24 @@ class FtpUtility:
del fileStatDict['Modify'] del fileStatDict['Modify']
del fileStatDict['Type'] del fileStatDict['Type']
def getFiles(self, dirPath, fileDict={}): def getFiles(self, dirPath, fileDict={}, replacementDirPath=None):
if not self.ftpClient: if not self.ftpClient:
self.ftpClient = self.getFtpClient(self.host, self.port, self.username, self.password) self.ftpClient = self.getFtpClient(self.host, self.port, self.username, self.password)
# Need these to be class members for the callback function # Need these to be class members for the callback function
self.mlsdFileDict = {} self.mlsdFileDict = {}
self.mlsdDirList = [] self.mlsdDirList = []
self.ftpClient.retrlines('MLSD %s' % dirPath, self.__parseMlsdOutput) self.ftpClient.retrlines('MLSD %s' % dirPath, self.__parseMlsdOutput)
if not replacementDirPath:
replacementDirPath = dirPath
for (fileName,fileInfo) in self.mlsdFileDict.items(): for (fileName,fileInfo) in self.mlsdFileDict.items():
self.__processFileStatDict(fileInfo) self.__processFileStatDict(fileInfo)
del fileInfo['Name'] del fileInfo['Name']
filePath = '%s/%s' % (dirPath, fileName) filePath = '%s/%s' % (replacementDirPath, fileName)
fileDict[filePath] = fileInfo fileDict[filePath] = fileInfo
for d in copy.copy(self.mlsdDirList): for d in copy.copy(self.mlsdDirList):
dirPath2 = '%s/%s' % (dirPath,d) dirPath2 = '%s/%s' % (dirPath,d)
self.getFiles(dirPath2,fileDict) replacementDirPath2 = '%s/%s' % (replacementDirPath,d)
self.getFiles(dirPath2,fileDict, replacementDirPath2)
return fileDict return fileDict
def getMd5Sum(self, filePath, fileInfo={}): def getMd5Sum(self, filePath, fileInfo={}):
...@@ -136,5 +139,7 @@ if __name__ == '__main__': ...@@ -136,5 +139,7 @@ if __name__ == '__main__':
ftpUtility = FtpUtility('s8dserv', 2811) ftpUtility = FtpUtility('s8dserv', 2811)
files = ftpUtility.getFiles('/export/8-id-i/test') files = ftpUtility.getFiles('/export/8-id-i/test')
print files print files
files = ftpUtility.getFiles('/export/8-id-i/test', replacementDirPath='/data/testing/8-id-i')
print files
print ftpUtility.getMd5Sum('/export/8-id-i/test/testfile01') print ftpUtility.getMd5Sum('/export/8-id-i/test/testfile01')
print ftpUtility.statFile('/export/8-id-i/test/testfile01') print ftpUtility.statFile('/export/8-id-i/test/testfile01')
...@@ -51,23 +51,26 @@ class SftpUtility: ...@@ -51,23 +51,26 @@ class SftpUtility:
outputDict[key] = value outputDict[key] = value
return outputDict return outputDict
def getFiles(self, dirPath, fileDict={}): def getFiles(self, dirPath, fileDict={}, replacementDirPath=None):
if not self.sftpClient: if not self.sftpClient:
self.sftpClient = self.getSftpClient(self.host, self.port, self.username, self.password) self.sftpClient = self.getSftpClient(self.host, self.port, self.username, self.password)
# Need these to be class members for the callback function if not replacementDirPath:
replacementDirPath = dirPath
attrs = self.sftpClient.listdir_attr(dirPath) attrs = self.sftpClient.listdir_attr(dirPath)
mode = attrs[0].st_mode mode = attrs[0].st_mode
for attr in attrs: for attr in attrs:
fileName = attr.filename fileName = attr.filename
mode = attr.st_mode mode = attr.st_mode
fullPath = '%s/%s' % (dirPath, fileName)
if stat.S_ISDIR(mode): if stat.S_ISDIR(mode):
self.getFiles(fullPath, fileDict) dirPath2 = '%s/%s' % (dirPath, fileName)
replacementDirPath2 = '%s/%s' % (replacementDirPath, fileName)
self.getFiles(dirPath2, fileDict, replacementDirPath2)
elif stat.S_ISREG(mode): elif stat.S_ISREG(mode):
fileInfo = {'filePath' : fullPath, 'fileSize' : attr.st_size, filePath = '%s/%s' % (replacementDirPath, fileName)
fileInfo = {'fileSize' : attr.st_size,
'fileModificationTime' : attr.st_mtime } 'fileModificationTime' : attr.st_mtime }
fileInfo['fileModificationTimeStamp'] = TimeUtility.formatLocalTimeStamp(attr.st_mtime) fileInfo['fileModificationTimeStamp'] = TimeUtility.formatLocalTimeStamp(attr.st_mtime)
fileDict[fullPath] = fileInfo fileDict[filePath] = fileInfo
return fileDict return fileDict
####################################################################### #######################################################################
...@@ -77,3 +80,5 @@ if __name__ == '__main__': ...@@ -77,3 +80,5 @@ if __name__ == '__main__':
sftpUtility = SftpUtility('xstor-devel', username='dmadmin') sftpUtility = SftpUtility('xstor-devel', username='dmadmin')
files = sftpUtility.getFiles('/data/testing/test1') files = sftpUtility.getFiles('/data/testing/test1')
print files print files
files = sftpUtility.getFiles('/data/testing/test1', replacementDirPath='/xyz/ccc')
print files
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment