def __getRemoteFile(self, sourceFilePath, targetFilePath, gatewayHosts, sftp): """ Send local file to remote machine sourceFilePath -- Source file path (/file path/...). targetFilePath -- Target file path (/file path/...). sftp -- sftp connection. """ log.info("Getting " + sourceFilePath + " to " + targetFilePath) # Check if file already existsFilePath and it is up to date existsFilePath = False if exists(targetFilePath): if self.__getRemoteSHA1( sourceFilePath, self.ssh) == self.__getLocalSHA1(targetFilePath): existsFilePath = True log.info(targetFilePath + " already existed") if not existsFilePath: makeFilePath(targetFilePath) try: sftp.get(sourceFilePath, targetFilePath) except IOError as err: log.error("Fail getting remote file " + sourceFilePath + " to local file " + targetFilePath + " - " + str(err)) raise
def __init__(self, filePath=''): """ If filePath is empty string, the general logger is used. """ self._filePath = filePath makeFilePath(self._filePath) if self._filePath not in config['loggers']: config['handlers'][self._filePath] = { 'level': 'NOTSET', 'class': 'logging.handlers.RotatingFileHandler', 'formatter': 'fileFormat', 'filename': self._filePath, 'maxBytes': 100000 } config['loggers'][self._filePath] = { 'handlers': [self._filePath], 'level': 'NOTSET', 'propagate': False } # Note: if we want to see in the console what we also have in # run.log, add 'consoleHandler' to the list of 'handlers'. logging.config.dictConfig(config) self._log = logging.getLogger(self._filePath)
def _writeDoneList(self, micList): """ Write to a text file the items that have been done. """ doneFile = self._getAllDone() if not exists(doneFile): makeFilePath(doneFile) with open(doneFile, 'a') as f: for mic in micList: f.write('%d\n' % mic.getObjId())
def __copyLocalFile(self, sourceFilePath, targetFilePath): """ Send local file to remote machine sourceFilePath -- Source file path (/file path/...). targetFilePath -- Target file path (/file path/...). """ log.info("Copying " + sourceFilePath + " to " + targetFilePath) # Check if file already existsFilePath and it is up to date existsFilePath = False if (exists(targetFilePath)): if ( self.__getLocalSHA1(sourceFilePath) == self.__getLocalSHA1(targetFilePath)): existsFilePath = True log.info(targetFilePath + " already existed") if (not existsFilePath): makeFilePath(targetFilePath) shutil.copy2(sourceFilePath, targetFilePath)
def __copyLocalFile(self, sourceFilePath, targetFilePath): """ Send local file to remote machine sourceFilePath -- Source file path (/file path/...). targetFilePath -- Target file path (/file path/...). """ log.info("Copying " + sourceFilePath + " to " + targetFilePath) # Check if file already existsFilePath and it is up to date existsFilePath = False if exists(targetFilePath): if self.__getLocalSHA1(sourceFilePath) == self.__getLocalSHA1( targetFilePath): existsFilePath = True log.info(targetFilePath + " already existed") if not existsFilePath: makeFilePath(targetFilePath) shutil.copy2(sourceFilePath, targetFilePath)
def __getRemoteFile(self, sourceFilePath, targetFilePath, gatewayHosts, sftp): """ Send local file to remote machine sourceFilePath -- Source file path (/file path/...). targetFilePath -- Target file path (/file path/...). sftp -- sftp connection. """ log.info("Getting " + sourceFilePath + " to " + targetFilePath) # Check if file already existsFilePath and it is up to date existsFilePath = False if (exists(targetFilePath)): if ( self.__getRemoteSHA1(sourceFilePath, self.ssh) == self.__getLocalSHA1(targetFilePath)): existsFilePath = True log.info(targetFilePath + " already existed") if (not existsFilePath): makeFilePath(targetFilePath) try: sftp.get(sourceFilePath, targetFilePath) except IOError as err: log.error("Fail getting remote file " + sourceFilePath + " to local file " + targetFilePath + " - " + str(err)) raise
def __init__(self, filePath=''): """ If filePath is empty string, the general logger is used. """ self._filePath = filePath makeFilePath(self._filePath) if self._filePath not in config['loggers']: config['handlers'][self._filePath] = { 'level': 'NOTSET', 'class': 'logging.handlers.RotatingFileHandler', 'formatter': 'fileFormat', 'filename': self._filePath, 'maxBytes': 100000} config['loggers'][self._filePath] = { 'handlers': [self._filePath], 'level': 'NOTSET', 'propagate': False} # Note: if we want to see in the console what we also have in # run.log, add 'consoleHandler' to the list of 'handlers'. logging.config.dictConfig(config) self._log = logging.getLogger(self._filePath)
def getFile(self, remoteFile, localFile): """ Wrapper around sftp.get that ensures path exists for localFile. """ makeFilePath(localFile) self.sftp.get(remoteFile, localFile)