Пример #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 URL is a non-empty, non-None string.
        # - existence of the url will also be checked in run_command().
        pv_URL = self.get_parameter_value(
            parameter_name='URL', command_parameters=command_parameters)

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

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

        # Check that parameter OutputFile is a non-empty string (can be None).
        # - 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, True, False):

            message = "OutputFile parameter has no value."
            recommendation = "Specify the OutputFile parameter to indicate the output file."
            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)
Пример #2
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 = ""
        logger = logging.getLogger(__name__)

        # Unlike most commands, set internal data here because it is needed by initial call to next()
        # before calls to run_command

        # Name is required
        pv_Name = self.get_parameter_value(
            parameter_name='Name', command_parameters=command_parameters)
        if not validators.validate_string(pv_Name, False, False):
            message = "A name for the If block must be specified"
            recommendation = "Specify the Name."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Condition is required
        pv_Condition = self.get_parameter_value(
            parameter_name='Condition', command_parameters=command_parameters)
        if not validators.validate_string(pv_Condition, False, False):
            message = "A condition for the If command must be specified"
            recommendation = "Specify the condition."
            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:
            logger.warn(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Пример #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 GeoLayerIDs is a non-empty, non-None string.
        pv_GeoLayerIDs = self.get_parameter_value(
            parameter_name='GeoLayerIDs',
            command_parameters=command_parameters)

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

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

        if not validators.validate_string(pv_OutputGeoLayerID, False, False):
            message = "OutputGeoLayerID parameter has no value."
            recommendation = "Specify the OutputGeoLayerID parameter to indicate the ID of the merged GeoLayer."
            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)
    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__)

        # SearchFolder is required
        pv_SearchFolder = self.get_parameter_value(parameter_name='SearchFolder', command_parameters=command_parameters)
        if not validators.validate_string(pv_SearchFolder, False, False):
            message = "SearchFolder parameter has no value."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message, "Specify the search folder."))
            print(message)

        # FilenamePattern is optional, will default to "test-*" at runtime

        # OutputFile is required
        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."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message, "Specify the output file."))
            print(message)

        # 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)
Пример #5
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 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 to indicate the GeoLayer to copy."
            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 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)
