def find_databases(dbs=None):
 sockfiles = find_sockfiles()
 if (dbs is None):
  dbs = {}
 for sockfile in sockfiles:
  dbname = get_dbname(sockfile)
  if (dbname in dbs):
   continue
  if (not dbname):
   continue
  try:
   db = mysql_connect(sockfile)
   cursor = db.cursor()
   cursor.execute('SELECT VERSION()')
  except (EnvironmentError, EOFError, RuntimeError, socket.error, MySQLdb.MySQLError) as e:
   utils.err(("Couldn't connect to %s: %s" % (sockfile, e)))
   continue
  version = cursor.fetchone()[0]
  dbs[dbname] = DB(sockfile, dbname, db, cursor, version)
 return dbs

def find_databases ( dbs = None ) : sockfiles = find_sockfiles ( ) if ( dbs is None ) : dbs = { } for sockfile in sockfiles : dbname = get_dbname ( sockfile ) if ( dbname in dbs ) : continue if ( not dbname ) : continue try : db = mysql_connect ( sockfile ) cursor = db . cursor ( ) cursor . execute ( 'SELECT VERSION()' ) except ( EnvironmentError , EOFError , RuntimeError , socket . error , MySQLdb . MySQLError ) as e : utils . err ( ( "Couldn't connect to %s: %s" % ( sockfile , e ) ) ) continue version = cursor . fetchone ( ) [ 0 ] dbs [ dbname ] = DB ( sockfile , dbname , db , cursor , version ) return dbs
returns a map of dbname to db instances to monitor .