Exemplo n.º 1
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 as details:
    print >>sys.stderr, 'ERROR:', details

exit()