Пример #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 = ""
        logger = logging.getLogger("gp")

        # Message is required
        pv_Message = self.get_parameter_value(
            parameter_name='Message', command_parameters=command_parameters)
        if not validators.validate_string(pv_Message, False, False):
            message = "Message parameter has no value."
            recommendation = "Specify text for the Message parameter."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))
        pv_CommandStatus = self.get_parameter_value(
            parameter_name='CommandStatus',
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_CommandStatus,
                CommandStatusType.get_command_status_types_as_str(), True,
                True):
            message = 'The requested command status "' + pv_CommandStatus + '"" is invalid.'
            recommendation = "Specify a valid command status."
            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:
            logger.warning(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(
            CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Пример #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 SpatialDataFile is a non-empty, non-None string.
        # - existence of the file will also be checked in run_command().
        pv_SpatialDataFile = self.get_parameter_value(parameter_name='SpatialDataFile',
                                                      command_parameters=command_parameters)

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

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

        # Check that optional parameter IfGeoLayerIDExists is one of the acceptable values or is None.
        pv_IfGeoLayerIDExists = self.get_parameter_value(parameter_name="IfGeoLayerIDExists",
                                                         command_parameters=command_parameters)
        if not validators.validate_string_in_list(pv_IfGeoLayerIDExists, self.__choices_IfGeoLayerIDExists,
                                                  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(
                self.__choices_IfGeoLayerIDExists)
            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:
            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__)

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

        # ExpectedStatus is optional, will default to Success at runtime
        pv_ExpectedStatus = self.get_parameter_value(parameter_name='ExpectedStatus',
                                                     command_parameters=command_parameters)
        if not validators.validate_string_in_list(pv_ExpectedStatus,
                                                  self.__choices_ExpectedStatus, True, True):
            message = "ExpectedStatus parameter is invalid."
            recommendation = "Specify the ExpectedStatus parameter as blank or one of " + \
                             str(self.__choices_ExpectedStatus)
            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)
    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 = ""
        logger = logging.getLogger(__name__)

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

        # 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:
            logger.warning(warning)
            raise ValueError(warning)

        # Refresh the phase severity
        self.command_status.refresh_phase_severity(CommandPhaseType.INITIALIZATION, CommandStatusType.SUCCESS)
Пример #10
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)
    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 = ""
        logger = logging.getLogger(__name__)

        # PropertyName is required
        pv_PropertyName = self.get_parameter_value(
            parameter_name='PropertyName',
            command_parameters=command_parameters)
        if not validators.validate_string(pv_PropertyName, False, False):
            message = "PropertyName parameter has no value."
            recommendation = "Specify a property name."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # PropertyType is required
        pv_PropertyType = self.get_parameter_value(
            parameter_name='PropertyType',
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_PropertyType, self.__choices_PropertyType, False, False):
            message = 'The requested property type "' + pv_PropertyType + '"" is invalid.'
            recommendation = "Specify a valid property type:  " + str(
                property_types)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # TODO smalers 2017-12-28 add other parameters similar to TSTool to set special values

        property_value_parameter_count = 0  # increment for PropertyValue or PropertyValues, only one is allowed
        # PropertyValue or PropertyValues are required
        pv_PropertyValue = self.get_parameter_value(
            parameter_name='PropertyValue',
            command_parameters=command_parameters)
        if pv_PropertyValue is not None and pv_PropertyValue != "":
            property_value_parameter_count += 1
            if not validators.validate_string(pv_PropertyValue, True, True):
                message = "PropertyValue parameter is not specified."
                recommendation = "Specify a property value."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        pv_PropertyValues = self.get_parameter_value(
            parameter_name='PropertyValues',
            command_parameters=command_parameters)
        if pv_PropertyValues is not None and pv_PropertyValues != "":
            property_value_parameter_count += 1
            if not validators.validate_list(
                    pv_PropertyValues, True, True, brackets_required=False):
                message = "PropertyValues parameter is not valid."
                recommendation = "Specify a list of values separated by commas and optional spaces."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        if property_value_parameter_count != 1:
            message = "PropertyValue (single value) or PropertyValues (for list) parameter must be specified."
            recommendation = "Specify a single value with PropertyValue or list of values with PropertyValues."
            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:
            # Message.printWarning ( warning_level,
            #    MessageUtil.formatMessageTag(command_tag, warning_level), routine, warning );
            logger.warning(warning)
            raise ValueError(warning)

        # 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 the required parameters are non-empty, non-None strings.
        required_parameters = ["TableID", "DataStoreID", "DataStoreTable"]

        for parameter in required_parameters:

            parameter_value = self.get_parameter_value(
                parameter_name=parameter,
                command_parameters=command_parameters)
            if not validators.validate_string(parameter_value, False, False):
                message = "{} parameter has no value.".format(parameter)
                recommendation = "Specify a valid 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 WriteMode is one of the acceptable values or is None.
        pv_WriteMode = self.get_parameter_value(
            parameter_name="WriteMode", command_parameters=command_parameters)
        if not validators.validate_string_in_list(pv_WriteMode,
                                                  self.__choices_WriteMode,
                                                  none_allowed=False,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):
            message = "WriteMode parameter value ({}) is not recognized.".format(
                pv_WriteMode)
            recommendation = "Specify one of the acceptable values ({}) for the WriteMode parameter.".format(
                self.__choices_WriteMode)
            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)
    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)
    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 = ""
        logger = logging.getLogger(__name__)

        # GeoLayerID is required
        # - 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 process."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # PropertyName is required
        pv_PropertyName = self.get_parameter_value(
            parameter_name='PropertyName',
            command_parameters=command_parameters)
        if not validators.validate_string(pv_PropertyName, False, False):
            message = "PropertyName parameter has no value."
            recommendation = "Specify a property name."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # PropertyType is required
        pv_PropertyType = self.get_parameter_value(
            parameter_name='PropertyType',
            command_parameters=command_parameters)
        property_types = ["bool", "float", "int", "long", "str"]
        if not validators.validate_string_in_list(
                pv_PropertyType, property_types, False, False):
            message = 'The requested property type "' + pv_PropertyType + '"" is invalid.'
            recommendation = "Specify a valid property type:  " + str(
                property_types)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # PropertyValue is required
        pv_PropertyValue = self.get_parameter_value(
            parameter_name='PropertyValue',
            command_parameters=command_parameters)
        if not validators.validate_string(pv_PropertyValue, False, False):
            # TODO smalers 2017-12-28 add other parameters similar to TSTool to set special values
            message = "PropertyValue parameter is not specified."
            recommendation = "Specify a property value."
            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:
            logger.warning(warning)
            raise ValueError(warning)

        # 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 the appropriate parameters have a string value.
        for parameter in ['GeoLayerID', 'OutputFile']:

            # Get the parameter value.
            parameter_value = self.get_parameter_value(
                parameter_name=parameter,
                command_parameters=command_parameters)

            # Check that the parameter value is a non-empty, non-None string. If not, raise a FAILURE.
            if not validators.validate_string(parameter_value, False, False):
                message = "{} parameter has no value.".format(parameter)
                recommendation = "Specify the {} parameter.".format(parameter)
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        # Check that optional parameter OutputGeometryFormat is either `WKT`, `XYZ`, `XY`, `YX` or None.
        pv_OutputGeometryFormat = self.get_parameter_value(
            parameter_name="OutputGeometryFormat",
            command_parameters=command_parameters)
        acceptable_values = ["WKT", "XYZ", "XY", "YZ"]
        if not validators.validate_string_in_list(pv_OutputGeometryFormat,
                                                  acceptable_values,
                                                  none_allowed=True,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):
            message = "OutputGeometryFormat parameter value ({}) is not recognized.".format(
                pv_OutputGeometryFormat)
            recommendation = "Specify one of the acceptable values ({}) for the OutputGeometryFormat parameter.".format(
                acceptable_values)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional parameter OutputDelimiter is either `COMMA`, `SPACE`, `TAB`, `SEMICOLON` or None.
        pv_OutputDelimiter = self.get_parameter_value(
            parameter_name="OutputDelimiter",
            command_parameters=command_parameters)
        acceptable_values = ["COMMA", "SEMICOLON", "TAB", "SPACE"]
        if not validators.validate_string_in_list(pv_OutputDelimiter,
                                                  acceptable_values,
                                                  none_allowed=True,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):
            message = "OutputDelimiter parameter value ({}) is not recognized.".format(
                pv_OutputDelimiter)
            recommendation = "Specify one of the acceptable values ({}) for the OutputDelimiter 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)

        # 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)
