Beispiel #1
0
    def get_value(self, section, parameter):
        """ Search the configuration dictionary for the parameter

        Search the configuration dictionary for the specified parameter
        and return the associated value

        Args:
            section: The section of the config file to read the parameter from
            parameter: The parameter to read from the file

        Return:
            the parameter value that is read from the file

        """

        if not self._config:
            return None

        if section and parameter:
            try:
                read_value = self._config.get(section, parameter.lower())
            except configparser.NoSectionError:
                return None
        else:
            return None

        param_value = convert_to_number(read_value)

        if param_value != None:
            return param_value
        else:
            return read_value
Beispiel #2
0
    def parse(self, path_and_file):
        """Read all autoscript commands from the file.

        Reads the entire autoscript file formatted as a comma separated value
        (CSV) file.  The commands are stored as objects in a List.

        Args:
            path_and_file: the path and filename of the autoscript file.

        Returns:
            The list of AutoScriptCommand objects.

        """
        # Clear out any old data
        self._commands = []

        try:
            with open(path_and_file, 'r') as asfile:
                csvreader = csv.reader(asfile, delimiter=',')
                for row in csvreader:
                    cmd = None
                    params = []
                    for column in row:
                        if not cmd:
                            cmd = column
                        else:
                            num = convert_to_number(column)
                            if num:
                                params.append(num)
                            else:
                                params.append(column)
                    if cmd:
                        command = AutoScriptCommand(cmd, params)
                        self._commands.append(command)
        except (OSError, IOError):
            self._commands = None
            return self._commands

        self._command_iterator = iter(self._commands)
        return self._commands