Пример #1
0
    def get_stores(self, names=None, workspaces=None):
        '''
          Returns a list of stores in the catalog. If workspaces is specified will only return stores in those workspaces.
          If names is specified, will only return stores that match.
          names can either be a comma delimited string or an array.
          Will return an empty list if no stores are found.
        '''

        if isinstance(workspaces, Workspace):
            workspaces = [workspaces]
        elif isinstance(workspaces, list) and [w for w in workspaces if isinstance(w, Workspace)]:
            # nothing
            pass
        else:
            workspaces = self.get_workspaces(names=workspaces)

        stores = []
        for ws in workspaces:
            ds_list = self.get_xml(ws.datastore_url)
            cs_list = self.get_xml(ws.coveragestore_url)
            wms_list = self.get_xml(ws.wmsstore_url)
            stores.extend([datastore_from_index(self, ws, n) for n in ds_list.findall("dataStore")])
            stores.extend([coveragestore_from_index(self, ws, n) for n in cs_list.findall("coverageStore")])
            stores.extend([wmsstore_from_index(self, ws, n) for n in wms_list.findall("wmsStore")])

        if names is None:
            names = []
        elif isinstance(names, basestring):
            names = [s.strip() for s in names.split(',') if s.strip()]

        if stores and names:
            return ([store for store in stores if store.name in names])

        return stores
Пример #2
0
 def get_stores(self, workspace=None):
     if workspace is not None:
         if isinstance(workspace, basestring):
             workspace = self.get_workspace(workspace)
         ds_list = self.get_xml(workspace.datastore_url)
         cs_list = self.get_xml(workspace.coveragestore_url)
         wms_list = self.get_xml(workspace.wmsstore_url)
         datastores = [
             datastore_from_index(self, workspace, n)
             for n in ds_list.findall("dataStore")
         ]
         coveragestores = [
             coveragestore_from_index(self, workspace, n)
             for n in cs_list.findall("coverageStore")
         ]
         wmsstores = [
             wmsstore_from_index(self, workspace, n)
             for n in wms_list.findall("wmsStore")
         ]
         return datastores + coveragestores + wmsstores
     else:
         stores = []
         for ws in self.get_workspaces():
             a = self.get_stores(ws)
             stores.extend(a)
         return stores
Пример #3
0
    def get_stores(self, names=None, workspace=None):
        """
          Returns a list of stores in the catalog. If workspace is specified will only return stores in that workspace.
          If names is specified, will only return stores that match.
          names can either be a comma delimited string or an array.
          If names is specified will only return stores that match the name.
          Will return an empty list if no stores are found.
        """

        workspaces = []
        if workspace is not None:
            if isinstance(workspace, basestring):
                ws = self.get_workspaces(workspace)
                if ws:
                    # There can only be one workspace with this name
                    workspaces.append(ws[0])
            elif getattr(
                    workspace, 'resource_type', None
            ) is not None and workspace.resource_type == "workspace":
                workspaces.append(workspace)
        else:
            workspaces = self.get_workspaces()

        stores = []
        if workspaces:
            for ws in workspaces:
                ds_list = self.get_xml(ws.datastore_url)
                cs_list = self.get_xml(ws.coveragestore_url)
                wms_list = self.get_xml(ws.wmsstore_url)
                stores.extend([
                    datastore_from_index(self, ws, n)
                    for n in ds_list.findall("dataStore")
                ])
                stores.extend([
                    coveragestore_from_index(self, ws, n)
                    for n in cs_list.findall("coverageStore")
                ])
                stores.extend([
                    wmsstore_from_index(self, ws, n)
                    for n in wms_list.findall("wmsStore")
                ])

        if names is None:
            names = []
        elif isinstance(names, basestring):
            names = list(map(str.strip, str(names).split(',')))
        if stores and names:
            named_stores = []
            for store in stores:
                if store.name in names:
                    named_stores.append(store)
            return named_stores

        return stores