Пример #17
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 = ""
        logger = logging.getLogger(__name__)

        # Unlike most commands, set internal data here because it is needed by initial call to next()
        # before calls to run_command

        # Options for iterating, will be changed based on parameters that are set
        self.iterator_is_list = False
        self.iterator_is_sequence = False
        self.iterator_is_table = False
        option_count = 0  # How many iteration options are specified (should only be 1)

        # Name is required
        pv_Name = self.get_parameter_value(
            parameter_name='Name', command_parameters=command_parameters)
        if not validators.validate_string(pv_Name, False, False):
            message = "A name for the For block must be specified"
            recommendation = "Specify the Name."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # --------------------------------
        # Iterator option 1 - use a sequence
        # SequenceStart is currently required since no other iteration types are implemented
        pv_SequenceStart = self.get_parameter_value(
            parameter_name='SequenceStart',
            command_parameters=command_parameters)
        if pv_SequenceStart is not None and pv_SequenceStart != "":
            self.iterator_is_sequence = True  # Will be checked below to make sure only one option is used
            option_count += 1
            if not validators.validate_number(pv_SequenceStart, False, False):
                message = "The SequenceStart value must be specified as a number"
                recommendation = "Specify the SequenceStart as a number."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))
            else:
                if pv_SequenceStart.find(".") >= 0:
                    # Decimal
                    self.iterator_sequence_start = float(pv_SequenceStart)
                else:
                    # Assume integer
                    self.iterator_sequence_start = int(pv_SequenceStart)

            # The other sequence parameters only make sense if the start is specified
            # SequenceEnd is currently required since no other iteration types are implemented
            pv_SequenceEnd = self.get_parameter_value(
                parameter_name='SequenceEnd',
                command_parameters=command_parameters)
            if not validators.validate_number(pv_SequenceEnd, False, False):
                message = "The SequenceEnd value must be specified as a number"
                recommendation = "Specify the SequenceEnd as a number."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))
            else:
                if pv_SequenceEnd.find(".") >= 0:
                    # Decimal
                    self.iterator_sequence_end = float(pv_SequenceEnd)
                else:
                    # Assume integer
                    self.iterator_sequence_end = int(pv_SequenceEnd)

            # SequenceIncrement is currently required since no other iteration types are implemented
            pv_SequenceIncrement = self.get_parameter_value(
                parameter_name='SequenceIncrement',
                command_parameters=command_parameters)
            if not validators.validate_number(pv_SequenceIncrement, False,
                                              False):
                message = "The SequenceIncrement value must be specified as a number"
                recommendation = "Specify the SequenceIncrement as a number."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))
            else:
                if pv_SequenceIncrement.find(".") >= 0:
                    # Decimal
                    self.iterator_sequence_increment = float(
                        pv_SequenceIncrement)
                else:
                    # Assume integer
                    self.iterator_sequence_increment = int(
                        pv_SequenceIncrement)

        # --------------------------------
        # Iterator option 2 - use a processor property that contains a list
        pv_ListProperty = self.get_parameter_value(
            parameter_name='ListProperty',
            command_parameters=command_parameters)
        if pv_ListProperty is not None and pv_ListProperty != "":
            self.iterator_is_list = True  # Will be checked below to make sure only one option is used
            option_count += 1
            # No further validation is done - ListProperty property must be defined at run time

        # --------------------------------
        # Iterator option 3 - use a table
        pv_TableID = self.get_parameter_value(
            parameter_name='TableID', command_parameters=command_parameters)
        if pv_TableID is not None and pv_TableID != "":
            self.iterator_is_table = True
            option_count += 1

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

        # --------------------------------
        # Only allow one of the iteration properties to be specified because otherwise the command will be confused.
        if option_count > 1:
            message = "Parameters for multiple iterator types have been specified."
            recommendation = "Specify parameters for only one iteration type."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))
            # Allow multiple iteration types to be set since they will be processed in order when running
            # and the preferred approach will take precedent

        # 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:
            logger.warn(warning)
            raise ValueError(warning)

        # 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 InputFile is a non-empty, non-None string.
        pv_InputFile = self.get_parameter_value(
            parameter_name='InputFile', command_parameters=command_parameters)

        if not validators.validate_string(pv_InputFile, False, False):
            message = "InputFile parameter has no value."
            recommendation = "Specify the InputFile 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 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."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

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

        # If the HeaderLines is used, continue with the checks.
        pv_HeaderLines = self.get_parameter_value(
            "HeaderLines", command_parameters=command_parameters)
        if pv_HeaderLines:

            # Check that the HeaderLines parameter is an integer or None.
            if not validators.validate_int(pv_HeaderLines, True, False):

                message = "HeaderLines parameter value ({}) is not a valid integer value.".format(
                    pv_HeaderLines)
                recommendation = "Specify a positive integer for the HeaderLines parameter to specify how" \
                                 " many rows represent the header contnet of the delimited file."
                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)
Пример #19
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__)

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

        # IncludeProperties is optional, default to * at runtime

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

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

        # SortOrder is optional, will default to None (no sort) at runtime
        pv_SortOrder = self.get_parameter_value(
            parameter_name='SortOrder', command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_SortOrder, self.__choices_SortOrder, True, True):
            message = "SortOrder parameter is invalid."
            recommendation = "Specify the SortOrder parameter as blank or one of " + \
                             str(self.__choices_SortOrder)
            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)
Пример #20
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 parameters GeoLayerID and 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 to indicate the input GeoLayer."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

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

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

            message = "AttributeName parameter has no value."
            recommendation = "Specify the AttributeName parameter to indicate the name of attribute to add."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that parameter AttributeType is either 'string', 'date', 'int' and 'double'.
        pv_AttributeType = self.get_parameter_value(
            parameter_name="AttributeType",
            command_parameters=command_parameters)

        acceptable_values = ["string", "date", "int", "double"]
        if not validators.validate_string_in_list(
                pv_AttributeType, acceptable_values, ignore_case=True):
            message = "AttributeType parameter value ({}) is not recognized.".format(
                pv_AttributeType)
            recommendation = "Specify one of the acceptable values ({}) for the AttributeType 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)
Пример #22
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 the DataStoreID is a non-empty, non-None string.
        pv_DataStoreID = self.get_parameter_value(parameter_name="DataStoreID", command_parameters=command_parameters)

        if not validators.validate_string(pv_DataStoreID, False, False):
            message = "DataStoreID parameter has no value."
            recommendation = "Specify a valid DataStore ID."
            warning += "\n" + message
            self.command_status.add_to_log(CommandPhaseType.INITIALIZATION,
                                           CommandLogRecord(CommandStatusType.FAILURE, message, recommendation))

        # Check that one (and only one) sql method is a non-empty and non-None string.
        is_string_list = []
        sql_method_parameter_list = ["Sql", "SqlFile", "DataStoreProcedure"]

        for parameter in sql_method_parameter_list:
            parameter_value = self.get_parameter_value(parameter_name=parameter, command_parameters=command_parameters)
            is_string_list.append(validators.validate_string(parameter_value, False, False))

        if not is_string_list.count(True) == 1:
            message = "Must enable one (and ONLY one) of the following parameters: {}".format(sql_method_parameter_list)
            recommendation = "Specify the value for one (and ONLY one) of the following parameters: {}".format(
                sql_method_parameter_list)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message, recommendation))

        # TEMPORARY CHECK: Check that the DataStoreProcedure method is not being used. Currently disabled until future
        # development. Once developed, this check can be removed.
        else:
            pv_DataStoreProcedure = self.get_parameter_value(parameter_name="DataStoreProcedure",
                                                             command_parameters=command_parameters)

            if validators.validate_string(pv_DataStoreProcedure, none_allowed=False, empty_string_allowed=False):
                message = "DataStoreProcedure is not currently enabled."
                recommendation = "Specify the Sql method or the SqlFile method. "
                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)
    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 the DataStoreID is a non-empty, non-None string.
        pv_DataStoreID = self.get_parameter_value(
            parameter_name="DataStoreID",
            command_parameters=command_parameters)

        if not validators.validate_string(pv_DataStoreID, False, False):
            message = "DataStoreID parameter has no value."
            recommendation = "Specify a valid DataStore ID."
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that optional IfDataStoreIDExists param is `Replace`, `Open`, `Warn`, `Fail`, `ReplaceAndWarn` or None.
        pv_IfDataStoreIDExists = self.get_parameter_value(
            parameter_name="IfDataStoreIDExists",
            command_parameters=command_parameters)

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

        # Check if the ConfigFile parameter is a non-empty, non-None string.
        pv_ConfigFile = self.get_parameter_value(
            parameter_name="ConfigFile", command_parameters=command_parameters)

        # If there is a value for ConfigFile, assume "Configuration file configures datastore" method.
        if validators.validate_string(pv_ConfigFile, False, False):

            pass

        # If the IfDataStoreIDExists parameter is set to "Open", ignore all checks.
        elif validators.validate_string_in_list(pv_IfDataStoreIDExists,
                                                ["OPEN"], False, False, True):

            pass

        # If there is no value for ConfigFile, assume "Parameters configure datastore" method.
        else:

            # Check that the required parameters are non-empty, non-None string.
            required_parameters = [
                "DatabaseServer", "DatabaseName", "DatabaseUser",
                "DatabasePassword"
            ]
            for parameter in required_parameters:

                parameter_value = self.get_parameter_value(
                    parameter_name=parameter,
                    command_parameters=command_parameters)

                if not validators.validate_string(parameter_value, False,
                                                  False):
                    message = "{} parameter has no value.".format(parameter)
                    recommendation = "Specify a valid {} parameter.".format(
                        parameter)
                    warning += "\n" + message
                    self.command_status.add_to_log(
                        CommandPhaseType.INITIALIZATION,
                        CommandLogRecord(CommandStatusType.FAILURE, message,
                                         recommendation))

            # Check that parameter DatabaseDialect is one of the acceptable values.
            pv_DatabaseDialect = self.get_parameter_value(
                parameter_name="DatabaseDialect",
                command_parameters=command_parameters)

            if not validators.validate_string_in_list(
                    pv_DatabaseDialect, self.__choices_DatabaseDialect, False,
                    False, True):
                message = "DatabaseDialect parameter value ({}) is not recognized.".format(
                    pv_DatabaseDialect)
                recommendation = "Specify one of the acceptable values ({}) for the DatabaseDialect parameter.".format(
                    self.__choices_DatabaseDialect)
                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)
