code: def open_connection(self):
          
          self.connection = None
          base_directory = os.path.dirname(self.metadata_db_path)
          if not os.path.exists(base_directory):
              try:
                  os.mkdir(base_directory)
              except IOError:
                  LOGGER.exception(
                      'Could not create directory for metadata cache.')
                  raise
  
          try:
              self.connection = sqlite.connect(self.metadata_db_path)
          except (OperationalError, sqlite.Error):
              LOGGER.exception('Failed to open metadata cache database.')
              raise
docs: Open an sqlite connection to the metadata database.
  
          By default the metadata database will be used in the plugin dir,
          unless an explicit path has been set using setmetadataDbPath, or
          overridden in QSettings. If the db does not exist it will
          be created.
  
          :raises: An sqlite.Error is raised if anything goes wrong