Beispiel #1
0
    def write_keywords(self, layer, keywords):
        """Write keywords for a datasource.

        This is a wrapper method that will 'do the right thing' to store
        keywords for the given datasource. In particular, if the datasource
        is remote (e.g. a database connection) it will write the keywords from
        the keywords store.

        :param layer: A QGIS QgsMapLayer instance.
        :type layer: QgsMapLayer

        :param keywords: A dict containing all the keywords to be written
              for the layer.
        :type keywords: dict

        :raises: UnsupportedProviderError
        """
        try:
            myFlag = self.are_keywords_file_based(layer)
        except UnsupportedProviderError:
            raise

        mySource = str(layer.source())
        try:
            if myFlag:
                writeKeywordsToFile(mySource, keywords)
            else:
                self.write_keywords_for_uri(mySource, keywords)
            return
        except:
            raise
Beispiel #2
0
    def writeKeywords(self, theLayer, theKeywords):
        """Write keywords for a datasource.
        This is a wrapper method that will 'do the right thing' to store
        keywords for the given datasource. In particular, if the datasource
        is remote (e.g. a database connection) it will write the keywords from
        the keywords store.

        Args:
            * theLayer - A QGIS QgsMapLayer instance.
            * theKeywords - a dict containing all the keywords to be written
              for the layer.
        Returns:
            None.
        Raises:
            None
        """
        mySource = str(theLayer.source())
        myFlag = self.areKeywordsFileBased(theLayer)
        try:
            if myFlag:
                writeKeywordsToFile(mySource, theKeywords)
            else:
                self.writeKeywordsForUri(mySource, theKeywords)
            return
        except:
            raise
Beispiel #3
0
    def writeKeywords(self, theLayer, theKeywords):
        """Write keywords for a datasource.
        This is a wrapper method that will 'do the right thing' to store
        keywords for the given datasource. In particular, if the datasource
        is remote (e.g. a database connection) it will write the keywords from
        the keywords store.

        Args:
            * theLayer - A QGIS QgsMapLayer instance.
            * theKeywords - a dict containing all the keywords to be written
              for the layer.
        Returns:
            None.
        Raises:
            None
        """
        mySource = str(theLayer.source())
        myFlag = self.areKeywordsFileBased(theLayer)
        try:
            if myFlag:
                writeKeywordsToFile(mySource, theKeywords)
            else:
                self.writeKeywordsForUri(mySource, theKeywords)
            return
        except:
            raise
Beispiel #4
0
    def write_keywords(self, layer, keywords):
        """Write keywords for a datasource.

        This is a wrapper method that will 'do the right thing' to store
        keywords for the given datasource. In particular, if the datasource
        is remote (e.g. a database connection) it will write the keywords from
        the keywords store.

        :param layer: A QGIS QgsMapLayer instance.
        :type layer: QgsMapLayer

        :param keywords: A dict containing all the keywords to be written
              for the layer.
        :type keywords: dict

        :raises: UnsupportedProviderError
        """
        try:
            flag = self.are_keywords_file_based(layer)
        except UnsupportedProviderError:
            raise

        source = str(layer.source())
        try:
            if flag:
                writeKeywordsToFile(source, keywords)
            else:
                self.write_keywords_for_uri(source, keywords)
            return
        except:
            raise
Beispiel #5
0
    def copyKeywords(self,
                     theSourceLayer,
                     theDestinationFile,
                     theExtraKeywords=None):
        """Helper to copy the keywords file from a source dataset
        to a destination dataset.

        e.g.::

            copyKeywords('foo.shp', 'bar.shp')

        Will result in the foo.keywords file being copied to bar.keyword.

        Optional argument extraKeywords is a dictionary with additional
        keywords that will be added to the destination file
        e.g::

            copyKeywords('foo.shp', 'bar.shp', {'resolution': 0.01})

        Args:
            * theSourceLayer - A QGIS QgsMapLayer instance.
            * theDestinationFile - the output filename that should be used
              to store the keywords in. It can be a .shp or a .keywords for
              exampled since the suffix will always be replaced with .keywords.
            * theExtraKeywords - a dict containing all the extra keywords to be
              written for the layer. The written keywords will consist of any
              original keywords from the source layer's keywords file and
              and the extra keywords (which will replace the source layers
              keywords if the key is identical).
        Returns:
            None.
        Raises:
            None
        """
        myKeywords = self.readKeywords(theSourceLayer)
        if theExtraKeywords is None:
            theExtraKeywords = {}
        myMessage = self.tr(
            'Expected extraKeywords to be a dictionary. Got %s' %
            str(type(theExtraKeywords))[1:-1])
        verify(isinstance(theExtraKeywords, dict), myMessage)
        # compute the output keywords file name
        myDestinationBase = os.path.splitext(theDestinationFile)[0]
        myNewDestination = myDestinationBase + '.keywords'
        # write the extra keywords into the source dict
        try:
            for key in theExtraKeywords:
                myKeywords[key] = theExtraKeywords[key]
            writeKeywordsToFile(myNewDestination, myKeywords)
        except Exception, e:
            myMessage = self.tr(
                'Failed to copy keywords file from :'
                '\n%s\nto\%s: %s' %
                (theSourceLayer.source(), myNewDestination, str(e)))
            raise Exception(myMessage)