Пример #24
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 DataStoreID is a non-empty, non-None string.
        pv_DataStoreID = self.get_parameter_value(
            parameter_name='DataStoreID',
            command_parameters=command_parameters)

        if not validators.validate_string(pv_DataStoreID, False, False):
            message = "DataStoreID parameter has no value."
            recommendation = "Specify the DataStoreID 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 one (and only one) selection method is a non-empty and non-None string.
        is_string_list = []
        selection_method_parameter_list = ["Sql", "SqlFile", "DataStoreTable"]

        for parameter in selection_method_parameter_list:

            parameter_value = self.get_parameter_value(
                parameter_name=parameter,
                command_parameters=command_parameters)
            is_string_list.append(
                validators.validate_string(parameter_value, False, False))

        if not is_string_list.count(True) == 1:
            message = "Must enable one (and ONLY one) of the following parameters: {}".format(
                selection_method_parameter_list)
            recommendation = "Specify the value for one (and ONLY one) of the following parameters: {}".format(
                selection_method_parameter_list)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Run the checks for the Top parameter.
        pv_Top = self.get_parameter_value(
            parameter_name='Top', command_parameters=command_parameters)
        pv_DataStoreTable = self.get_parameter_value(
            parameter_name="DataStoreTable",
            command_parameters=command_parameters)
        if pv_Top:

            # Check that the Top parameter is only used with the DataStoreTable selection.
            if is_string_list.count(True) == 1 and not pv_DataStoreTable:

                message = "The Top parameter is only valid when the DataStoreTable is enabled. The Top parameter" \
                          " value ({}) will be ignored.".format(pv_Top)
                recommendation = "To use the Top parameter, specify a value for the DataStoreTable parameter."
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.WARNING, message,
                                     recommendation))

            # If the DataStoreTable parameter is enabled, check that the Top parameter is an integer or None.
            if pv_DataStoreTable and not validators.validate_int(
                    pv_Top, True, False):

                message = "Top parameter value ({}) is not a valid integer value.".format(
                    pv_Top)
                recommendation = "Specify a positive integer for the Top parameter to specify how many rows to return."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

            # If the DataStoreTable parameter is enabled, check that the Top parameter is positive.
            elif pv_DataStoreTable and not int(pv_Top) > 0:

                message = "Top parameter value ({}) is not a positive, non-zero integer value.".format(
                    pv_Top)
                recommendation = "Specify a positive integer for the Top parameter to specify how many rows to return."
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        # Check that optional parameter IfTableIDExists is one of the acceptable values or is None.
        pv_IfTableIDExists = self.get_parameter_value(
            parameter_name="IfTableIDExists",
            command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_IfTableIDExists,
                self.__choices_IfTableIDExists,
                none_allowed=True,
                empty_string_allowed=False,
                ignore_case=True):
            message = "IfTableIDExists parameter value ({}) is not recognized.".format(
                pv_IfTableIDExists)
            recommendation = "Specify one of the acceptable values ({}) for the IfTableIDExists parameter.".format(
                self.__choices_IfTableIDExists)
            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)
    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__)

        # CommandLine is required, pending other options
        pv_CommandLine = self.get_parameter_value(
            parameter_name='CommandLine',
            command_parameters=command_parameters)
        if not validators.validate_string(pv_CommandLine, False, False):
            message = "The CommandLine must be specified."
            recommendation = "Specify the command line."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

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

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

        # TODO smalers 2018-12-16 need to make sure IncludeEnvVars and ExcludeEnvVars are valid lists
        # - for now allow any string to be specified

        # 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)
