Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7ae9d0

Browse files
author
lsabi1234
committed
🚧 Add click options to dump
1 parent523c8b1 commitb7ae9d0

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

‎rethinkdb/cli/_dump.py‎

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,24 @@ def parse_options(argv, prog=None):
166166

167167

168168
@click.command
169-
defcmd_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+
defcmd_dump(directory,fields,delimiter,format,quiet,debug,out_file):
170177
"""
171178
Dump creates an archive of data from a RethinkDB cluster.
172179
"""
173180
click.echo("dump command")
174-
argv=None
175-
prog=None
181+
#argv = None
182+
#prog = None
176183

177-
options=parse_options(argvorsys.argv[1:],prog=prog)
184+
#options = parse_options(argv or sys.argv[1:], prog=prog)
178185
try:
179-
ifnotoptions.quiet:
186+
ifnotquiet:
180187
# Print a warning about the capabilities of dump, so no one is confused (hopefully)
181188
print(
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-
ifnotoptions.quiet:
208+
# if not options.quiet:
209+
# print(" Exporting to temporary directory...")
210+
ifnotquiet:
202211
print(" Exporting to temporary directory...")
203212

204213
try:
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+
})
206222
exceptExceptionasexc:
207223
# default_logger.exception(exc)
208224

209-
ifoptions.debug:
225+
# if options.debug:
226+
ifdebug:
210227
sys.stderr.write(f"\n{traceback.format_exc()}\n")
211228

212229
raiseException(f"Error: export failed,{exc}")
213230

214231
# -- zip directory
215232

216-
ifnotoptions.quiet:
233+
# if not options.quiet:
234+
ifnotquiet:
217235
print(" Zipping export directory...")
218236

219237
try:
220-
ifhasattr(options.out_file,"read"):
221-
archive=tarfile.open(fileobj=options.out_file,mode="w:gz")
238+
# if hasattr(options.out_file, "read"):
239+
ifhasattr(out_file,"read")
240+
# archive = tarfile.open(fileobj=options.out_file, mode="w:gz")
241+
archive=tarfile.open(fileobj=out_file,mode="w:gz")
222242
else:
223-
archive=tarfile.open(name=options.out_file,mode="w:gz")
224-
forcurr,_,filesinos.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+
forcurr,_,filesinos.walk(os.path.realpath(directory)):
225247
fordata_fileinfiles:
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)
227250
archive_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
)
231256
archive.add(full_path,arcname=archive_path)
232257
os.unlink(full_path)
@@ -236,25 +261,32 @@ def cmd_dump():
236261

237262
# --
238263

239-
ifnotoptions.quiet:
264+
# if not options.quiet:
265+
ifnotquiet:
240266
print(
241267
"Done (%.2f seconds): %s"
242268
% (
243269
time.time()-start_time,
244-
options.out_file.name
245-
ifhasattr(options.out_file,"name")
246-
elseoptions.out_file,
270+
# options.out_file.name
271+
out_file.name
272+
# if hasattr(options.out_file, "name")
273+
ifhasattr(out_file,"name")
274+
# else options.out_file,
275+
elseout_file,
247276
)
248277
)
249278
exceptKeyboardInterrupt:
250279
time.sleep(0.2)
251280
raiseRuntimeError("Interrupted")
252281
finally:
253-
ifos.path.exists(options.directory):
254-
shutil.rmtree(options.directory)
282+
# if os.path.exists(options.directory):
283+
# shutil.rmtree(options.directory)
284+
ifos.path.exists(directory):
285+
shutil.rmtree(directory)
255286

256287
exceptExceptionasex:
257-
ifoptions.debug:
288+
# if options.debug:
289+
ifdebug:
258290
traceback.print_exc()
259291
print(ex,file=sys.stderr)
260292
return1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp