def grant_add(grant, database, user, host='localhost', grant_option=False, escape=True, ssl_option=False, **connection_args):
 dbc = _connect(**connection_args)
 if (dbc is None):
  return False
 cur = dbc.cursor()
 grant = grant.strip()
 try:
  qry = __grant_generate(grant, database, user, host, grant_option, escape, ssl_option)
 except Exception:
  log.error('Error during grant generation')
  return False
 try:
  _execute(cur, qry['qry'], qry['args'])
 except (MySQLdb.OperationalError, MySQLdb.ProgrammingError) as exc:
  err = 'MySQL Error {0}: {1}'.format(*exc)
  __context__['mysql.error'] = err
  log.error(err)
  return False
 if grant_exists(grant, database, user, host, grant_option, escape, **connection_args):
  log.info("Grant '{0}' on '{1}' for user '{2}' has been added".format(grant, database, user))
  return True
 log.info("Grant '{0}' on '{1}' for user '{2}' has NOT been added".format(grant, database, user))
 return False

def grant_add ( grant , database , user , host = 'localhost' , grant_option = False , escape = True , ssl_option = False , ** connection_args ) : dbc = _connect ( ** connection_args ) if ( dbc is None ) : return False cur = dbc . cursor ( ) grant = grant . strip ( ) try : qry = __grant_generate ( grant , database , user , host , grant_option , escape , ssl_option ) except Exception : log . error ( 'Error during grant generation' ) return False try : _execute ( cur , qry [ 'qry' ] , qry [ 'args' ] ) except ( MySQLdb . OperationalError , MySQLdb . ProgrammingError ) as exc : err = 'MySQL Error {0}: {1}' . format ( * exc ) __context__ [ 'mysql.error' ] = err log . error ( err ) return False if grant_exists ( grant , database , user , host , grant_option , escape , ** connection_args ) : log . info ( "Grant '{0}' on '{1}' for user '{2}' has been added" . format ( grant , database , user ) ) return True log . info ( "Grant '{0}' on '{1}' for user '{2}' has NOT been added" . format ( grant , database , user ) ) return False
adds a grant to the mysql server .