mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-17 13:56:47 +00:00
Have the TorrentInfo object raise an exception if unable to open/bdecode
the torrent file Catch the exception in AddTorrentDialog
This commit is contained in:
parent
35671b3f8e
commit
d25ad68521
@ -44,16 +44,17 @@ class TorrentInfo(object):
|
|||||||
self.__m_metadata = bencode.bdecode(open(filename, "rb").read())
|
self.__m_metadata = bencode.bdecode(open(filename, "rb").read())
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to open %s: %s", filename, e)
|
log.warning("Unable to open %s: %s", filename, e)
|
||||||
|
raise e
|
||||||
|
|
||||||
self.__m_info_hash = sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
|
self.__m_info_hash = sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
|
||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
self.__m_files = []
|
self.__m_files = []
|
||||||
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:
|
||||||
prefix = self.__m_metadata["info"]["name"]
|
prefix = self.__m_metadata["info"]["name"]
|
||||||
|
|
||||||
for f in self.__m_metadata["info"]["files"]:
|
for f in self.__m_metadata["info"]["files"]:
|
||||||
self.__m_files.append({
|
self.__m_files.append({
|
||||||
'path': os.path.join(prefix, *f["path"]),
|
'path': os.path.join(prefix, *f["path"]),
|
||||||
@ -82,28 +83,28 @@ class TorrentInfo(object):
|
|||||||
@property
|
@property
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
return self.__m_metadata
|
return self.__m_metadata
|
||||||
|
|
||||||
def get_torrent_info(filename):
|
def get_torrent_info(filename):
|
||||||
"""
|
"""
|
||||||
Return the metadata of a torrent file
|
Return the metadata of a torrent file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 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)
|
||||||
metadata = bencode.bdecode(open(filename, "rb").read())
|
metadata = bencode.bdecode(open(filename, "rb").read())
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to open %s: %s", filename, e)
|
log.warning("Unable to open %s: %s", filename, e)
|
||||||
|
|
||||||
info_hash = sha(bencode.bencode(metadata["info"])).hexdigest()
|
info_hash = sha(bencode.bencode(metadata["info"])).hexdigest()
|
||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
files = []
|
files = []
|
||||||
if metadata["info"].has_key("files"):
|
if metadata["info"].has_key("files"):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if len(metadata["info"]["files"]) > 1:
|
if len(metadata["info"]["files"]) > 1:
|
||||||
prefix = metadata["info"]["name"]
|
prefix = metadata["info"]["name"]
|
||||||
|
|
||||||
for f in metadata["info"]["files"]:
|
for f in metadata["info"]["files"]:
|
||||||
files.append({
|
files.append({
|
||||||
'path': os.path.join(prefix, *f["path"]),
|
'path': os.path.join(prefix, *f["path"]),
|
||||||
@ -116,7 +117,7 @@ def get_torrent_info(filename):
|
|||||||
"size": metadata["info"]["length"],
|
"size": metadata["info"]["length"],
|
||||||
"download": True
|
"download": True
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"filename": filename,
|
"filename": filename,
|
||||||
"name": metadata["info"]["name"],
|
"name": metadata["info"]["name"],
|
||||||
|
@ -185,7 +185,11 @@ class AddTorrentDialog(component.Component):
|
|||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
# Get the torrent data from the torrent file
|
# Get the torrent data from the torrent file
|
||||||
info = deluge.ui.common.TorrentInfo(filename)
|
try:
|
||||||
|
info = deluge.ui.common.TorrentInfo(filename)
|
||||||
|
except Exception, e:
|
||||||
|
log.debug("Unable to open torrent file: %s", e)
|
||||||
|
continue
|
||||||
|
|
||||||
name = "%s (%s)" % (info.name, os.path.split(filename)[-1])
|
name = "%s (%s)" % (info.name, os.path.split(filename)[-1])
|
||||||
new_row = self.torrent_liststore.append(
|
new_row = self.torrent_liststore.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user