コード例 #1
0
def main(unused_argv):
  """This drives the standalone checksumming app.

  This function sets up the parameters for a DbChecksummer, passing the FLAGS
  parameters in as the droid-compatible config dictionary.
  """
  assert FLAGS.db, 'Please pass --db'

  dbh = db.Connect(FLAGS.db)
  db_checksummer = drift_lib.DbChecksummer(dbh=dbh,
                                           result_table=FLAGS.result_table,
                                           golden_table=FLAGS.golden_table,
                                           log_table=FLAGS.log_table,
                                           job_started=FLAGS.job_started,
                                           scan_rate=FLAGS.scan_rate,
                                           secs_per_query=FLAGS.secs_per_query,
                                           rows_per_query=FLAGS.rows_per_query,
                                           hours_to_run=FLAGS.hours_to_run,
                                           utilization=FLAGS.utilization,
                                           tables_to_skip=FLAGS.skip_table,
                                           databases_to_skip=FLAGS.skip_db,
                                           engines_to_check=FLAGS.check_engine,
                                           tables_to_check=FLAGS.check_table)
  db_checksummer.ChecksumTables()
  dbh.Close()
コード例 #2
0
ファイル: validate.py プロジェクト: zihaozhu93/mysql-tools
def main(argv):
    if not FLAGS.db:
        raise app.UsageError('Please specify --db')
    if len(argv) < 2:
        raise app.UsageError('Please specify at least one filename.')

    dbh = db.Connect(FLAGS.db)
    val = validator.Validator(schema.Schema(dbh))

    for filename in argv[1:]:
        val.ValidateString(open(filename, 'r').read())

    dbh.Close()
コード例 #3
0
ファイル: permissions.py プロジェクト: zihaozhu93/mysql-tools
def main(argv):
    if len(argv) != 2:
        raise app.UsageError('Incorrect arguments')

    args = {}

    if FLAGS.private_keyfile:
        args['private_keyfile'] = FLAGS.private_keyfile

    if FLAGS.file:
        args['self'] = use.PermissionsFile(
            None, private_keyfile=FLAGS.private_keyfile)
        args.pop('private_keyfile', None)  # Not otherwise used
        for file in FLAGS.file:
            args['self'].Parse(open(file, 'r').read())

    if FLAGS.db:
        args['dbh'] = db.Connect(FLAGS.db)

    if FLAGS.set:
        args['dest_set_name'] = FLAGS.set
        args['set_name'] = FLAGS.set

    if FLAGS.source_set:
        args['set_name'] = FLAGS.source_set

    if FLAGS.push_duration:
        args['push_duration'] = FLAGS.push_duration

    if FLAGS.public_keyfile:
        args['public_keyfile'] = FLAGS.public_keyfile

    if FLAGS.comment_name:
        args['comment_names'] = FLAGS.comment_name

    args['incremental'] = FLAGS.incremental

    CheckArgs(_COMMANDS[argv[1]], args)
    try:
        if 'self' in args:
            obj = args.pop('self')
            _COMMANDS[argv[1]](obj, **args)
        else:
            _COMMANDS[argv[1]](**args)
    except db.Error as e:
        # Lose the stack trace; it's not useful for DB errors
        print e
        return 1
    finally:
        if 'dbh' in args:
            args['dbh'].Close()
コード例 #4
0
ファイル: sql_batch.py プロジェクト: zihaozhu93/mysql-tools
def main(argv):
    if len(argv) != 2:
        raise app.UsageError('Please specify a dbspec')

    if FLAGS.output_type not in _RESULT_WRITERS:
        raise app.UsageError(
            'Unrecognized output type %r. Must be one of %r.' %
            (FLAGS.output_type, _RESULT_WRITERS.keys()))
    result_writer_cls = _RESULT_WRITERS[FLAGS.output_type]

    with db.Connect(argv[1], charset=FLAGS.charset) as dbh:
        results = dbh.ExecuteOrDie(FLAGS.query or sys.stdin.read())
        with result_writer_cls() as result_writer:
            result_writer.Write(results)
コード例 #5
0
def main(unused_args):
    assert FLAGS.db, 'Please pass --db'
    assert FLAGS.table, 'Please pass --table'
    assert FLAGS.condition, 'Please pass --condition'

    dbh = db.Connect(FLAGS.db)

    database_name = db.Spec.Parse(FLAGS.db)['db']

    groundskeeper = willie.Willie(dbh, database_name, FLAGS.table,
                                  FLAGS.condition, FLAGS.limit,
                                  FLAGS.utilization_percent, FLAGS.dry_run,
                                  FLAGS.writer_type, FLAGS.filename)
    groundskeeper.Loop()

    dbh.Close()
コード例 #6
0
ファイル: sql.py プロジェクト: zihaozhu93/mysql-tools
def main(argv):
  if len(argv) < 2:
    raise app.UsageError('Please specify a dbspec')

  try:
    histfile = os.path.join(os.environ['HOME'], '.mysql_history')
    readline.read_history_file(histfile)
    atexit.register(readline.write_history_file, histfile)
  except (KeyError, IOError):
    pass

  if sys.stdin.isatty():
    if FLAGS.prompt:
      prompt = '%s> ' % FLAGS.prompt
    else:
      prompt = '%s> ' % argv[1]
    continued_prompt = ' ' * (len(prompt) - 3) + '-> '
  else:
    prompt = continued_prompt = ''

  continued = [False]

  def GetLines():
    while True:
      try:
        display_prompt = continued_prompt if continued[0] else prompt
        continued[0] = True
        yield raw_input(display_prompt).decode(FLAGS.charset)
      except EOFError:
        print
        return

  with db.Connect(argv[1], charset=FLAGS.charset) as dbh:
    for statement in db.XCombineSQL(GetLines()):
      continued[0] = False
      executor = CancellableExecutor(dbh)
      try:
        executor.Execute(statement)
      except KeyboardInterrupt:
        print ('Cancelling current query. '
               'Hitting ^C again will terminate the program.')
        executor.CancelOngoingOperation()
コード例 #7
0
 def initialize(self):
     self.conn = db.Connect(self.dbspec)
     assert self.conn is not None
コード例 #8
0
ファイル: pipelines.py プロジェクト: MahmoudHassan/adspider
 def initialize(self):
     self.conn = db.Connect(self.dbspec)
     if self.conn is not None:
         self.create_ads_profile_table()
         self.create_ads_refer_graph_table()
         self.create_and_update_refer_graph_trigger()
コード例 #9
0
def main(unused_argv):
    assert FLAGS.db, 'Please pass --db'

    with db.Connect(FLAGS.db) as dbh:
        FindDuplicateIndexes(dbh)
        FindNonTransactionalTables(dbh)