本文整理汇总了Python中TriblerGUI.tribler_request_manager.TriblerRequestManager.download_file方法的典型用法代码示例。如果您正苦于以下问题:Python TriblerRequestManager.download_file方法的具体用法?Python TriblerRequestManager.download_file怎么用?Python TriblerRequestManager.download_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriblerGUI.tribler_request_manager.TriblerRequestManager
的用法示例。
在下文中一共展示了TriblerRequestManager.download_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_export_download_dialog_done
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import download_file [as 别名]
def on_export_download_dialog_done(action):
if action == 0:
dest_path = os.path.join(export_dir, dialog.dialog_widget.dialog_input.text())
request_mgr = TriblerRequestManager()
request_mgr.download_file("channels/discovered/%s/mdblob" % mdblob_name,
lambda data: on_export_download_request_done(dest_path, data))
dialog.close_dialog()
示例2: DebugWindow
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import download_file [as 别名]
#.........这里部分代码省略.........
if 'profiler_file' in data:
QMessageBox.about(self,
"Profiler statistics saved",
"The profiler data has been saved to %s." % data['profiler_file'])
def refresh_memory_plot(self):
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("debug/memory/history", self.on_core_memory_history)
def on_core_memory_history(self, data):
if not data:
return
plot_data = [[], []]
for mem_info in data["memory_history"]:
plot_data[0].append(datetime.datetime.fromtimestamp(mem_info["time"]))
plot_data[1].append(mem_info["mem"] / 1024 / 1024)
if len(plot_data[0]) == 0:
plot_data = [[datetime.datetime.now()], [0]]
self.memory_plot.plot_data = plot_data
self.memory_plot.compute_initial_figure()
def on_memory_dump_button_clicked(self, dump_core):
self.export_dir = QFileDialog.getExistingDirectory(self, "Please select the destination directory", "",
QFileDialog.ShowDirsOnly)
if len(self.export_dir) > 0:
filename = "tribler_mem_dump_%s_%s.json" % \
('core' if dump_core else 'gui', datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))
if dump_core:
self.request_mgr = TriblerRequestManager()
self.request_mgr.download_file("debug/memory/dump",
lambda data: self.on_memory_dump_data_available(filename, data))
elif scanner:
scanner.dump_all_objects(os.path.join(self.export_dir, filename))
else:
ConfirmationDialog.show_error(self.window(),
"Error when performing a memory dump",
"meliae memory dumper is not compatible with Python 3")
def on_memory_dump_data_available(self, filename, data):
if not data:
return
dest_path = os.path.join(self.export_dir, filename)
try:
memory_dump_file = open(dest_path, "wb")
memory_dump_file.write(data)
memory_dump_file.close()
except IOError as exc:
ConfirmationDialog.show_error(self.window(),
"Error when exporting file",
"An error occurred when exporting the torrent file: %s" % str(exc))
def closeEvent(self, close_event):
self.request_mgr.cancel_request()
if self.cpu_plot_timer:
self.cpu_plot_timer.stop()
if self.memory_plot_timer:
self.memory_plot_timer.stop()
def load_logs_tab(self):
# Max lines from GUI
max_log_lines = self.window().max_lines_value.text()
示例3: DownloadsPage
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import download_file [as 别名]
#.........这里部分代码省略.........
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("downloads/%s" % infohash, lambda _: None,
method='PATCH', data='anon_hops=%d' % hops)
def on_explore_files(self):
for selected_item in self.selected_items:
path = os.path.normpath(os.path.join(self.window().tribler_settings['download_defaults']['saveas'],
selected_item.download_info["destination"]))
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
def on_export_download(self):
self.export_dir = QFileDialog.getExistingDirectory(self, "Please select the destination directory", "",
QFileDialog.ShowDirsOnly)
selected_item = self.selected_items[:1]
if len(self.export_dir) > 0 and selected_item:
# Show confirmation dialog where we specify the name of the file
torrent_name = selected_item[0].download_info['name']
self.dialog = ConfirmationDialog(self, "Export torrent file",
"Please enter the name of the torrent file:",
[('SAVE', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)],
show_input=True)
self.dialog.dialog_widget.dialog_input.setPlaceholderText('Torrent file name')
self.dialog.dialog_widget.dialog_input.setText("%s.torrent" % torrent_name)
self.dialog.dialog_widget.dialog_input.setFocus()
self.dialog.button_clicked.connect(self.on_export_download_dialog_done)
self.dialog.show()
def on_export_download_dialog_done(self, action):
selected_item = self.selected_items[:1]
if action == 0 and selected_item:
filename = self.dialog.dialog_widget.dialog_input.text()
self.request_mgr = TriblerRequestManager()
self.request_mgr.download_file("downloads/%s/torrent" % selected_item[0].download_info['infohash'],
lambda data: self.on_export_download_request_done(filename, data))
self.dialog.close_dialog()
self.dialog = None
def on_export_download_request_done(self, filename, data):
dest_path = os.path.join(self.export_dir, filename)
try:
torrent_file = open(dest_path, "wb")
torrent_file.write(data)
torrent_file.close()
except IOError as exc:
ConfirmationDialog.show_error(self.window(),
"Error when exporting file",
"An error occurred when exporting the torrent file: %s" % str(exc))
else:
self.window().tray_show_message("Torrent file exported", "Torrent file exported to %s" % dest_path)
def on_right_click_item(self, pos):
item_clicked = self.window().downloads_list.itemAt(pos)
if not item_clicked or self.selected_items is None:
return
if item_clicked not in self.selected_items:
self.selected_items.append(item_clicked)
menu = TriblerActionMenu(self)
start_action = QAction('Start', self)
stop_action = QAction('Stop', self)
remove_download_action = QAction('Remove download', self)
force_recheck_action = QAction('Force recheck', self)