[Console] Refactor build_file_list()
* Remove usage of sys.maxint and rename variable to make method more readable.
This commit is contained in:
parent
f1e70829af
commit
05ab06e3a5
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from sys import maxint
|
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.common import FILE_PRIORITY, fdate, fsize, ftime
|
from deluge.common import FILE_PRIORITY, fdate, fsize, ftime
|
||||||
|
@ -81,7 +80,6 @@ class TorrentDetail(BaseMode, component.Component):
|
||||||
self.file_list = None
|
self.file_list = None
|
||||||
self.current_file = None
|
self.current_file = None
|
||||||
self.current_file_idx = 0
|
self.current_file_idx = 0
|
||||||
self.file_limit = maxint
|
|
||||||
self.file_off = 0
|
self.file_off = 0
|
||||||
self.more_to_draw = False
|
self.more_to_draw = False
|
||||||
self.full_names = None
|
self.full_names = None
|
||||||
|
@ -146,43 +144,45 @@ class TorrentDetail(BaseMode, component.Component):
|
||||||
self.torrent_state = state
|
self.torrent_state = state
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
# split file list into directory tree. this function assumes all files in a
|
def build_file_list(self, torrent_files, progress, priority):
|
||||||
# particular directory are returned together. it won't work otherwise.
|
""" Split file list from torrent state into a directory tree.
|
||||||
# returned list is a list of lists of the form:
|
|
||||||
# [file/dir_name,index,size,children,expanded,progress,priority]
|
Returns:
|
||||||
# for directories index values count down from maxint (for marking usage),
|
|
||||||
# for files the index is the value returned in the
|
Tuple:
|
||||||
# state object for use with other libtorrent calls (i.e. setting prio)
|
A list of lists in the form:
|
||||||
#
|
[file/dir_name, index, size, children, expanded, progress, priority]
|
||||||
# Also returns a dictionary that maps index values to the file leaves
|
|
||||||
# for fast updating of progress and priorities
|
Dictionary:
|
||||||
def build_file_list(self, file_tuples, prog, prio):
|
Map of file index for fast updating of progress and priorities.
|
||||||
ret = []
|
"""
|
||||||
retdict = {}
|
|
||||||
diridx = maxint
|
file_list = []
|
||||||
for f in file_tuples:
|
file_dict = {}
|
||||||
cur = ret
|
# directory index starts from total file count.
|
||||||
ps = f["path"].split("/")
|
dir_idx = len(torrent_files)
|
||||||
fin = ps[-1]
|
for torrent_file in torrent_files:
|
||||||
for p in ps:
|
cur = file_list
|
||||||
if not cur or p != cur[-1][0]:
|
paths = torrent_file["path"].split("/")
|
||||||
cl = []
|
for path in paths:
|
||||||
if p == fin:
|
if not cur or path != cur[-1][0]:
|
||||||
ent = [p, f["index"], f["size"], cl, False,
|
child_list = []
|
||||||
format_utils.format_progress(prog[f["index"]] * 100),
|
if path == paths[-1]:
|
||||||
prio[f["index"]]]
|
file_progress = format_utils.format_progress(progress[torrent_file["index"]] * 100)
|
||||||
retdict[f["index"]] = ent
|
entry = [path, torrent_file["index"], torrent_file["size"], child_list,
|
||||||
|
False, file_progress, priority[torrent_file["index"]]]
|
||||||
|
file_dict[torrent_file["index"]] = entry
|
||||||
else:
|
else:
|
||||||
ent = [p, diridx, -1, cl, False, 0, -1]
|
entry = [path, dir_idx, -1, child_list, False, 0, -1]
|
||||||
retdict[diridx] = ent
|
file_dict[dir_idx] = entry
|
||||||
diridx -= 1
|
dir_idx += 1
|
||||||
cur.append(ent)
|
cur.append(entry)
|
||||||
cur = cl
|
cur = child_list
|
||||||
else:
|
else:
|
||||||
cur = cur[-1][3]
|
cur = cur[-1][3]
|
||||||
self.__build_sizes(ret)
|
self.__build_sizes(file_list)
|
||||||
self.__fill_progress(ret, prog)
|
self.__fill_progress(file_list, progress)
|
||||||
return (ret, retdict)
|
return file_list, file_dict
|
||||||
|
|
||||||
# fill in the sizes of the directory entries based on their children
|
# fill in the sizes of the directory entries based on their children
|
||||||
def __build_sizes(self, fs):
|
def __build_sizes(self, fs):
|
||||||
|
@ -289,8 +289,6 @@ class TorrentDetail(BaseMode, component.Component):
|
||||||
self.more_to_draw = True
|
self.more_to_draw = True
|
||||||
return -1, -1
|
return -1, -1
|
||||||
|
|
||||||
self.file_limit = idx
|
|
||||||
|
|
||||||
# default color values
|
# default color values
|
||||||
fg = "white"
|
fg = "white"
|
||||||
bg = "black"
|
bg = "black"
|
||||||
|
|
Loading…
Reference in New Issue