コード例 #1
0
ファイル: mysqlmetagrep.py プロジェクト: juanga16/p111mil
_NO_SERVERS_ALLOWED_MSG = """You should not include servers in the
call if you are using the --sql option"""

# A --pattern is required.
if not options.pattern:
    parser.error("No pattern supplied.")

# Check that --sql option is not used with --server, and --server are
# supplied if --sql is not used.
if options.print_sql:
    if options.server is not None and len(options.server) > 0:
        parser.error(_NO_SERVERS_ALLOWED_MSG)
else:        
    if options.server is None or len(options.server) == 0:
        parser.error(_AT_LEAST_ONE_SERVER_MSG)

object_types = re.split(r"\s*,\s*", options.object_types)
command = ObjectGrep(options.pattern, options.database_pattern, object_types,
                     options.check_body, options.use_regexp)

try:
    if options.print_sql:
        print command.sql()
    else:
        command.execute(options.server, format=options.format)
except Exception as details:
    print >>sys.stderr, 'ERROR:', details

exit()
コード例 #2
0
_NO_SERVERS_ALLOWED_MSG = """You should not include servers in the
call if you are using the --sql option"""

# A --pattern is required.
if not options.pattern:
    parser.error("No pattern supplied.")

# Check that --sql option is not used with --server, and --server are
# supplied if --sql is not used.
if options.print_sql:
    if options.server is not None and len(options.server) > 0:
        parser.error(_NO_SERVERS_ALLOWED_MSG)
else:
    if options.server is None or len(options.server) == 0:
        parser.error(_AT_LEAST_ONE_SERVER_MSG)

object_types = re.split(r"\s*,\s*", options.object_types)
command = ObjectGrep(options.pattern, options.database_pattern, object_types, options.check_body, options.use_regexp)

try:
    if options.print_sql:
        print(command.sql())
    else:
        command.execute(options.server, format=options.format)
except Exception:
    _, details, _ = sys.exc_info()
    sys.stderr.write("ERROR: %s" % details)

sys.exit()
コード例 #3
0
        parser.error("No pattern supplied.")

    # Check that --sql option is not used with --server, and --server are
    # supplied if --sql is not used.
    if options.print_sql:
        if options.server is not None and len(options.server) > 0:
            parser.error(_NO_SERVERS_ALLOWED_MSG)
    else:
        if options.server is None or len(options.server) == 0:
            parser.error(_AT_LEAST_ONE_SERVER_MSG)

    object_types = re.split(r"\s*,\s*", options.object_types)

    try:
        command = ObjectGrep(options.pattern, options.database_pattern,
                             object_types, options.check_body,
                             options.use_regexp)
        if options.print_sql:
            print(command.sql())
        else:
            ssl_opts = get_ssl_dict(options)
            command.execute(options.server,
                            format=options.format,
                            charset=options.charset,
                            ssl_opts=ssl_opts)
    except UtilError:
        _, err, _ = sys.exc_info()
        sys.stderr.write("ERROR: {0}\n".format(err.errmsg))
        sys.exit(1)
    except:
        _, details, _ = sys.exc_info()
コード例 #4
0
        parser.error("No pattern supplied.")

    # Check that --sql option is not used with --server, and --server are
    # supplied if --sql is not used.
    if options.print_sql:
        if options.server is not None and len(options.server) > 0:
            parser.error(_NO_SERVERS_ALLOWED_MSG)
    else:
        if options.server is None or len(options.server) == 0:
            parser.error(_AT_LEAST_ONE_SERVER_MSG)

    object_types = re.split(r"\s*,\s*", options.object_types)

    try:
        command = ObjectGrep(options.pattern, options.database_pattern,
                             object_types, options.check_body,
                             options.use_regexp)
        if options.print_sql:
            print(command.sql())
        else:
            ssl_opts = get_ssl_dict(options)
            command.execute(options.server, format=options.format,
                            charset=options.charset, ssl_opts=ssl_opts)
    except UtilError:
        _, err, _ = sys.exc_info()
        sys.stderr.write("ERROR: {0}\n".format(err.errmsg))
        sys.exit(1)
    except:
        _, details, _ = sys.exc_info()
        sys.stderr.write("ERROR: {0}\n".format(details))
        sys.exit(1)