Beispiel #6
0
    def copy_keywords(
            self,
            source_layer,
            destination_file,
            extra_keywords=None):
        """Helper to copy the keywords file from a source to a target dataset.

        e.g.::

            copyKeywords('foo.shp', 'bar.shp')

        Will result in the foo.keywords file being copied to bar.keyword.

        Optional argument extraKeywords is a dictionary with additional
        keywords that will be added to the destination file e.g::

            copyKeywords('foo.shp', 'bar.shp', {'resolution': 0.01})

        :param source_layer: A QGIS QgsMapLayer instance.
        :type source_layer: QgsMapLayer

        :param destination_file: The output filename that should be used
            to store the keywords in. It can be a .shp or a .keywords for
            example since the suffix will always be replaced with .keywords.
        :type destination_file: str

        :param extra_keywords: A dict containing all the extra keywords
            to be written for the layer. The written keywords will consist of
            any original keywords from the source layer's keywords file and
            and the extra keywords (which will replace the source layers
            keywords if the key is identical).
        :type extra_keywords: dict

        """
        keywords = self.read_keywords(source_layer)
        if extra_keywords is None:
            extra_keywords = {}
        message = self.tr(
            'Expected extraKeywords to be a dictionary. Got '
            '%s' % str(type(extra_keywords))[1:-1])
        verify(isinstance(extra_keywords, dict), message)
        # compute the output keywords file name
        destination_base = os.path.splitext(destination_file)[0]
        new_destination = destination_base + '.keywords'
        # write the extra keywords into the source dict
        try:
            for key in extra_keywords:
                keywords[key] = extra_keywords[key]
            writeKeywordsToFile(new_destination, keywords)
        except Exception, e:
            message = self.tr(
                'Failed to copy keywords file from : \n%s\nto\n%s: %s' % (
                source_layer.source(), new_destination, str(e)))
            raise Exception(message)
Beispiel #7
0
    def copy_keywords(self,
                      source_layer,
                      destination_file,
                      extra_keywords=None):
        """Helper to copy the keywords file from a source to a target dataset.

        e.g.::

            copyKeywords('foo.shp', 'bar.shp')

        Will result in the foo.keywords file being copied to bar.keyword.

        Optional argument extraKeywords is a dictionary with additional
        keywords that will be added to the destination file e.g::

            copyKeywords('foo.shp', 'bar.shp', {'resolution': 0.01})

        :param source_layer: A QGIS QgsMapLayer instance.
        :type source_layer: QgsMapLayer

        :param destination_file: The output filename that should be used
            to store the keywords in. It can be a .shp or a .keywords for
            example since the suffix will always be replaced with .keywords.
        :type destination_file: str

        :param extra_keywords: A dict containing all the extra keywords
            to be written for the layer. The written keywords will consist of
            any original keywords from the source layer's keywords file and
            and the extra keywords (which will replace the source layers
            keywords if the key is identical).
        :type extra_keywords: dict

        """
        myKeywords = self.read_keywords(source_layer)
        if extra_keywords is None:
            extra_keywords = {}
        myMessage = self.tr('Expected extraKeywords to be a dictionary. Got '
                            '%s' % str(type(extra_keywords))[1:-1])
        verify(isinstance(extra_keywords, dict), myMessage)
        # compute the output keywords file name
        myDestinationBase = os.path.splitext(destination_file)[0]
        myNewDestination = myDestinationBase + '.keywords'
        # write the extra keywords into the source dict
        try:
            for key in extra_keywords:
                myKeywords[key] = extra_keywords[key]
            writeKeywordsToFile(myNewDestination, myKeywords)
        except Exception, e:
            myMessage = self.tr(
                'Failed to copy keywords file from : \n%s\nto\n%s: %s' %
                (source_layer.source(), myNewDestination, str(e)))
            raise Exception(myMessage)
Beispiel #8
0
    def copyKeywords(self, theSourceLayer,
                     theDestinationFile, theExtraKeywords=None):
        """Helper to copy the keywords file from a source dataset
        to a destination dataset.

        e.g.::

            copyKeywords('foo.shp', 'bar.shp')

        Will result in the foo.keywords file being copied to bar.keyword.

        Optional argument extraKeywords is a dictionary with additional
        keywords that will be added to the destination file
        e.g::

            copyKeywords('foo.shp', 'bar.shp', {'resolution': 0.01})

        Args:
            * theSourceLayer - A QGIS QgsMapLayer instance.
            * theDestinationFile - the output filename that should be used
              to store the keywords in. It can be a .shp or a .keywords for
              exampled since the suffix will always be replaced with .keywords.
            * theExtraKeywords - a dict containing all the extra keywords to be
              written for the layer. The written keywords will consist of any
              original keywords from the source layer's keywords file and
              and the extra keywords (which will replace the source layers
              keywords if the key is identical).
        Returns:
            None.
        Raises:
            None
        """
        myKeywords = self.readKeywords(theSourceLayer)
        if theExtraKeywords is None:
            theExtraKeywords = {}
        myMessage = self.tr('Expected extraKeywords to be a dictionary. Got %s'
               % str(type(theExtraKeywords))[1:-1])
        verify(isinstance(theExtraKeywords, dict), myMessage)
        # compute the output keywords file name
        myDestinationBase = os.path.splitext(theDestinationFile)[0]
        myNewDestination = myDestinationBase + '.keywords'
        # write the extra keywords into the source dict
        try:
            for key in theExtraKeywords:
                myKeywords[key] = theExtraKeywords[key]
            writeKeywordsToFile(myNewDestination, myKeywords)
        except Exception, e:
            myMessage = self.tr('Failed to copy keywords file from :'
                           '\n%s\nto\%s: %s' %
                   (theSourceLayer.source(), myNewDestination, str(e)))
            raise Exception(myMessage)