if (options.server is None or len(options.server) == 0) \
            and not options.print_sql:
        parser.error("You need at least one server if you're not using the "
                     "--sql option")
    elif options.server is not None and len(options.server) > 0 \
            and options.print_sql:
        parser.error("You should not include servers in the call if you are "
                     "using the --sql option")

    # If no option was supplied, we print the processes by default
    if len(options.actions) == 0:
        options.actions.append(PRINT_PROCESS)

    try:
        command = ProcessGrep(options.matches,
                              options.actions,
                              options.use_regexp,
                              age=options.age)
        if options.print_sql:
            print(command.sql(options.sql_body).strip())
        else:
            ssl_opts = get_ssl_dict(options)
            command.execute(options.server,
                            format=options.format,
                            charset=options.charset,
                            ssl_opts=ssl_opts)
    except EmptyResultError:
        _, details, _ = sys.exc_info()
        sys.stderr.write("No matches\n")
        sys.exit(1)
    except:
        _, details, _ = sys.exc_info()
# Print SQL if only --sql-body is given
if options.sql_body:
    options.print_sql = True

if (options.server is None or len(options.server) == 0) and not options.print_sql:
    parser.error("You need at least one server if you're not using the --sql option")
elif options.server is not None and len(options.server) > 0 and options.print_sql:
    parser.error("You should not include servers in the call if you are using the --sql option")

# If no option was supplied, we print the processes by default
if len(options.actions) == 0:
    options.actions.append(PRINT_PROCESS)

try:
    command = ProcessGrep(options.matches, options.actions, options.use_regexp,
                          age=options.age)
    if options.print_sql:
        print(command.sql(options.sql_body).strip())
    else:
        command.execute(options.server, format=options.format)
except EmptyResultError:
    _, details, _ = sys.exc_info()
    sys.stderr.write("No matches")
    sys.exit(1)
except Exception:
    _, details, _ = sys.exc_info()
    sys.stderr.write('ERROR: %s' % details)
    sys.exit(2)

sys.exit()
Example #3
0
        or len(options.server) == 0) and not options.print_sql:
    parser.error(
        "You need at least one server if you're not using the --sql option")
elif options.server is not None and len(
        options.server) > 0 and options.print_sql:
    parser.error(
        "You should not include servers in the call if you are using the --sql option"
    )

# If no option was supplied, we print the processes by default
if len(options.actions) == 0:
    options.actions.append(PRINT_PROCESS)

try:
    command = ProcessGrep(options.matches,
                          options.actions,
                          options.use_regexp,
                          age=options.age)
    if options.print_sql:
        print command.sql(options.sql_body).strip()
    else:
        command.execute(options.server, format=options.format)
except EmptyResultError as details:
    print >> sys.stderr, "No matches"
    exit(1)
except Exception as details:
    print >> sys.stderr, 'ERROR:', details
    exit(2)

exit()
Example #4
0
    if (options.server is None or len(options.server) == 0) \
            and not options.print_sql:
        parser.error("You need at least one server if you're not using the "
                     "--sql option")
    elif options.server is not None and len(options.server) > 0 \
            and options.print_sql:
        parser.error("You should not include servers in the call if you are "
                     "using the --sql option")

    # If no option was supplied, we print the processes by default
    if len(options.actions) == 0:
        options.actions.append(PRINT_PROCESS)

    try:
        command = ProcessGrep(options.matches, options.actions,
                              options.use_regexp,
                              age=options.age)
        if options.print_sql:
            print(command.sql(options.sql_body).strip())
        else:
            ssl_opts = get_ssl_dict(options)
            command.execute(options.server, format=options.format,
                            charset=options.charset, ssl_opts=ssl_opts)
    except EmptyResultError:
        _, details, _ = sys.exc_info()
        sys.stderr.write("No matches\n")
        sys.exit(1)
    except Exception:
        _, details, _ = sys.exc_info()
        sys.stderr.write('ERROR: {0}\n'.format(details))
        sys.exit(2)