""" Module that manage the behaviour of source allocated in a ftp """ from tools.protocols.masterProtocol import MasterProtocol from tools import const import json class GJsonVirtual(MasterProtocol): ConnectionError = type('ConnectionError', (Exception,), {}) LoginError = type('LoginError', (Exception,), {}) NotEnoughPrivileges = type('NotEnoughPrivileges', (Exception, ), {}) NoDirectoryOrFile = type('NoDirectoryOrFile', (Exception,), {}) DirectoryOrFileExists = type('DirectoryOrFileExists', (Exception, ), {}) CONNECTION_REQUIRED = {'user': 'user', 'password': 'password', 'ip': 'ip', 'fileType': 'driver_type', 'filePath': 'source', 'domain': 'domain', 'port': 'port', 'layerName': 'layer_name', 'subtype': 'type'} NAME = const.GJSON_VIRTUAL_PROTOC def __init__(self, *_): super().__init__() def exists(self, layer): if 'source' in layer.parameters.keys() and json.loads(layer['source']): return True return False def list_files(self, *_): return ['GeoJson'] def is_file(self, path): return True def gdal_layer(self, layer, with_vsi): return self.gdal_url(layer['source'], with_vsi=with_vsi, driver_prefix=layer.driver.gdal_prefix) def gdal_url(self, source, **__): return source def join(self, *args): return args[0] def mkdir(self, directory, p=False): pass def upload(self, src, dst): pass def upload_dir(self, src_directory, dst_directory): pass def download(self, file, path): with open(path, 'w') as handle: json.dump(json.loads(file), handle) def format_parameters(self, _, parameters): # Format source parameters.update({'source': parameters['source'].replace('\n', '')}) return parameters