Пример #4
0
 def get_stores(self, workspace=None):
     if workspace is not None:
         ds_list = self.get_xml(workspace.datastore_url)
         cs_list = self.get_xml(workspace.coveragestore_url)
         datastores = [datastore_from_index(self, workspace, n) for n in ds_list.findall("dataStore")]
         coveragestores = [coveragestore_from_index(self, workspace, n) for n in cs_list.findall("coverageStore")]
         return datastores + coveragestores
     else:
         stores = []
         for ws in self.get_workspaces():
             a = self.get_stores(ws)
             stores.extend(a)
         return stores
Пример #5
0
    def get_store(self, name, workspace=None):
        #stores = [s for s in self.get_stores(workspace) if s.name == name]
        if workspace is None:
            store = None
            for ws in self.get_workspaces():
                found = None
                try:
                    found = self.get_store(name, ws)
                except:
                    # don't expect every workspace to contain the named store
                    pass
                if found:
                    if store:
                        raise AmbiguousRequestError(
                            "Multiple stores found named: " + name)
                    else:
                        store = found
            if not store:
                raise FailedRequestError("No store found named: " + name)
            return store
        else:  # workspace is not None
            if isinstance(workspace, basestring):
                workspace = self.get_workspace(workspace)
                if workspace is None:
                    return None
            logger.debug("datastore url is [%s]", workspace.datastore_url)
            ds_list = self.get_xml(workspace.datastore_url)
            cs_list = self.get_xml(workspace.coveragestore_url)
            datastores = [
                n for n in ds_list.findall("dataStore")
                if n.find("name").text == name
            ]
            coveragestores = [
                n for n in cs_list.findall("coverageStore")
                if n.find("name").text == name
            ]
            ds_len, cs_len = len(datastores), len(coveragestores)

            if ds_len == 1 and cs_len == 0:
                return datastore_from_index(self, workspace, datastores[0])
            elif ds_len == 0 and cs_len == 1:
                return coveragestore_from_index(self, workspace,
                                                coveragestores[0])
            elif ds_len == 0 and cs_len == 0:
                raise FailedRequestError("No store found in " +
                                         str(workspace) + " named: " + name)
            else:
                raise AmbiguousRequestError(
                    str(workspace) + " and name: " + name +
                    " do not uniquely identify a layer")
Пример #6
0
    def get_stores(self, names=None, workspaces=None):
        '''
          Returns a list of stores in the catalog. If workspaces is specified will only return stores in those workspaces.
          If names is specified, will only return stores that match.
          names can either be a comma delimited string or an array.
          Will return an empty list if no stores are found.
        '''

        if workspaces:
            if isinstance(workspaces, Workspace):
                workspaces = [workspaces]
            elif isinstance(workspaces, list) and [
                    w for w in workspaces if isinstance(w, Workspace)
            ]:
                # nothing
                pass
            else:
                workspaces = self.get_workspaces(names=workspaces)
        else:
            workspaces = []

        stores = []
        for ws in workspaces:
            ds_list = self.get_xml(ws.datastore_url)
            cs_list = self.get_xml(ws.coveragestore_url)
            wms_list = self.get_xml(ws.wmsstore_url)
            stores.extend([
                datastore_from_index(self, ws, n)
                for n in ds_list.findall("dataStore")
            ])
            stores.extend([
                coveragestore_from_index(self, ws, n)
                for n in cs_list.findall("coverageStore")
            ])
            stores.extend([
                wmsstore_from_index(self, ws, n)
                for n in wms_list.findall("wmsStore")
            ])

        if names is None:
            names = []
        elif isinstance(names, string_types):
            names = [s.strip() for s in names.split(',') if s.strip()]

        if stores and names:
            return ([store for store in stores if store.name in names])

        return stores
