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

Commita50f822

Browse files
authored
🚧 Remove the click command library references
1 parent753bb1f commita50f822

File tree

1 file changed

+33
-70
lines changed

1 file changed

+33
-70
lines changed

‎rethinkdb/cli/_dump.py‎

Lines changed: 33 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"""
2121
Dump creates an archive of data from a RethinkDB cluster.
2222
"""
23-
importclick
24-
2523
importdatetime
2624
importos
2725
importplatform
@@ -165,25 +163,10 @@ def parse_options(argv, prog=None):
165163
returnoptions
166164

167165

168-
@click.command
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):
177-
"""
178-
Dump creates an archive of data from a RethinkDB cluster.
179-
"""
180-
click.echo("dump command")
181-
# argv = None
182-
# prog = None
183-
184-
# options = parse_options(argv or sys.argv[1:], prog=prog)
166+
defmain(argv=None,prog=None):
167+
options=parse_options(argvorsys.argv[1:],prog=prog)
185168
try:
186-
ifnotquiet:
169+
ifnotoptions.quiet:
187170
# Print a warning about the capabilities of dump, so no one is confused (hopefully)
188171
print(
189172
"""\
@@ -198,60 +181,42 @@ def cmd_dump(directory, fields, delimiter, format, quiet, debug, out_file):
198181

199182
# -- _export options - need to be kep in-sync with _export
200183

201-
#options.directory = os.path.realpath(tempfile.mkdtemp(dir=options.temp_dir))
202-
#options.fields = None
203-
#options.delimiter = None
204-
#options.format = "json"
184+
options.directory=os.path.realpath(tempfile.mkdtemp(dir=options.temp_dir))
185+
options.fields=None
186+
options.delimiter=None
187+
options.format="json"
205188

206189
# -- export to a directory
207190

208-
# if not options.quiet:
209-
# print(" Exporting to temporary directory...")
210-
ifnotquiet:
191+
ifnotoptions.quiet:
211192
print(" Exporting to temporary directory...")
212193

213194
try:
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-
})
195+
_export.run(options)
222196
exceptExceptionasexc:
223-
#default_logger.exception(exc)
197+
default_logger.exception(exc)
224198

225-
# if options.debug:
226-
ifdebug:
227-
sys.stderr.write(f"\n{traceback.format_exc()}\n")
199+
ifoptions.debug:
200+
sys.stderr.write("\n%s\n"%traceback.format_exc())
228201

229-
raiseException(f"Error: export failed,{exc}")
202+
raiseException("Error: export failed,%s"%exc)
230203

231204
# -- zip directory
232205

233-
# if not options.quiet:
234-
ifnotquiet:
206+
ifnotoptions.quiet:
235207
print(" Zipping export directory...")
236208

237209
try:
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")
210+
ifhasattr(options.out_file,"read"):
211+
archive=tarfile.open(fileobj=options.out_file,mode="w:gz")
242212
else:
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)):
213+
archive=tarfile.open(name=options.out_file,mode="w:gz")
214+
forcurr,_,filesinos.walk(os.path.realpath(options.directory)):
247215
fordata_fileinfiles:
248-
# full_path = os.path.join(options.directory, curr, data_file)
249-
full_path=os.path.join(directory,curr,data_file)
216+
full_path=os.path.join(options.directory,curr,data_file)
250217
archive_path=os.path.join(
251-
# options.dump_name,
252-
dump_name
253-
# os.path.relpath(full_path, options.directory),
254-
os.path.relpath(full_path,directory),
218+
options.dump_name,
219+
os.path.relpath(full_path,options.directory),
255220
)
256221
archive.add(full_path,arcname=archive_path)
257222
os.unlink(full_path)
@@ -261,32 +226,30 @@ def cmd_dump(directory, fields, delimiter, format, quiet, debug, out_file):
261226

262227
# --
263228

264-
# if not options.quiet:
265-
ifnotquiet:
229+
ifnotoptions.quiet:
266230
print(
267231
"Done (%.2f seconds): %s"
268232
% (
269233
time.time()-start_time,
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,
234+
options.out_file.name
235+
ifhasattr(options.out_file,"name")
236+
elseoptions.out_file,
276237
)
277238
)
278239
exceptKeyboardInterrupt:
279240
time.sleep(0.2)
280241
raiseRuntimeError("Interrupted")
281242
finally:
282-
# if os.path.exists(options.directory):
283-
# shutil.rmtree(options.directory)
284-
ifos.path.exists(directory):
285-
shutil.rmtree(directory)
243+
ifos.path.exists(options.directory):
244+
shutil.rmtree(options.directory)
286245

287246
exceptExceptionasex:
288-
# if options.debug:
289-
ifdebug:
247+
ifoptions.debug:
290248
traceback.print_exc()
291249
print(ex,file=sys.stderr)
292250
return1
251+
return0
252+
253+
254+
if__name__=="__main__":
255+
sys.exit(main())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp