Beispiel #1
0
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """
        warning = ""

        # Check that parameter SpatialDataFolder is a non-empty, non-None string.
        # - existence of the folder will also be checked in run_command().
        pv_SpatialDataFolder = self.get_parameter_value(
            parameter_name='SpatialDataFolder',
            command_parameters=command_parameters)

        if not validators.validate_string(pv_SpatialDataFolder, False, False):
            message = "SpatialDataFolder parameter has no value."
            recommendation = "Specify text for the SpatialDataFolder parameter to indicate the file geodatabase."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional parameter IfGeoLayerIDExists is either `Replace`, `ReplaceAndWarn`, `Warn`, `Fail`, None.
        pv_IfGeoLayerIDExists = self.get_parameter_value(
            parameter_name="IfGeoLayerIDExists",
            command_parameters=command_parameters)
        acceptable_values = ["Replace", "ReplaceAndWarn", "Warn", "Fail"]
        if not validators.validate_string_in_list(pv_IfGeoLayerIDExists,
                                                  acceptable_values,
                                                  none_allowed=True,
                                                  empty_string_allowed=True,
                                                  ignore_case=True):
            message = "IfGeoLayerIDExists parameter value ({}) is not recognized.".format(
                pv_IfGeoLayerIDExists)
            recommendation = "Specify one of the acceptable values ({}) for the IfGeoLayerIDExists parameter.".format(
                acceptable_values)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that the optional parameter ReadOnlyOneFeatureClass is a valid Boolean.
        pv_ReadOnlyOneFeatureClass = self.get_parameter_value(
            parameter_name="ReadOnlyOneFeatureClass",
            command_parameters=command_parameters)
        if not validators.validate_bool(pv_ReadOnlyOneFeatureClass, True,
                                        False):
            message = "ReadOnlyOneFeatureClass is not a valid boolean value."
            recommendation = "Specify a valid boolean value for the ReadOnlyOneFeatureClass parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Continue with checks if the ReadOnlyOneFeatureClass is a valid TRUE Boolean.
        elif string_util.str_to_bool(pv_ReadOnlyOneFeatureClass):

            # Check that parameter GeoLayerID is a non-empty, non-None string.
            pv_GeoLayerID = self.get_parameter_value(
                parameter_name='GeoLayerID',
                command_parameters=command_parameters)

            if not validators.validate_string(pv_GeoLayerID, False, False):
                message = "GeoLayerID parameter has no value."
                recommendation = "Specify the GeoLayerID parameter."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        else:
            # Refresh the phase severity
            self.command_status.refresh_phase_severity(
                CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """
        warning = ""

        # Check that either the parameter File is a non-empty, non-None string.
        pv_File = self.get_parameter_value(
            parameter_name='File', command_parameters=command_parameters)

        if not validators.validate_string(pv_File, False, False):

            message = "File parameter has no value."
            recommendation = "Specify the File parameter to indicate the compressed file to extract."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional parameter FileType is an acceptable value or is None.
        pv_FileType = self.get_parameter_value(
            parameter_name="FileType", command_parameters=command_parameters)

        acceptable_values = ["Zip", "Tar"]

        if not validators.validate_string_in_list(pv_FileType,
                                                  acceptable_values,
                                                  none_allowed=True,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):
            message = "FileType parameter value ({}) is not recognized.".format(
                pv_FileType)
            recommendation = "Specify one of the acceptable values ({}) for the" \
                             " FileType parameter.".format(acceptable_values)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional DeleteFile parameter value is a valid Boolean value or is None.
        pv_DeleteFile = self.get_parameter_value(
            parameter_name="DeleteFile", command_parameters=command_parameters)

        if not validators.validate_bool(
                pv_DeleteFile, none_allowed=True, empty_string_allowed=False):
            message = "DeleteFile parameter value ({}) is not a recognized boolean value.".format(
                pv_DeleteFile)
            recommendation = "Specify either 'True' or 'False for the DeleteFile parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        else:
            # Refresh the phase severity
            self.command_status.refresh_phase_severity(
                CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Beispiel #3
0
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """

        warning = ""

        # Check that parameter TableID is a non-empty, non-None string.
        pv_TableID = self.get_parameter_value(
            parameter_name='TableID', command_parameters=command_parameters)

        if not validators.validate_string(pv_TableID, False, False):
            message = "TableID parameter has no value."
            recommendation = "Specify the TableID parameter to indicate the Table to write."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter OutputFile is a non-empty, non-None string.
        pv_OutputFile = self.get_parameter_value(
            parameter_name='OutputFile', command_parameters=command_parameters)

        if not validators.validate_string(pv_OutputFile, False, False):
            message = "OutputFile parameter has no value."
            recommendation = "Specify the OutputFile parameter (relative or absolute pathname) to indicate the " \
                             "location and name of the output delimited file."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that the required parameters are valid Boolean values or None.
        parameters = ['WriteIndexColumn', 'WriteHeaderRow']

        for parameter in parameters:
            parameter_value = self.get_parameter_value(
                parameter_name=parameter,
                command_parameters=command_parameters)

            if not validators.validate_bool(parameter_value, True, False):
                message = "{} parameter ({}) is not a valid Boolean value.".format(
                    parameter, parameter_value)
                recommendation = "Specify a valid Boolean value for the {} parameter.".format(
                    parameter)
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        # Check that optional parameter ArrayFormat is one of the acceptable values or is None.
        pv_ArrayFormat = self.get_parameter_value(
            parameter_name="ArrayFormat",
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(pv_ArrayFormat,
                                                  self.__choices_ArrayFormat,
                                                  none_allowed=True,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):
            message = "ArrayFormat parameter value ({}) is not recognized.".format(
                pv_ArrayFormat)
            recommendation = "Specify one of the acceptable values ({}) for the ArrayFormat parameter.".format(
                self.__choices_ArrayFormat)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional parameter NullValueFormat is one of the acceptable values or is None.
        pv_NullValueFormat = self.get_parameter_value(
            parameter_name="NullValueFormat",
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_NullValueFormat,
                self.__choices_NullValueFormat,
                none_allowed=True,
                empty_string_allowed=False,
                ignore_case=True):
            message = "NullValueFormat parameter value ({}) is not recognized.".format(
                pv_NullValueFormat)
            recommendation = "Specify one of the acceptable values ({}) for the NullValueFormat parameter.".format(
                self.__choices_NullValueFormat)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Beispiel #4
0
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """
        warning = ""

        # Check that either the parameter Folder or the parameter URL is a non-empty, non-None string.
        pv_Folder = self.get_parameter_value(
            parameter_name='Folder', command_parameters=command_parameters)
        pv_URL = self.get_parameter_value(
            parameter_name='URL', command_parameters=command_parameters)

        folder_is_string = validators.validate_string(pv_Folder, False, False)
        url_is_string = validators.validate_string(pv_URL, False, False)

        if folder_is_string and url_is_string:
            message = "The Folder parameter and the URL parameter cannot both be enabled in the same command."
            recommendation = "Specify only the Folder parameter or only the URL parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        if not folder_is_string and not url_is_string:
            message = "Both the Folder parameter and the URL have no value."
            recommendation = "Specify EITHER the Folder parameter OR the URL parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional ListFiles parameter value is a valid Boolean value or is None.
        pv_ListFiles = self.get_parameter_value(
            parameter_name="ListFiles", command_parameters=command_parameters)

        if not validators.validate_bool(
                pv_ListFiles, none_allowed=True, empty_string_allowed=False):
            message = "ListFiles parameter value ({}) is not a recognized boolean value.".format(
                pv_ListFiles)
            recommendation = "Specify either 'True' or 'False for the ListFiles parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional ListFolders parameter value is a valid Boolean value or is None.
        pv_ListFolders = self.get_parameter_value(
            parameter_name="ListFolders",
            command_parameters=command_parameters)
        if not validators.validate_bool(
                pv_ListFolders, none_allowed=True, empty_string_allowed=False):
            message = "ListFolders parameter value ({}) is not a recognized boolean value.".format(
                pv_ListFolders)
            recommendation = "Specify either 'True' or 'False for the ListFolders parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter ListProperty is a non-empty, non-None string.
        pv_ListProperty = self.get_parameter_value(
            parameter_name='ListProperty',
            command_parameters=command_parameters)

        if not validators.validate_string(pv_ListProperty, False, False):
            message = "ListProperty parameter has no value."
            recommendation = "Specify the ListProperty parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional parameter IfPropertyExists is either `Replace`, `ReplaceAndWarn`, `Warn`, `Fail`, None.
        pv_IfPropertyExists = self.get_parameter_value(
            parameter_name="IfPropertyExists",
            command_parameters=command_parameters)

        acceptable_values = ["Replace", "ReplaceAndWarn", "Warn", "Fail"]

        if not validators.validate_string_in_list(pv_IfPropertyExists,
                                                  acceptable_values,
                                                  none_allowed=True,
                                                  empty_string_allowed=True,
                                                  ignore_case=True):
            message = "IfPropertyExists parameter value ({}) is not recognized.".format(
                pv_IfPropertyExists)
            recommendation = "Specify one of the acceptable values ({}) for the IfPropertyExists parameter.".format(
                acceptable_values)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        else:
            # Refresh the phase severity
            self.command_status.refresh_phase_severity(
                CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """

        warning = ""

        # Check that parameter GeoLayerID is a non-empty, non-None string.
        # - existence of the GeoLayer will also be checked in run_command().
        pv_GeoLayerID = self.get_parameter_value(
            parameter_name='GeoLayerID', command_parameters=command_parameters)

        if not validators.validate_string(pv_GeoLayerID, False, False):
            message = "GeoLayerID parameter has no value."
            recommendation = "Specify the GeoLayerID parameter to indicate the GeoLayer to write."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter OutputFile is a non-empty, non-None string.
        # - existence of the folder will also be checked in run_command().
        pv_OutputFile = self.get_parameter_value(
            parameter_name='OutputFile', command_parameters=command_parameters)

        if not validators.validate_string(pv_OutputFile, False, False):
            message = "OutputFile parameter has no value."
            recommendation = "Specify the OutputFile parameter (relative or absolute pathname) to indicate the " \
                             "location and name of the output spatial data file in GeoJSON format."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional ZipOutput parameter value is a valid Boolean value or is None.
        pv_ZipOutput = self.get_parameter_value(
            parameter_name="ZipOutput", command_parameters=command_parameters)
        if not validators.validate_bool(
                pv_ZipOutput, none_allowed=True, empty_string_allowed=False):
            message = "ZipOutput parameter value ({}) is not a recognized boolean value.".format(
                pv_ZipOutput)
            recommendation = "Specify either 'True' or 'False for the ZipOutput parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Beispiel #6
0
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns:
            Nothing.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """
        warning_message = ""
        logger = logging.getLogger(__name__)

        # SourceFile is required
        pv_SourceFile = self.get_parameter_value(
            parameter_name='SourceFile', command_parameters=command_parameters)
        if not validators.validate_string(pv_SourceFile, False, False):
            message = "The SourceFile must be specified."
            recommendation = "Specify the source file."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # RemoveIfFolder must be a boolean value or None.
        pv_RemoveIfFolder = self.get_parameter_value(
            parameter_name='RemoveIfFolder',
            command_parameters=command_parameters)
        if not validators.validate_bool(pv_RemoveIfFolder, True, False):
            message = "The RemoveIfFolder must be either True or False."
            recommendation = "Specify a valid Boolean value."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # IfSourceFileNotFound is optional, will default to Warn at runtime
        pv_IfSourceFileNotFound = self.get_parameter_value(
            parameter_name='IfSourceFileNotFound',
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_IfSourceFileNotFound, self.__choices_IfSourceFileNotFound,
                True, True):
            message = "IfSourceFileNotFound parameter is invalid."
            recommendation = "Specify the IfSourceFileNotFound parameter as blank or one of " + \
                             str(self.__choices_IfSourceFileNotFound)
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty
        # triggers an exception below.
        warning_message = command_util.validate_command_parameter_names(
            self, warning_message)

        # If any warnings were generated, throw an exception
        if len(warning_message) > 0:
            logger.warning(warning_message)
            raise ValueError(warning_message)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Beispiel #7
0
    def check_command_parameters(self, command_parameters):
        """
        Check the command parameters for validity.

        Args:
            command_parameters: the dictionary of command parameters to check (key:string_value)

        Returns: None.

        Raises:
            ValueError if any parameters are invalid or do not have a valid value.
            The command status messages for initialization are populated with validation messages.
        """

        warning = ""

        # Check that parameter TableID is a non-empty, non-None string.
        pv_TableID = self.get_parameter_value(
            parameter_name='TableID', command_parameters=command_parameters)

        if not validators.validate_string(pv_TableID, False, False):
            message = "TableID parameter has no value."
            recommendation = "Specify the TableID parameter to indicate the Table to write."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter OutputFile is a non-empty, non-None string.
        pv_OutputFile = self.get_parameter_value(
            parameter_name='OutputFile', command_parameters=command_parameters)

        if not validators.validate_string(pv_OutputFile, False, False):
            message = "OutputFile parameter has no value."
            recommendation = "Specify the OutputFile parameter (relative or absolute pathname) to indicate the " \
                             "location and name of the output Excel file."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter WriteIndexColumn is a valid Boolean value or None.
        pv_WriteIndexColumn = self.get_parameter_value(
            parameter_name='WriteIndexColumn',
            command_parameters=command_parameters)

        if not validators.validate_bool(pv_WriteIndexColumn, True, False):
            message = "WriteIndexColumn parameter is not a valid Boolean value."
            recommendation = "Specify a valid Boolean value for the WriteIndexColumn parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check for unrecognized parameters.
        # This returns a message that can be appended to the warning, which if non-empty triggers an exception below.
        warning = command_util.validate_command_parameter_names(self, warning)

        # If any warnings were generated, throw an exception.
        if len(warning) > 0:
            self.logger.warning(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)