Пример #7
0
 def get_stores(self, workspace=None):
     if workspace is not None:
         if isinstance(workspace, basestring):
             workspace = self.get_workspace(workspace)
         ds_list = self.get_xml(workspace.datastore_url)
         cs_list = self.get_xml(workspace.coveragestore_url)
         wms_list = self.get_xml(workspace.wmsstore_url)
         datastores = [datastore_from_index(self, workspace, n) for n in ds_list.findall("dataStore")]
         coveragestores = [coveragestore_from_index(self, workspace, n) for n in cs_list.findall("coverageStore")]
         wmsstores = [wmsstore_from_index(self, workspace, n) for n in wms_list.findall("wmsStore")]
         return datastores + coveragestores + wmsstores
     else:
         stores = []
         for ws in self.get_workspaces():
             a = self.get_stores(ws)
             stores.extend(a)
         return stores
Пример #8
0
  def get_store(self, name, workspace=None):
      #stores = [s for s in self.get_stores(workspace) if s.name == name]
      if workspace is None:
          store = None
          for ws in self.get_workspaces():
              found = None
              try:
                  found = self.get_store(name, ws)
              except:
                  # don't expect every workspace to contain the named store
                  pass
              if found:
                  if store:
                      raise AmbiguousRequestError("Multiple stores found named: " + name)
                  else:
                      store = found

          if not store:
              raise FailedRequestError("No store found named: " + name)
          return store
      else: # workspace is not None
          logger.debug("datastore url is [%s]", workspace.datastore_url )
          ds_list = self.get_xml(workspace.datastore_url)
          cs_list = self.get_xml(workspace.coveragestore_url)
          ws_list = self.get_xml(workspace.wmsstore_url)
          datastores = [n for n in ds_list.findall("dataStore") if n.find("name").text == name]
          coveragestores = [n for n in cs_list.findall("coverageStore") if n.find("name").text == name]
          wmsstores = [n for n in ws_list.findall("wmsStore") if n.find("name").text == name]
          ds_len, cs_len, ws_len = len(datastores), len(coveragestores), len(wmsstores)

          if ds_len == 1 and cs_len == 0 and ws_len == 0 :
              return datastore_from_index(self, workspace, datastores[0])
          elif ds_len == 0 and cs_len == 1 and ws_len == 0 :
              return coveragestore_from_index(self, workspace, coveragestores[0])
          elif ds_len == 0 and cs_len == 0 and ws_len == 1 :
              return wmsstore_from_index(self, workspace, wmsstores[0])
          elif ds_len == 0 and cs_len == 0 and ws_len == 0 :
              raise FailedRequestError("No store found in " + str(workspace) + " named: " + name)
          else:
              raise AmbiguousRequestError(str(workspace) + " and name: " + name + " do not uniquely identify a layer")
Пример #9
0
def get_store(cat, name, workspace=None):
    # Make sure workspace is a workspace object and not a string.
    # If the workspace does not exist, continue as if no workspace had been defined.
    if isinstance(workspace, str) or isinstance(workspace, six.string_types):
        workspace = cat.get_workspace(workspace)

    if workspace is None:
        workspace = cat.get_default_workspace()

    if workspace:
        try:
            store = cat.get_xml('%s/%s.xml' %
                                (workspace.datastore_url[:-4], name))
        except FailedRequestError:
            try:
                store = cat.get_xml('%s/%s.xml' %
                                    (workspace.coveragestore_url[:-4], name))
            except FailedRequestError:
                try:
                    store = cat.get_xml('%s/%s.xml' %
                                        (workspace.wmsstore_url[:-4], name))
                except FailedRequestError:
                    raise FailedRequestError("No store found named: " + name)
        if store:
            if store.tag == 'dataStore':
                store = datastore_from_index(cat, workspace, store)
            elif store.tag == 'coverageStore':
                store = coveragestore_from_index(cat, workspace, store)
            elif store.tag == 'wmsStore':
                store = wmsstore_from_index(cat, workspace, store)

            return store
        else:
            raise FailedRequestError("No store found named: " + name)
    else:
        raise FailedRequestError("No store found named: " + name)