class FtpRepository(Repository): def __init__(self, ip, username, password, timeout): self.connection = Ftp(ip, username, password, timeout) def publish(self, name, raster_file): with self.connection: self.connection.create_directory_if_not_exists(name) self.connection.upload_file(raster_file, join(name, basename(raster_file)))
class FtpRepository(Repository): def __init__(self, host, username, password, timeout, path=''): self.path = path self.connection = Ftp(host, username, password, timeout) def publish(self, name, raster_file): directory = join(self.path, name) with self.connection: self.connection.create_directory_if_not_exists(directory) self.connection.upload_file(raster_file, join(directory, basename(raster_file)))
class ProcessesGateway(object): def __init__(self, host, user, password, timeout, directory): self.connection = Ftp(host, user, password, timeout) self.remote_directory = directory def add(self, identifier, process_file_path): with self.connection: process_directory = self._get_remote_process_directory(identifier) remote_file_path = join(process_directory, basename(process_file_path)) self.connection.create_directory_if_not_exists( self.remote_directory) self.connection.create_directory_if_not_exists(process_directory) self.connection.upload_file(process_file_path, remote_file_path) def get(self, identifier, local_directory): remote_process_dir = self._get_remote_process_directory(identifier) local_process_dir = join(local_directory, identifier) self._create_local_directory(local_process_dir) with self.connection: self.connection.download_directory_contents( remote_process_dir, local_process_dir) return local_process_dir def remove(self, identifier): with self.connection: self.connection.delete_non_empty_directory( self._get_remote_process_directory(identifier)) def get_process_context(self, identifier, local_directory): local_directory = self.get(identifier, local_directory) return ProcessContext(identifier, local_directory) def _get_remote_process_directory(self, identifier): return join(self.remote_directory, identifier) @staticmethod def _create_local_directory(directory): if not exists(directory): makedirs(directory)