Flake8 addtorrentdialog
This commit is contained in:
parent
7e4d50b406
commit
29a05978ec
|
@ -59,6 +59,7 @@ from deluge.ui.gtkui.path_chooser import PathChooser
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AddTorrentDialog(component.Component):
|
class AddTorrentDialog(component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
component.Component.__init__(self, "AddTorrentDialog")
|
component.Component.__init__(self, "AddTorrentDialog")
|
||||||
|
@ -95,8 +96,8 @@ class AddTorrentDialog(component.Component):
|
||||||
|
|
||||||
self.torrent_liststore = gtk.ListStore(str, str, str)
|
self.torrent_liststore = gtk.ListStore(str, str, str)
|
||||||
#download?, path, filesize, sequence number, inconsistent?
|
#download?, path, filesize, sequence number, inconsistent?
|
||||||
self.files_treestore = gtk.TreeStore(bool, str, gobject.TYPE_UINT64,
|
self.files_treestore = gtk.TreeStore(
|
||||||
gobject.TYPE_INT64, bool, str)
|
bool, str, gobject.TYPE_UINT64, gobject.TYPE_INT64, bool, str)
|
||||||
self.files_treestore.set_sort_column_id(1, gtk.SORT_ASCENDING)
|
self.files_treestore.set_sort_column_id(1, gtk.SORT_ASCENDING)
|
||||||
|
|
||||||
# Holds the files info
|
# Holds the files info
|
||||||
|
@ -107,7 +108,6 @@ class AddTorrentDialog(component.Component):
|
||||||
|
|
||||||
self.previous_selected_torrent = None
|
self.previous_selected_torrent = None
|
||||||
|
|
||||||
|
|
||||||
self.listview_torrents = self.builder.get_object("listview_torrents")
|
self.listview_torrents = self.builder.get_object("listview_torrents")
|
||||||
self.listview_files = self.builder.get_object("listview_files")
|
self.listview_files = self.builder.get_object("listview_files")
|
||||||
|
|
||||||
|
@ -142,8 +142,7 @@ class AddTorrentDialog(component.Component):
|
||||||
self.listview_files.set_model(self.files_treestore)
|
self.listview_files.set_model(self.files_treestore)
|
||||||
|
|
||||||
self.listview_files.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
self.listview_files.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
||||||
self.listview_torrents.get_selection().connect("changed",
|
self.listview_torrents.get_selection().connect("changed", self._on_torrent_changed)
|
||||||
self._on_torrent_changed)
|
|
||||||
|
|
||||||
self.setup_move_completed_path_chooser()
|
self.setup_move_completed_path_chooser()
|
||||||
self.setup_download_location_path_chooser()
|
self.setup_download_location_path_chooser()
|
||||||
|
@ -208,7 +207,6 @@ class AddTorrentDialog(component.Component):
|
||||||
return client.core.get_config_values(self.core_keys).addCallback(_on_config_values)
|
return client.core.get_config_values(self.core_keys).addCallback(_on_config_values)
|
||||||
|
|
||||||
def add_from_files(self, filenames):
|
def add_from_files(self, filenames):
|
||||||
import os.path
|
|
||||||
new_row = None
|
new_row = None
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
@ -229,9 +227,7 @@ class AddTorrentDialog(component.Component):
|
||||||
).run()
|
).run()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = "%s (%s)" % (info.name, os.path.split(filename)[-1])
|
new_row = self.torrent_liststore.append([info.info_hash, info.name, filename])
|
||||||
new_row = self.torrent_liststore.append(
|
|
||||||
[info.info_hash, info.name, filename])
|
|
||||||
self.files[info.info_hash] = info.files
|
self.files[info.info_hash] = info.files
|
||||||
self.infos[info.info_hash] = info.filedata
|
self.infos[info.info_hash] = info.filedata
|
||||||
self.listview_torrents.get_selection().select_iter(new_row)
|
self.listview_torrents.get_selection().select_iter(new_row)
|
||||||
|
@ -244,7 +240,6 @@ class AddTorrentDialog(component.Component):
|
||||||
self.listview_torrents.get_selection().select_iter(new_row)
|
self.listview_torrents.get_selection().select_iter(new_row)
|
||||||
|
|
||||||
def add_from_magnets(self, uris):
|
def add_from_magnets(self, uris):
|
||||||
import base64
|
|
||||||
new_row = None
|
new_row = None
|
||||||
|
|
||||||
for uri in uris:
|
for uri in uris:
|
||||||
|
@ -334,8 +329,8 @@ class AddTorrentDialog(component.Component):
|
||||||
ret = 0
|
ret = 0
|
||||||
for key, value in split_files.iteritems():
|
for key, value in split_files.iteritems():
|
||||||
if key.endswith(os.path.sep):
|
if key.endswith(os.path.sep):
|
||||||
chunk_iter = self.files_treestore.append(parent_iter,
|
chunk_iter = self.files_treestore.append(
|
||||||
[True, key, 0, -1, False, gtk.STOCK_DIRECTORY])
|
parent_iter, [True, key, 0, -1, False, gtk.STOCK_DIRECTORY])
|
||||||
chunk_size = self.add_files(chunk_iter, value)
|
chunk_size = self.add_files(chunk_iter, value)
|
||||||
self.files_treestore.set(chunk_iter, 2, chunk_size)
|
self.files_treestore.set(chunk_iter, 2, chunk_size)
|
||||||
ret += chunk_size
|
ret += chunk_size
|
||||||
|
@ -370,8 +365,10 @@ class AddTorrentDialog(component.Component):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def load_path_choosers_data(self):
|
def load_path_choosers_data(self):
|
||||||
self.move_completed_path_chooser.set_text(self.core_config["move_completed_path"], cursor_end=False, default_text=True)
|
self.move_completed_path_chooser.set_text(self.core_config["move_completed_path"],
|
||||||
self.download_location_path_chooser.set_text(self.core_config["download_location"], cursor_end=False, default_text=True)
|
cursor_end=False, default_text=True)
|
||||||
|
self.download_location_path_chooser.set_text(self.core_config["download_location"],
|
||||||
|
cursor_end=False, default_text=True)
|
||||||
self.builder.get_object("chk_move_completed").set_active(self.core_config["move_completed"])
|
self.builder.get_object("chk_move_completed").set_active(self.core_config["move_completed"])
|
||||||
|
|
||||||
def setup_move_completed_path_chooser(self):
|
def setup_move_completed_path_chooser(self):
|
||||||
|
@ -467,11 +464,9 @@ class AddTorrentDialog(component.Component):
|
||||||
def build_priorities(self, iter, priorities):
|
def build_priorities(self, iter, priorities):
|
||||||
while iter is not None:
|
while iter is not None:
|
||||||
if self.files_treestore.iter_has_child(iter):
|
if self.files_treestore.iter_has_child(iter):
|
||||||
self.build_priorities(self.files_treestore.iter_children(iter),
|
self.build_priorities(self.files_treestore.iter_children(iter), priorities)
|
||||||
priorities)
|
|
||||||
elif not self.files_treestore.get_value(iter, 1).endswith(os.path.sep):
|
elif not self.files_treestore.get_value(iter, 1).endswith(os.path.sep):
|
||||||
priorities[self.files_treestore.get_value(iter, 3)] = \
|
priorities[self.files_treestore.get_value(iter, 3)] = self.files_treestore.get_value(iter, 0)
|
||||||
self.files_treestore.get_value(iter, 0)
|
|
||||||
iter = self.files_treestore.iter_next(iter)
|
iter = self.files_treestore.iter_next(iter)
|
||||||
return priorities
|
return priorities
|
||||||
|
|
||||||
|
@ -531,13 +526,12 @@ class AddTorrentDialog(component.Component):
|
||||||
child = self.files_treestore.iter_next(child)
|
child = self.files_treestore.iter_next(child)
|
||||||
|
|
||||||
def update_treeview_toggles(self, iter):
|
def update_treeview_toggles(self, iter):
|
||||||
TOGGLE_INCONSISTENT = -1
|
toggle_inconsistent = -1
|
||||||
this_level_toggle = None
|
this_level_toggle = None
|
||||||
while iter is not None:
|
while iter is not None:
|
||||||
if self.files_treestore.iter_has_child(iter):
|
if self.files_treestore.iter_has_child(iter):
|
||||||
toggle = self.update_treeview_toggles(
|
toggle = self.update_treeview_toggles(self.files_treestore.iter_children(iter))
|
||||||
self.files_treestore.iter_children(iter))
|
if toggle == toggle_inconsistent:
|
||||||
if toggle == TOGGLE_INCONSISTENT:
|
|
||||||
self.files_treestore.set_value(iter, 4, True)
|
self.files_treestore.set_value(iter, 4, True)
|
||||||
else:
|
else:
|
||||||
self.files_treestore.set_value(iter, 0, toggle)
|
self.files_treestore.set_value(iter, 0, toggle)
|
||||||
|
@ -548,7 +542,7 @@ class AddTorrentDialog(component.Component):
|
||||||
if this_level_toggle is None:
|
if this_level_toggle is None:
|
||||||
this_level_toggle = toggle
|
this_level_toggle = toggle
|
||||||
elif this_level_toggle != toggle:
|
elif this_level_toggle != toggle:
|
||||||
this_level_toggle = TOGGLE_INCONSISTENT
|
this_level_toggle = toggle_inconsistent
|
||||||
iter = self.files_treestore.iter_next(iter)
|
iter = self.files_treestore.iter_next(iter)
|
||||||
return this_level_toggle
|
return this_level_toggle
|
||||||
|
|
||||||
|
@ -749,7 +743,7 @@ class AddTorrentDialog(component.Component):
|
||||||
self.save_torrent_options(row)
|
self.save_torrent_options(row)
|
||||||
|
|
||||||
row = self.torrent_liststore.get_iter_first()
|
row = self.torrent_liststore.get_iter_first()
|
||||||
while row != None:
|
while row is not None:
|
||||||
torrent_id = self.torrent_liststore.get_value(row, 0)
|
torrent_id = self.torrent_liststore.get_value(row, 0)
|
||||||
filename = self.torrent_liststore.get_value(row, 2)
|
filename = self.torrent_liststore.get_value(row, 2)
|
||||||
try:
|
try:
|
||||||
|
@ -758,7 +752,7 @@ class AddTorrentDialog(component.Component):
|
||||||
options = None
|
options = None
|
||||||
|
|
||||||
file_priorities = self.get_file_priorities(torrent_id)
|
file_priorities = self.get_file_priorities(torrent_id)
|
||||||
if options != None:
|
if options is not None:
|
||||||
options["file_priorities"] = file_priorities
|
options["file_priorities"] = file_priorities
|
||||||
|
|
||||||
if deluge.common.is_magnet(filename):
|
if deluge.common.is_magnet(filename):
|
||||||
|
@ -787,7 +781,7 @@ class AddTorrentDialog(component.Component):
|
||||||
|
|
||||||
# Set all the torrent options
|
# Set all the torrent options
|
||||||
row = model.get_iter_first()
|
row = model.get_iter_first()
|
||||||
while row != None:
|
while row is not None:
|
||||||
torrent_id = model.get_value(row, 0)
|
torrent_id = model.get_value(row, 0)
|
||||||
self.options[torrent_id].update(options)
|
self.options[torrent_id].update(options)
|
||||||
row = model.iter_next(row)
|
row = model.iter_next(row)
|
||||||
|
@ -851,8 +845,7 @@ class AddTorrentDialog(component.Component):
|
||||||
# and then move the file iter to top
|
# and then move the file iter to top
|
||||||
split_text = new_text.split(os.path.sep)
|
split_text = new_text.split(os.path.sep)
|
||||||
for s in split_text[:-1]:
|
for s in split_text[:-1]:
|
||||||
parent = self.files_treestore.append(parent,
|
parent = self.files_treestore.append(parent, [True, s, 0, -1, False, gtk.STOCK_DIRECTORY])
|
||||||
[True, s, 0, -1, False, gtk.STOCK_DIRECTORY])
|
|
||||||
|
|
||||||
self.files_treestore[itr][1] = split_text[-1]
|
self.files_treestore[itr][1] = split_text[-1]
|
||||||
common.reparent_iter(self.files_treestore, itr, parent)
|
common.reparent_iter(self.files_treestore, itr, parent)
|
||||||
|
|
Loading…
Reference in New Issue