MCPcopy Create free account
hub / github.com/chasingboy/Xtools / run

Method run

xtools.py:399–427  ·  view source on GitHub ↗
(self, edit)

Source from the content-addressed store, hash-verified

397
398class CurlDownloadFileCommand(sublime_plugin.TextCommand):
399 def run(self, edit):
400 text = get_buffer_text(self.view).strip('\n')
401 global workdir
402 file = write_file(workdir,text)
403 ticks = str(int(time.time()))
404
405 workdir = os.path.join(HOME,'Desktop','work')
406 dwdir = os.path.join(workdir,ticks)
407
408 if os.path.exists(workdir) == False:
409 os.mkdir(workdir)
410 os.mkdir(dwdir)
411 else:
412 os.mkdir(dwdir)
413
414 errurls = is_url(text.split('\n'))
415 if len(errurls) > 0:
416 sublime.message_dialog('[error] Urls are invaild! Please check...')
417 panel_print(self.view, edit, '[-] The invaild urls:\n' + errurls)
418 return
419
420 if os.path.exists(workdir):
421 if platform == 'windows':
422 cmd = '"cd {dir} && FOR /f %f IN ({file}) DO curl -k -O %f"'.format(dir=dwdir,file=file)
423 else:
424 cmd = 'cd {dir};for line in $(cat {file});do curl -k -O ${line};done;'.format(dir=dwdir,file=file,line='{line}')
425 exec_command(cmd)
426 else:
427 panel_print(self.view, edit, '[!] $HOME/Desktop/work folder not exists!')
428
429
430# Format tools result

Callers

nothing calls this directly

Calls 5

get_buffer_textFunction · 0.85
write_fileFunction · 0.85
is_urlFunction · 0.85
panel_printFunction · 0.85
exec_commandFunction · 0.85

Tested by

no test coverage detected