<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> import geoserver . workspace as ws <EOL> from geoserver . resource import featuretype_from_index , coverage_from_index , wmslayer_from_index <EOL> from geoserver . support import ResourceInfo , xml_property , key_value_pairs , write_bool , write_dict , write_string , url <EOL> def datastore_from_index ( catalog , workspace , node ) : <EOL> name = node . find ( "<STR_LIT:name>" ) <EOL> return DataStore ( catalog , workspace , name . text ) <EOL> def coveragestore_from_index ( catalog , workspace , node ) : <EOL> name = node . find ( "<STR_LIT:name>" ) <EOL> return CoverageStore ( catalog , workspace , name . text ) <EOL> def wmsstore_from_index ( catalog , workspace , node ) : <EOL> name = node . find ( "<STR_LIT:name>" ) <EOL> return WmsStore ( catalog , workspace , name . text , None , None ) <EOL> class DataStore ( ResourceInfo ) : <EOL> resource_type = "<STR_LIT>" <EOL> save_method = "<STR_LIT>" <EOL> def __init__ ( self , catalog , workspace , name ) : <EOL> super ( DataStore , self ) . __init__ ( ) <EOL> assert isinstance ( workspace , ws . Workspace ) <EOL> assert isinstance ( name , basestring ) <EOL> self . catalog = catalog <EOL> self . workspace = workspace <EOL> self . name = name <EOL> @ property <EOL> def href ( self ) : <EOL> return url ( self . catalog . service_url , <EOL> [ "<STR_LIT>" , self . workspace . name , "<STR_LIT>" , self . name + "<STR_LIT>" ] ) <EOL> enabled = xml_property ( "<STR_LIT>" , lambda x : x . text == "<STR_LIT:true>" ) <EOL> name = xml_property ( "<STR_LIT:name>" ) <EOL> type = xml_property ( "<STR_LIT:type>" ) <EOL> connection_parameters = xml_property ( "<STR_LIT>" , key_value_pairs ) <EOL> writers = dict ( enabled = write_bool ( "<STR_LIT>" ) , <EOL> name = write_string ( "<STR_LIT:name>" ) , <EOL> type = write_string ( "<STR_LIT:type>" ) , <EOL> connectionParameters = write_dict ( "<STR_LIT>" ) ) <EOL> @ property <EOL> def resource_url ( self ) : <EOL> return url ( self . catalog . service_url , <EOL> [ "<STR_LIT>" , self . workspace . name , "<STR_LIT>" , self . name , "<STR_LIT>" ] ) <EOL> def get_resources ( self , name = None , available = False ) : <EOL> res_url = self . resource_url <EOL> if available : <EOL> res_url += "<STR_LIT>" <EOL> xml = self . catalog . get_xml ( res_url ) <EOL> def ft_from_node ( node ) : <EOL> return featuretype_from_index ( self . catalog , self . workspace , self , node ) <EOL> if name is not None : <EOL> for node in xml . findall ( "<STR_LIT>" ) : <EOL> if node . findtext ( "<STR_LIT:name>" ) == name : <EOL> return ft_from_node ( node ) <EOL> return None <EOL> if available : <EOL> return [ str ( node . text ) for node in xml . findall ( "<STR_LIT>" ) ] <EOL> else : <EOL> return [ ft_from_node ( node ) for node in xml . findall ( "<STR_LIT>" ) ] <EOL> class UnsavedDataStore ( DataStore ) : <EOL> save_method = "<STR_LIT:POST>" <EOL> def __init__ ( self , catalog , name , workspace ) : <EOL> super ( UnsavedDataStore , self ) . __init__ ( catalog , workspace , name ) <EOL> self . dirty . update ( dict ( <EOL> name = name , enabled = True , type = None , <EOL> connectionParameters = dict ( ) ) ) <EOL> @ property <EOL> def href ( self ) : <EOL> path = [ "<STR_LIT>" , <EOL> self . workspace . name , "<STR_LIT>" ] <EOL> query = dict ( name = self . name ) <EOL> return url ( self . catalog . service_url , path , query ) <EOL> class CoverageStore ( ResourceInfo ) : <EOL> resource_type = '<STR_LIT>' <EOL> save_method = "<STR_LIT>" <EOL> def __init__ ( self , catalog , workspace , name ) : <EOL> super ( CoverageStore , self ) . __init__ ( ) <EOL> assert isinstance ( workspace , ws . Workspace ) <EOL> assert isinstance ( name , basestring ) <EOL> self . catalog = catalog <EOL> self . workspace = workspace <EOL> self . name = name <EOL> @ property <EOL> def href ( self ) : <EOL> return url ( self . catalog . service_url , <EOL> [ "<STR_LIT>" , self . workspace . name , "<STR_LIT>" , self . name + "<STR_LIT>" ] ) <EOL> enabled = xml_property ( "<STR_LIT>" , lambda x : x . text == "<STR_LIT:true>" ) <EOL> name = xml_property ( "<STR_LIT:name>" ) <EOL> url = xml_property ( "<STR_LIT:url>" ) <EOL> type = xml_property ( "<STR_LIT:type>" ) <EOL> writers = dict ( enabled = write_bool ( "<STR_LIT>" ) , <EOL> name = write_string ( "<STR_LIT:name>" ) , <EOL> url = write_string ( "<STR_LIT:url>" ) , <EOL> type = write_string ( "<STR_LIT:type>" ) , <EOL> workspace = write_string ( "<STR_LIT>" ) ) <EOL> def get_resources ( self , name = None ) : <EOL> res_url = url ( self . catalog . service_url , <EOL> [ "<STR_LIT>" , self . workspace . name , "<STR_LIT>" , self . name , "<STR_LIT>" ] ) <EOL> xml = self . catalog . get_xml ( res_url ) <EOL> def cov_from_node ( node ) : <EOL> return coverage_from_index ( self . catalog , self . workspace , self , node ) <EOL> if name is not None : <EOL> for node in xml . findall ( "<STR_LIT>" ) : <EOL> if node . findtext ( "<STR_LIT:name>" ) == name : <EOL> return cov_from_node ( node ) <EOL> return None <EOL> return [ cov_from_node ( node ) for node in xml . findall ( "<STR_LIT>" ) ] <EOL> class UnsavedCoverageStore ( CoverageStore ) : <EOL> save_method = "<STR_LIT:POST>" <EOL> def __init__ ( self , catalog , name , workspace ) : <EOL> super ( UnsavedCoverageStore , self ) . __init__ ( catalog , workspace , name ) <EOL> self . dirty . update ( name = name , enabled = True , type = "<STR_LIT>" , <EOL> url = "<STR_LIT>" , workspace = workspace . name if workspace else None ) <EOL> @ property <EOL> def href ( self ) : <EOL> return url ( self . catalog . service_url , <EOL> [ "<STR_LIT>" , self . workspace . name , "<STR_LIT>" ] , dict ( name = self . name ) ) <EOL> class WmsStore ( ResourceInfo ) : <EOL> resource_type = "<STR_LIT>" <EOL> save_method = "<STR_LIT>" <EOL> def __init__ ( self , catalog , workspace , name , user , password ) : <EOL> super ( WmsStore , self ) . __init__ ( ) <EOL> assert isinstance ( workspace , ws . Workspace ) <EOL> assert isinstance ( name , basestring ) <EOL> self . catalog = catalog <EOL> self . workspace = workspace <EOL> self . name = name <EOL> self . metadata = { } <EOL> self . metadata [ '<STR_LIT:user>' ] = user <EOL> self . metadata [ '<STR_LIT:password>' ] = password <EOL> @ property <EOL> def href ( self ) : <EOL> return "<STR_LIT>" % ( self . catalog . service_url , self . workspace . name , self . name ) <EOL> enabled = xml_property ( "<STR_LIT>" , lambda x : x . text == "<STR_LIT:true>" ) <EOL> name = xml_property ( "<STR_LIT:name>" ) <EOL> nativeName = xml_property ( "<STR_LIT>" ) <EOL> capabilitiesURL = xml_property ( "<STR_LIT>" ) <EOL> type = xml_property ( "<STR_LIT:type>" ) <EOL> metadata = xml_property ( "<STR_LIT>" , key_value_pairs ) <EOL> writers = dict ( enabled = write_bool ( "<STR_LIT>" ) , <EOL> name = write_string ( "<STR_LIT:name>" ) , <EOL> capabilitiesURL = write_string ( "<STR_LIT>" ) , <EOL> type = write_string ( "<STR_LIT:type>" ) , <EOL> metadata = write_dict ( "<STR_LIT>" ) ) <EOL> def get_resources ( self , name = None , available = False ) : <EOL> res_url = "<STR_LIT>" % ( <EOL> self . catalog . service_url , <EOL> self . workspace . name , <EOL> self . name <EOL> ) <EOL> layer_name_attr = "<STR_LIT>" <EOL> if available : <EOL> res_url += "<STR_LIT>" <EOL> layer_name_attr += '<STR_LIT:Name>' <EOL> xml = self . catalog . get_xml ( res_url ) <EOL> def wl_from_node ( node ) : <EOL> return wmslayer_from_index ( self . catalog , self . workspace , self , node ) <EOL> if name is not None : <EOL> for node in xml . findall ( layer_name_attr ) : <EOL> if node . findtext ( "<STR_LIT:name>" ) == name : <EOL> return wl_from_node ( node ) <EOL> return None <EOL> if available : <EOL> return [ str ( node . text ) for node in xml . findall ( layer_name_attr ) ] <EOL> else : <EOL> return [ wl_from_node ( node ) for node in xml . findall ( layer_name_attr ) ] <EOL> class UnsavedWmsStore ( WmsStore ) : <EOL> save_method = "<STR_LIT:POST>" <EOL> def __init__ ( self , catalog , name , workspace , user , password ) : <EOL> super ( UnsavedWmsStore , self ) . __init__ ( catalog , workspace , name , user , password ) <EOL> metadata = { } <EOL> if user is not None and password is not None : <EOL> metadata [ '<STR_LIT:user>' ] = user <EOL> metadata [ '<STR_LIT:password>' ] = password <EOL> self . dirty . update ( dict ( <EOL> name = name , enabled = True , capabilitiesURL = "<STR_LIT>" , type = "<STR_LIT>" , metadata = metadata ) ) <EOL> @ property <EOL> def href ( self ) : <EOL> return "<STR_LIT>" % ( self . catalog . service_url , self . workspace . name , self . name ) </s>
