def load_config(self, file):
        """Attempts to load a JSON config file for Cardinal.

        Takes a file path, attempts to decode its contents from JSON, then
        validate known config options to see if they can safely be loaded in.
        their place. The final merged dictionary object is saved to the
        If they can't, the default value from the config spec is used in the
        instance and returned.

        Keyword arguments:
          file -- Path to a JSON config file.

        Returns:
          dict -- Dictionary object of the entire config.

        """
        # Attempt to load and parse the config file
        try:
            f = open(file, 'r')
            json_config = self._utf8_json(json.load(f))
            f.close()
        # File did not exist or we can't open it for another reason
        except IOError:
            self.logger.warning(
                "Can't open %s (using defaults / command-line values)" % file
            )
        # Thrown by json.load() when the content isn't valid JSON
        except ValueError:
            self.logger.warning(
                "Invalid JSON in %s, (using defaults / command-line values)" %
                file
            )
        else:
            # For every option,
            for option in self.spec.options:
                try:
                    # If the option wasn't defined in the config, default
                    if option not in json_config:
                        json_config[option] = None

                    self.config[option] = self.spec.return_value_or_default(
                        option, json_config[option])
                except __HOLE__:
                    self.logger.warning("Option %s not in spec -- ignored" %
                                        option)

        # If we didn't load the config earlier, or there was nothing in it...
        if self.config == {} and self.spec.options != {}:
            for option in self.spec.options:
                # Grab the default
                self.config[option] = self.spec.options[option][1]

        return self.config
dataset/ETHPy150Open JohnMaguire/Cardinal/cardinal/config.py/ConfigParser.load_config