def upload_file(self, local_filename: str, dest_filename: str, serverdir: str) -> str: """ Upload a file to koji :return: str, pathname on server """ self.log.debug("uploading %r to %r as %r", local_filename, serverdir, dest_filename) kwargs = {} if self.blocksize is not None: kwargs['blocksize'] = self.blocksize self.log.debug("using blocksize %d", self.blocksize) callback = KojiUploadLogger(self.log).callback self.session.uploadWrapper(local_filename, serverdir, name=dest_filename, callback=callback, **kwargs) # In case dest_filename includes path. uploadWrapper can handle this by itself. path = os.path.join(serverdir, os.path.basename(dest_filename)) self.log.debug("uploaded %r", path) return path
def test_with_defaults(self, totalsize, step, expected_times): logger = flexmock() logger.should_receive('debug').times(expected_times) upload_logger = KojiUploadLogger(logger) upload_logger.callback(0, totalsize, 0, 0, 0) for offset in range(step, totalsize + step, step): upload_logger.callback(offset, totalsize, step, 1.0, 1.0)
def upload_file(self, session, output, serverdir): """ Upload a file to koji :return: str, pathname on server """ name = output.metadata['filename'] self.log.debug("uploading %r to %r as %r", output.file.name, serverdir, name) kwargs = {} if self.blocksize is not None: kwargs['blocksize'] = self.blocksize self.log.debug("using blocksize %d", self.blocksize) upload_logger = KojiUploadLogger(self.log) session.uploadWrapper(output.file.name, serverdir, name=name, callback=upload_logger.callback, **kwargs) path = os.path.join(serverdir, name) self.log.debug("uploaded %r", path) return path
def test_with_notable(self, totalsize, step, notable, expected_times): logger = flexmock() logger.should_receive('debug').times(expected_times) upload_logger = KojiUploadLogger(logger, notable_percent=notable) for offset in range(0, totalsize + step, step): upload_logger.callback(offset, totalsize, step, 1.0, 1.0)
def test_with_zero(self, totalsize): logger = flexmock() logger.should_receive('debug').once() upload_logger = KojiUploadLogger(logger) upload_logger.callback(0, totalsize, 0, 0, 0)