def parse_options(argv, prog=None): parser = utils_common.CommonOptionsParser(usage=usage, epilog=help_epilog, prog=prog) parser.add_option( "-r", "--rebuild", dest="db_table", metavar="DB|DB.TABLE", default=[], help="databases or tables to rebuild indexes on (default: all, may be specified multiple times)", action="append", type="db_table") parser.add_option( "-n", dest="concurrent", metavar="NUM", default=1, help="concurrent indexes to rebuild (default: 1)", type="pos_int") parser.add_option("--force", dest="force", action="store_true", default=False, help="rebuild non-outdated indexes") options, args = parser.parse_args(argv) # Check validity of arguments if len(args) != 0: parser.error("Error: No positional arguments supported. Unrecognized option '%s'" % args[0]) return options
def startInterpreter(argv=None, prog=None): repl_variables = {'r': net.Connection._r, 'rebirthdb': net.Connection._r} banner = 'The RethinkDB driver has been imported as `r`.' # -- get host/port setup # - parse command line parser = utils_common.CommonOptionsParser( prog=prog, description= 'An interactive Python shell (repl) with the RethinkDB driver imported' ) options, args = parser.parse_args( argv if argv is not None else sys.argv[1:], connect=False) if args: parser.error( 'No positional arguments supported. Unrecognized option(s): %s' % args) # -- open connection try: repl_variables['conn'] = options.retryQuery.conn() repl_variables['conn'].repl() banner += ''' A connection to %s:%d has been established as `conn` and can be used by calling `run()` on a query without any arguments.''' % ( options.hostname, options.driver_port) except errors.ReqlDriverError as e: banner += '\nWarning: %s' % str(e) if options.debug: banner += '\n' + traceback.format_exc() # -- start interpreter code.interact(banner=banner + '\n==========', local=repl_variables)
def parse_options(argv, prog=None): parser = utils_common.CommonOptionsParser(usage=usage, epilog=help_epilog, prog=prog) parser.add_option( "-f", "--file", dest="out_file", metavar="FILE", default=None, help= 'file to write archive to (defaults to rethinkdb_dump_DATE_TIME.tar.gz);\nif FILE is -, use standard ' 'output (note that intermediate files will still be written to the --temp-dir directory)' ) parser.add_option( "-e", "--export", dest="db_tables", metavar="DB|DB.TABLE", default=[], help= 'limit dump to the given database or table (may be specified multiple times)', action="append") parser.add_option("--temp-dir", dest="temp_dir", metavar="directory", default=None, help='the directory to use for intermediary results') parser.add_option("--overwrite-file", dest="overwrite", default=False, help="overwrite -f/--file if it exists", action="store_true") parser.add_option( "--clients", dest="clients", metavar="NUM", default=3, help='number of tables to export simultaneously (default: 3)', type="pos_int") parser.add_option("--read-outdated", dest="outdated", default=False, help='use outdated read mode', action="store_true") options, args = parser.parse_args(argv) # Check validity of arguments if len(args) != 0: raise parser.error( "No positional arguments supported. Unrecognized option(s): %s" % args) # Add dump name if platform.system() == "Windows" or platform.system().lower().startswith( 'cygwin'): options.dump_name = "rethinkdb_dump_%s" % datetime.datetime.today( ).strftime("%Y-%m-%dT%H-%M-%S") # no colons in name else: options.dump_name = "rethinkdb_dump_%s" % datetime.datetime.today( ).strftime("%Y-%m-%dT%H:%M:%S") # Verify valid output file if options.out_file == "-": options.out_file = sys.stdout options.quiet = True elif options.out_file is None: options.out_file = os.path.realpath("%s.tar.gz" % options.dump_name) else: options.out_file = os.path.realpath(options.out_file) if not (options.out_file is not sys.stdout): if os.path.exists(options.out_file) and not options.overwrite: parser.error("Output file already exists: %s" % options.out_file) if os.path.exists( options.out_file) and not os.path.isfile(options.out_file): parser.error("There is a non-file at the -f/--file location: %s" % options.out_file) # Verify valid client count if options.clients < 1: raise RuntimeError( "Error: invalid number of clients (%d), must be greater than zero" % options.clients) # Make sure the temporary directory exists and is accessible if options.temp_dir is not None: if not os.path.exists(options.temp_dir): try: os.makedirs(options.temp_dir) except OSError: parser.error("Could not create temporary directory: %s" % options.temp_dir) if not os.path.isdir(options.temp_dir): parser.error( "Temporary directory doesn't exist or is not a directory: %s" % options.temp_dir) if not os.access(options.temp_dir, os.W_OK): parser.error("Temporary directory inaccessible: %s" % options.temp_dir) return options
def parse_options(argv, prog=None): if platform.system() == "Windows" or platform.system().lower().startswith('cygwin'): # no colons in name default_dir = "rethinkdb_export_%s" % datetime.datetime.today().strftime("%Y-%m-%dT%H-%M-%S") else: # " default_dir = "rethinkdb_export_%s" % datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%S") parser = utils_common.CommonOptionsParser(usage=usage, description=help_description, epilog=help_epilog, prog=prog) parser.add_option("-d", "--directory", dest="directory", metavar="DIRECTORY", default=default_dir, help='directory to output to (default: rethinkdb_export_DATE_TIME)', type="new_file") parser.add_option( "-e", "--export", dest="db_tables", metavar="DB|DB.TABLE", default=[], help='limit dump to the given database or table (may be specified multiple times)', action="append", type="db_table") parser.add_option("--fields", dest="fields", metavar="<FIELD>,...", default=None, help='export only specified fields (required for CSV format)') parser.add_option( "--format", dest="format", metavar="json|csv|ndjson", default="json", help='format to write (defaults to json. ndjson is newline delimited json.)', type="choice", choices=[ 'json', 'csv', 'ndjson']) parser.add_option( "--clients", dest="clients", metavar="NUM", default=3, help='number of tables to export simultaneously (default: 3)', type="pos_int") parser.add_option( "--read-outdated", dest="outdated", default=False, help='use outdated read mode', action="store_true") csvGroup = optparse.OptionGroup(parser, 'CSV options') csvGroup.add_option("--delimiter", dest="delimiter", metavar="CHARACTER", default=None, help="character to be used as field delimiter, or '\\t' for tab (default: ',')") parser.add_option_group(csvGroup) options, args = parser.parse_args(argv) # -- Check validity of arguments if len(args) != 0: parser.error("No positional arguments supported. Unrecognized option(s): %s" % args) if options.fields: if len(options.db_tables) != 1 or options.db_tables[0].table is None: parser.error("The --fields option can only be used when exporting a single table") options.fields = options.fields.split(",") # - format specific validation if options.format == "csv": if options.fields is None: parser.error("CSV files require the '--fields' option to be specified.") if options.delimiter is None: options.delimiter = "," elif options.delimiter == "\\t": options.delimiter = "\t" elif len(options.delimiter) != 1: parser.error("Specify exactly one character for the --delimiter option: %s" % options.delimiter) else: if options.delimiter: parser.error("--delimiter option is only valid for CSV file formats") # - return options
def parse_options(argv, prog=None): parser = utils_common.CommonOptionsParser(usage=usage, epilog=help_epilog, prog=prog) parser.add_option( "-i", "--import", dest="db_tables", metavar="DB|DB.TABLE", default=[], help= "limit restore to the given database or table (may be specified multiple times)", action="append", type="db_table") parser.add_option("--temp-dir", dest="temp_dir", metavar="DIR", default=None, help="directory to use for intermediary results") parser.add_option("--clients", dest="clients", metavar="CLIENTS", default=8, help="client connections to use (default: 8)", type="pos_int") parser.add_option( "--hard-durability", dest="durability", action="store_const", default="soft", help="use hard durability writes (slower, uses less memory)", const="hard") parser.add_option("--force", dest="force", action="store_true", default=False, help="import data even if a table already exists") parser.add_option( "--no-secondary-indexes", dest="indexes", action="store_false", default=None, help="do not create secondary indexes for the restored tables") parser.add_option("--writers-per-table", dest="writers", default=multiprocessing.cpu_count(), help=optparse.SUPPRESS_HELP, type="pos_int") parser.add_option("--batch-size", dest="batch_size", default=utils_common.default_batch_size, help=optparse.SUPPRESS_HELP, type="pos_int") # Replication settings replicationOptionsGroup = optparse.OptionGroup(parser, 'Replication Options') replicationOptionsGroup.add_option( "--shards", dest="create_args", metavar="SHARDS", help="shards to setup on created tables (default: 1)", type="pos_int", action="add_key") replicationOptionsGroup.add_option( "--replicas", dest="create_args", metavar="REPLICAS", help="replicas to setup on created tables (default: 1)", type="pos_int", action="add_key") parser.add_option_group(replicationOptionsGroup) options, args = parser.parse_args(argv) # -- Check validity of arguments # - archive if len(args) == 0: parser.error( "Archive to import not specified. Provide an archive file created by rebirthdb-dump." ) elif len(args) != 1: parser.error("Only one positional argument supported") options.in_file = args[0] if options.in_file == '-': options.in_file = sys.stdin else: if not os.path.isfile(options.in_file): parser.error("Archive file does not exist: %s" % options.in_file) options.in_file = os.path.realpath(options.in_file) # - temp_dir if options.temp_dir: if not os.path.isdir(options.temp_dir): parser.error( "Temporary directory doesn't exist or is not a directory: %s" % options.temp_dir) if not os.access(options["temp_dir"], os.W_OK): parser.error("Temporary directory inaccessible: %s" % options.temp_dir) # - create_args if options.create_args is None: options.create_args = {} # -- return options