Пример #26
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__)

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

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

        # CommentLineChar is optional, defaults to # at runtime, for now no checks

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

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

        # AllowedDiffCount is optional, defaults to 0 at runtime, but must be a number if specified
        pv_AllowedDiffCount = self.get_parameter_value(
            parameter_name='AllowedDiffCount',
            command_parameters=command_parameters)
        if not validators.validate_int(pv_AllowedDiffCount, True, True):
            message = "The AllowedDiffCount parameter is invalid."
            recommendation = "Specify the allowed difference count as an integer."
            warning_message += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

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

        # IfSame is optional, defaults to Ignore at runtime
        pv_IfSame = self.get_parameter_value(
            parameter_name='IfSame', command_parameters=command_parameters)
        if not validators.validate_string_in_list(
                pv_IfSame, self.__choices_IfSame, True, True):
            message = "IfSame parameter is invalid."
            recommendation = "Specify the IfSame parameter as blank or one of " + str(
                self.__choices_IfSame)
            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)
    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 the appropriate parameters have a string value.
        for parameter in ['DelimitedFile', 'Delimiter', 'CRS', 'GeoLayerID']:

            # Get the parameter value.
            parameter_value = self.get_parameter_value(
                parameter_name=parameter,
                command_parameters=command_parameters)

            # Check that the parameter value is a non-empty, non-None string. If not, raise a FAILURE.
            if not validators.validate_string(parameter_value, False, False):

                message = "{} parameter has no value.".format(parameter)
                recommendation = "Specify the {} parameter.".format(parameter)
                warning += "\n" + message
                self.command_status.add_to_log(
                    CommandPhaseType.INITIALIZATION,
                    CommandLogRecord(CommandStatusType.FAILURE, message,
                                     recommendation))

        # Check that the GeometryFormat is either `XY` or `WKT`.
        pv_GeometryFormat = self.get_parameter_value(
            parameter_name="GeometryFormat",
            command_parameters=command_parameters)
        acceptable_values = ["WKT", "XY"]

        if not validators.validate_string_in_list(pv_GeometryFormat,
                                                  acceptable_values,
                                                  none_allowed=False,
                                                  empty_string_allowed=False,
                                                  ignore_case=True):

            message = "GeometryFormat parameter value ({}) is not recognized.".format(
                pv_GeometryFormat)
            recommendation = "Specify one of the acceptable values ({}) for the GeometryFormat parameter.".format(
                acceptable_values)
            warning += "\n" + message
            self.command_status.add_to_log(
                CommandPhaseType.INITIALIZATION,
                CommandLogRecord(CommandStatusType.FAILURE, message,
                                 recommendation))

        # Check that the correct ColumnName variables are correct.
        else:

            # If the pv_GeometryFormat is "WKT" then check that the WKTColumn has a string value.
            if pv_GeometryFormat is not None and pv_GeometryFormat.upper(
            ) == "WKT":

                # Check that the parameter value is a non-None string. If not, raise a FAILURE.
                if not validators.validate_string("WKTColumn", False, True):
                    message = "WKTColumn parameter has no value."
                    recommendation = "Specify the WKTColumn parameter."
                    warning += "\n" + message
                    self.command_status.add_to_log(
                        CommandPhaseType.INITIALIZATION,
                        CommandLogRecord(CommandStatusType.FAILURE, message,
                                         recommendation))

            else:

                # Check that the appropriate parameters have a string value.
                for parameter in ['XColumn', 'YColumn']:

                    # Get the parameter value.
                    parameter_value = self.get_parameter_value(
                        parameter_name=parameter,
                        command_parameters=command_parameters)

                    # Check that the parameter value is a non-None string. If not, raise a FAILURE.
                    if not validators.validate_string(parameter_value, False,
                                                      True):
                        message = "{} parameter has no value.".format(
                            parameter)
                        recommendation = "Specify the {} parameter.".format(
                            parameter)
                        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 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)
Пример #28
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)