@@ -166,17 +166,24 @@ def parse_options(argv, prog=None):
166166
167167
168168@click .command
169- def cmd_dump ():
169+ @click .option ("--directory" ,default = "" ,help = "The target directory of the dump" )
170+ @click .option ("--fields" ,default = None ,help = "The fields to be dumped" )
171+ @click .option ("--delimiter" ,default = None ,help = "The delimiter of the exported data" )
172+ @click .option ("--format" ,default = "json" ,help = "The format of the export data" )
173+ @click .option ("--quiet" ,default = True ,help = "Verbose dump" )
174+ @click .opton ("--debug" ,default = False ,help = "Whether to debug or not" )
175+ @click .option ("--out_file" ,help = "The output file name" )
176+ def cmd_dump (directory ,fields ,delimiter ,format ,quiet ,debug ,out_file ):
170177"""
171178 Dump creates an archive of data from a RethinkDB cluster.
172179 """
173180click .echo ("dump command" )
174- argv = None
175- prog = None
181+ # argv = None
182+ # prog = None
176183
177- options = parse_options (argv or sys .argv [1 :],prog = prog )
184+ # options = parse_options(argv or sys.argv[1:], prog=prog)
178185try :
179- if not options . quiet :
186+ if not quiet :
180187# Print a warning about the capabilities of dump, so no one is confused (hopefully)
181188print (
182189"""\
@@ -191,42 +198,60 @@ def cmd_dump():
191198
192199# -- _export options - need to be kep in-sync with _export
193200
194- options .directory = os .path .realpath (tempfile .mkdtemp (dir = options .temp_dir ))
195- options .fields = None
196- options .delimiter = None
197- options .format = "json"
201+ # options.directory = os.path.realpath(tempfile.mkdtemp(dir=options.temp_dir))
202+ # options.fields = None
203+ # options.delimiter = None
204+ # options.format = "json"
198205
199206# -- export to a directory
200207
201- if not options .quiet :
208+ # if not options.quiet:
209+ # print(" Exporting to temporary directory...")
210+ if not quiet :
202211print (" Exporting to temporary directory..." )
203212
204213try :
205- cmd_export .run (options )
214+ # cmd_export.run(options)
215+ cmd_export .run ({
216+ "directory" :directory ,
217+ "quiet" :quiet ,
218+ "fields" :fields ,
219+ "delimter" :delimiter ,
220+ "format" :format
221+ })
206222except Exception as exc :
207223# default_logger.exception(exc)
208224
209- if options .debug :
225+ # if options.debug:
226+ if debug :
210227sys .stderr .write (f"\n { traceback .format_exc ()} \n " )
211228
212229raise Exception (f"Error: export failed,{ exc } " )
213230
214231# -- zip directory
215232
216- if not options .quiet :
233+ # if not options.quiet:
234+ if not quiet :
217235print (" Zipping export directory..." )
218236
219237try :
220- if hasattr (options .out_file ,"read" ):
221- archive = tarfile .open (fileobj = options .out_file ,mode = "w:gz" )
238+ # if hasattr(options.out_file, "read"):
239+ if hasattr (out_file ,"read" )
240+ # archive = tarfile.open(fileobj=options.out_file, mode="w:gz")
241+ archive = tarfile .open (fileobj = out_file ,mode = "w:gz" )
222242else :
223- archive = tarfile .open (name = options .out_file ,mode = "w:gz" )
224- for curr ,_ ,files in os .walk (os .path .realpath (options .directory )):
243+ # archive = tarfile.open(name=options.out_file, mode="w:gz")
244+ archive = tarfile .open (name = out_file ,mode = "w:gz" )
245+ # for curr, _, files in os.walk(os.path.realpath(options.directory)):
246+ for curr ,_ ,files in os .walk (os .path .realpath (directory )):
225247for data_file in files :
226- full_path = os .path .join (options .directory ,curr ,data_file )
248+ # full_path = os.path.join(options.directory, curr, data_file)
249+ full_path = os .path .join (directory ,curr ,data_file )
227250archive_path = os .path .join (
228- options .dump_name ,
229- os .path .relpath (full_path ,options .directory ),
251+ # options.dump_name,
252+ dump_name
253+ # os.path.relpath(full_path, options.directory),
254+ os .path .relpath (full_path ,directory ),
230255 )
231256archive .add (full_path ,arcname = archive_path )
232257os .unlink (full_path )
@@ -236,25 +261,32 @@ def cmd_dump():
236261
237262# --
238263
239- if not options .quiet :
264+ # if not options.quiet:
265+ if not quiet :
240266print (
241267"Done (%.2f seconds): %s"
242268% (
243269time .time ()- start_time ,
244- options .out_file .name
245- if hasattr (options .out_file ,"name" )
246- else options .out_file ,
270+ # options.out_file.name
271+ out_file .name
272+ # if hasattr(options.out_file, "name")
273+ if hasattr (out_file ,"name" )
274+ # else options.out_file,
275+ else out_file ,
247276 )
248277 )
249278except KeyboardInterrupt :
250279time .sleep (0.2 )
251280raise RuntimeError ("Interrupted" )
252281finally :
253- if os .path .exists (options .directory ):
254- shutil .rmtree (options .directory )
282+ # if os.path.exists(options.directory):
283+ # shutil.rmtree(options.directory)
284+ if os .path .exists (directory ):
285+ shutil .rmtree (directory )
255286
256287except Exception as ex :
257- if options .debug :
288+ # if options.debug:
289+ if debug :
258290traceback .print_exc ()
259291print (ex ,file = sys .stderr )
260292return 1