def setup_common_options(program_name, desc_str, usage_str, append=False, server=True, server_default="root@localhost:3306"): """Setup option parser and options common to all MySQL Utilities. This method creates an option parser and adds options for user login and connection options to a MySQL database system including user, password, host, socket, and port. program_name[in] The program name desc_str[in] The description of the utility usage_str[in] A brief usage example append[in] If True, allow --server to be specified multiple times (default = False) server[in] If True, add the --server option (default = True) server_default[in] Default value for option (default = "root@localhost:3306") Returns parser object """ parser = optparse.OptionParser( version=VERSION_FRM.format(program=program_name), description=desc_str, usage=usage_str, add_help_option=False, option_class=CaseInsensitiveChoicesOption) parser.add_option("--help", action="help", help="display a help message " "and exit") if server: # Connection information for the first server if append: parser.add_option("--server", action="append", dest="server", help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>].") else: parser.add_option("--server", action="store", dest="server", type="string", default=server_default, help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>].") return parser
def setup_common_options(program_name, desc_str, usage_str, append=False, server=True, server_default="root@localhost:3306"): """Setup option parser and options common to all MySQL Utilities. This method creates an option parser and adds options for user login and connection options to a MySQL database system including user, password, host, socket, and port. program_name[in] The program name desc_str[in] The description of the utility usage_str[in] A brief usage example append[in] If True, allow --server to be specified multiple times (default = False) server[in] If True, add the --server option (default = True) server_default[in] Default value for option (default = "root@localhost:3306") Returns parser object """ program_name = program_name.replace(".py","") parser = UtilitiesParser( version=VERSION_FRM.format(program=program_name), description=desc_str, usage=usage_str, add_help_option=False, option_class=CaseInsensitiveChoicesOption, prog=program_name) parser.add_option("--help", action="help", help="display a help message " "and exit") parser.add_option("--license", action='callback', callback=license_callback, help="display program's license and exit") if server: # Connection information for the first server if append: parser.add_option("--server", action="append", dest="server", help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>].") else: parser.add_option("--server", action="store", dest="server", type="string", default=server_default, help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>].") return parser
simply specify the colon like this: /home/me/data1/:t1.frm. In this case, the database will be omitted from the CREATE statement. - If you use the --new-storage-engine option, you must also provide the --frmdir option. When these options are specified, the utility will generate a new .frm file (prefixed with 'new_') and save it in the --frmdir= directory. Enjoy! """ if __name__ == '__main__': # Setup the command parser program = os.path.basename(sys.argv[0]).replace(".py", "") parser = MyParser(version=VERSION_FRM.format(program=program), description=DESCRIPTION, usage=USAGE, add_help_option=False, option_class=CaseInsensitiveChoicesOption, epilog=EXTENDED_HELP, prog=program) # Add --License option parser.add_option("--license", action='callback', callback=license_callback, help="display program's license and exit") # Add --help option parser.add_option("--help", action="help")
from mysql.utilities.command.audit_log import command_requires_server from mysql.utilities import VERSION_FRM class MyParser(optparse.OptionParser): def format_epilog(self, formatter): return self.epilog # Constants NAME = "MySQL Utilities - mysqlauditadmin " DESCRIPTION = "mysqlauditadmin - audit log maintenance utility " USAGE = "%prog --server=user:pass@host:port --show-options " # Setup the command parser parser = MyParser( version=VERSION_FRM.format(program=os.path.basename(sys.argv[0])), description=DESCRIPTION, usage=USAGE, add_help_option=False, option_class=CaseInsensitiveChoicesOption, epilog=audit_log.VALID_COMMANDS_TEXT) # Default option to provide help information parser.add_option("--help", action="help", help="display this help message " "and exit") # Setup utility-specific options: # Connection information for the source server parser.add_option("--server", action="store", dest="server", type="string", default=None,
raise ValueError except ValueError: parser.error("Invalid argument assignment: {0}. Please " "check your command.".format(arg)) variables.append({'name': name, 'value': value}) arguments.remove(arg) if len(arguments) > 0: parser.error("Unbalanced arguments. Please check your command.") for i in range(0, len(arguments), 2): variables.append({'name': arguments[i], 'value': arguments[i + 1]}) return variables # Setup the command parser program = os.path.basename(sys.argv[0]).replace(".py", "") parser = UtilitiesParser(version=VERSION_FRM.format(program=program), description=DESCRIPTION, usage=USAGE, add_help_option=False, prog=program) # Default option to provide help information parser.add_option("--help", action="help", help="display this help message and exit") # Add --License option parser.add_option("--license", action='callback', callback=license_callback, help="display program's license and exit")
return self.epilog # Constants NAME = "MySQL Utilities - mysqlauditgrep " DESCRIPTION = "mysqlauditgrep - audit log search utility " USAGE = "%prog [options] AUDIT_LOG_FILE " # Check for connector/python if not check_connector_python(): sys.exit(1) if __name__ == '__main__': # Setup the command parser program = os.path.basename(sys.argv[0]).replace(".py", "") parser = MyParser( version=VERSION_FRM.format(program=program), description=DESCRIPTION, usage=USAGE, add_help_option=False, option_class=CaseInsensitiveChoicesOption, epilog="", prog=program ) # Default option to provide help information parser.add_option("--help", action="help", help="display this help message and exit") # Add --License option parser.add_option("--license", action='callback', callback=license_callback,
from mysql.utilities.common.options import add_verbosity, check_verbosity from mysql.utilities.exception import UtilError from mysql.utilities.command import userclone from mysql.utilities import VERSION_FRM # Constants NAME = "MySQL Utilities - mysqluserclone " DESCRIPTION = "mysqluserclone - clone a MySQL user account to" + \ " one or more new users" USAGE = "%prog --source=user:pass@host:port:socket " \ "--destination=user:pass@host:port:socket " \ "joe@localhost sam:secret1@localhost" # Setup the command parser parser = optparse.OptionParser( version=VERSION_FRM.format(program=os.path.basename(sys.argv[0])), description=DESCRIPTION, usage=USAGE, add_help_option=False) parser.add_option("--help", action="help") # Setup utility-specific options: # Connection information for the source server parser.add_option("--source", action="store", dest="source", type = "string", default="root@localhost:3306", help="connection information for source server in " + \ "the form: <user>:<password>@<host>:<port>:<socket>") # Connection information for the destination server parser.add_option("--destination", action="store", dest="destination",
return self.epilog # Constants NAME = "MySQL Utilities - mysqlauditadmin " DESCRIPTION = "mysqlauditadmin - audit log maintenance utility " USAGE = "%prog --server=user:pass@host:port --show-options " # Check for connector/python if not check_connector_python(): sys.exit(1) if __name__ == '__main__': # Setup the command parser program = os.path.basename(sys.argv[0]).replace(".py", "") parser = MyParser( version=VERSION_FRM.format(program=program), description=DESCRIPTION, usage=USAGE, add_help_option=False, option_class=CaseInsensitiveChoicesOption, epilog=audit_log.VALID_COMMANDS_TEXT, prog=program ) # Default option to provide help information parser.add_option("--help", action="help", help="display this help message and exit") # Add --License option parser.add_option("--license", action='callback', callback=license_callback,
def setup_common_options(program_name, desc_str, usage_str, append=False, server=True, server_default="root@localhost:3306", extended_help=None, add_ssl=False): """Setup option parser and options common to all MySQL Utilities. This method creates an option parser and adds options for user login and connection options to a MySQL database system including user, password, host, socket, and port. program_name[in] The program name desc_str[in] The description of the utility usage_str[in] A brief usage example append[in] If True, allow --server to be specified multiple times (default = False) server[in] If True, add the --server option (default = True) server_default[in] Default value for option (default = "root@localhost:3306") extended_help[in] Extended help (by default: None). add_ssl[in] adds the --ssl-options, however these are added automatically if server is True, (default = False) Returns parser object """ program_name = program_name.replace(".py", "") parser = UtilitiesParser(version=VERSION_FRM.format(program=program_name), description=desc_str, usage=usage_str, add_help_option=False, option_class=CaseInsensitiveChoicesOption, epilog=extended_help, prog=program_name) parser.add_option("--help", action="help", help="display a help message " "and exit") parser.add_option("--license", action='callback', callback=license_callback, help="display program's license and exit") if server: # Connection information for the first server if append: parser.add_option("--server", action="append", dest="server", help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>] or <config-path>[<[group]>].") else: parser.add_option("--server", action="store", dest="server", type="string", default=server_default, help="connection information for the server in " "the form: <user>[:<password>]@<host>[:<port>]" "[:<socket>] or <login-path>[:<port>]" "[:<socket>] or <config-path>[<[group]>].") if server or add_ssl: add_ssl_options(parser) return parser