mirror of
https://github.com/codex-storage/deluge.git
synced 2025-03-03 12:30:45 +00:00
use FileTree2 in the TorrentInfo class when specified
adjust the filetree walking functions to match the server side code
This commit is contained in:
parent
14d9f6b7ba
commit
7053163f88
@ -80,7 +80,7 @@ class TorrentInfo(object):
|
|||||||
:type filename: string
|
:type filename: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, filetree=1):
|
||||||
# Get the torrent data from the torrent file
|
# Get the torrent data from the torrent file
|
||||||
try:
|
try:
|
||||||
log.debug("Attempting to open %s.", filename)
|
log.debug("Attempting to open %s.", filename)
|
||||||
@ -108,6 +108,7 @@ class TorrentInfo(object):
|
|||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
paths = {}
|
paths = {}
|
||||||
|
dirs = {}
|
||||||
if self.__m_metadata["info"].has_key("files"):
|
if self.__m_metadata["info"].has_key("files"):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if len(self.__m_metadata["info"]["files"]) > 1:
|
if len(self.__m_metadata["info"]["files"]) > 1:
|
||||||
@ -121,14 +122,34 @@ class TorrentInfo(object):
|
|||||||
f["index"] = index
|
f["index"] = index
|
||||||
paths[path] = f
|
paths[path] = f
|
||||||
|
|
||||||
|
dirname = os.path.dirname(path)
|
||||||
|
while dirname:
|
||||||
|
dirinfo = dirs.setdefault(dirname, {})
|
||||||
|
dirinfo["length"] = dirinfo.get("length", 0) + f["length"]
|
||||||
|
dirname = os.path.dirname(dirname)
|
||||||
|
|
||||||
|
if filetree == 2:
|
||||||
|
def walk(path, item):
|
||||||
|
if item["type"] == "dir":
|
||||||
|
item.update(dirs[path])
|
||||||
|
else:
|
||||||
|
item.update(paths[path])
|
||||||
|
item["download"] = True
|
||||||
|
|
||||||
|
file_tree = FileTree2(paths.keys())
|
||||||
|
file_tree.walk(walk)
|
||||||
|
else:
|
||||||
def walk(path, item):
|
def walk(path, item):
|
||||||
if type(item) is dict:
|
if type(item) is dict:
|
||||||
return item
|
return item
|
||||||
return [paths[path]['index'], paths[path]['length'], True]
|
return [paths[path]["index"], paths[path]["length"], True]
|
||||||
|
|
||||||
file_tree = FileTree(paths)
|
file_tree = FileTree(paths)
|
||||||
file_tree.walk(walk)
|
file_tree.walk(walk)
|
||||||
self.__m_files_tree = file_tree.get_tree()
|
self.__m_files_tree = file_tree.get_tree()
|
||||||
|
else:
|
||||||
|
if filetree == 2:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
self.__m_files_tree = {
|
self.__m_files_tree = {
|
||||||
self.__m_name: (0, self.__m_metadata["info"]["length"], True)
|
self.__m_name: (0, self.__m_metadata["info"]["length"], True)
|
||||||
|
@ -65,10 +65,6 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
}]
|
}]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
new Ext.tree.TreeSorter(this.files, {
|
|
||||||
folderSort: true
|
|
||||||
});
|
|
||||||
|
|
||||||
this.optionsManager = new Deluge.MultiOptionsManager();
|
this.optionsManager = new Deluge.MultiOptionsManager();
|
||||||
|
|
||||||
this.form = this.add({
|
this.form = this.add({
|
||||||
@ -200,7 +196,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
var fileIndexes = {};
|
var fileIndexes = {};
|
||||||
this.walkFileTree(torrent['files_tree'], function(filename, type, entry, parent) {
|
this.walkFileTree(torrent['files_tree'], function(filename, type, entry, parent) {
|
||||||
if (type != 'file') return;
|
if (type != 'file') return;
|
||||||
fileIndexes[entry[0]] = entry[2];
|
fileIndexes[entry.index] = entry.download;
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
var priorities = [];
|
var priorities = [];
|
||||||
@ -279,9 +275,9 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
|
|
||||||
this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parentNode) {
|
this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parentNode) {
|
||||||
if (type == 'dir') {
|
if (type == 'dir') {
|
||||||
alert(Ext.encode(entry));
|
|
||||||
var folder = new Ext.tree.TreeNode({
|
var folder = new Ext.tree.TreeNode({
|
||||||
filename: filename,
|
filename: filename,
|
||||||
|
size: entry.length,
|
||||||
checked: true
|
checked: true
|
||||||
});
|
});
|
||||||
folder.on('checkchange', this.onFolderCheck, this);
|
folder.on('checkchange', this.onFolderCheck, this);
|
||||||
@ -290,12 +286,10 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
} else {
|
} else {
|
||||||
var node = new Ext.tree.TreeNode({
|
var node = new Ext.tree.TreeNode({
|
||||||
filename: filename,
|
filename: filename,
|
||||||
fileindex: entry[0],
|
fileindex: entry.index,
|
||||||
text: filename, // this needs to be here for sorting reasons
|
size: entry.length,
|
||||||
size: entry[1],
|
|
||||||
leaf: true,
|
leaf: true,
|
||||||
checked: priorities[entry[0]],
|
checked: priorities[entry.index],
|
||||||
iconCls: 'x-deluge-file',
|
|
||||||
uiProvider: Ext.tree.ColumnNodeUI
|
uiProvider: Ext.tree.ColumnNodeUI
|
||||||
});
|
});
|
||||||
node.on('checkchange', this.onNodeCheck, this);
|
node.on('checkchange', this.onNodeCheck, this);
|
||||||
@ -306,9 +300,9 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
walkFileTree: function(files, callback, scope, parentNode) {
|
walkFileTree: function(files, callback, scope, parentNode) {
|
||||||
for (var filename in files) {
|
for (var filename in files.contents) {
|
||||||
var entry = files[filename];
|
var entry = files.contents[filename];
|
||||||
var type = (Ext.type(entry) == 'object') ? 'dir' : 'file';
|
var type = entry.type;
|
||||||
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
var ret = callback.apply(scope, [filename, type, entry, parentNode]);
|
var ret = callback.apply(scope, [filename, type, entry, parentNode]);
|
||||||
|
@ -652,9 +652,10 @@ class WebApi(JSONComponent):
|
|||||||
:rtype: dictionary
|
:rtype: dictionary
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
torrent_info = uicommon.TorrentInfo(filename.strip())
|
torrent_info = uicommon.TorrentInfo(filename.strip(), 2)
|
||||||
return torrent_info.as_dict("name", "info_hash", "files_tree")
|
return torrent_info.as_dict("name", "info_hash", "files_tree")
|
||||||
except:
|
except Exception, e:
|
||||||
|
log.exception(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@export
|
@export
|
||||||
|
Loading…
x
Reference in New Issue
Block a user