Add compatibility for lt-rb 1.0 and py3k

Beware, may remove your torrents from the app.

lt-rb >= 1.0 is now a requirement
This commit is contained in:
Kai Huuhko 2015-05-17 02:34:25 +03:00
parent 8a45182cc4
commit cb3c4b7f66
9 changed files with 56 additions and 73 deletions

12
README
View File

@ -2,20 +2,20 @@
REQUIREMENTS
============
* libtorrent-rasterbar 0.16.0 or later, currently tested and developed with
version 0.16.16
* libtorrent-rasterbar 1.0 or later, currently tested and developed with
version 1.0.5
http://www.libtorrent.org/
* Enlightenment Foundation Libraries 1.8 or later
http://enlightenment.org/p.php?p=download&l=en
https://www.enlightenment.org/download
* Python Bindings for EFL 1.8 or later
* Python-EFL 1.8 or later
http://enlightenment.org/p.php?p=download&l=en
https://www.enlightenment.org/download
* Python 2.x or later
* Python 2.6 or later, 3.2 or later
http://www.python.org/

View File

@ -57,10 +57,10 @@ else:
sys.exit()
import os
try:
from ConfigParser import SafeConfigParser
except ImportError:
if sys.hexversion >= 0x030000F0:
from configparser import ConfigParser as SafeConfigParser
else:
from ConfigParser import SafeConfigParser
import logging
@ -160,8 +160,12 @@ class Epour(object):
def save_conf(self):
conf_path = os.path.join(save_config_path("epour"), "epour.conf")
with open(conf_path, 'wb') as configfile:
self.conf.write(configfile)
if sys.hexversion >= 0x030000F0:
with open(conf_path, 'w') as configfile:
self.conf.write(configfile)
else:
with open(conf_path, 'wb') as configfile:
self.conf.write(configfile)
def quit(self):
session = self.session

View File

@ -1 +1 @@
__version__ = "0.6.0"
__version__ = "0.6.9"

View File

@ -19,6 +19,9 @@
# MA 02110-1301, USA.
#
if "long" not in dir(__builtins__):
long = int
import cgi
import sys
import os
@ -656,7 +659,7 @@ class TorrentStatus(Table):
pass
elif isinstance(v, lt.storage_mode_t):
v = str(v).replace("_", " ").capitalize()
elif isinstance(v, (int, long, basestring)):
elif isinstance(v, (int, long, bytes, str)):
if k in self.byte_values:
v = intrepr(v)
if k in self.byte_transfer_values:

View File

@ -241,13 +241,12 @@ always used.'''
single_line=True, scrollable=True
)
uri_entry.part_text_set("guide", _("Enter torrent file path / magnet URI / info hash"))
if t_uri:
uri_entry.entry = utf8_to_markup(t_uri)
hbox.pack_end(uri_entry)
uri_entry.show()
if t_uri:
uri_entry.entry = t_uri
uri_entry.entry = utf8_to_markup(t_uri)
hbox.pack_end(uri_entry)
uri_entry.show()
fsb = Button(box, text=_("Select file"))
fsb.callback_clicked_add(lambda x: TorrentFs(self, uri_entry))

View File

@ -16,6 +16,9 @@ EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL
FILL_HORIZ = EVAS_HINT_FILL, 0.5
if "xrange" not in dir(__builtins__):
xrange = range
def chunker(seq, size):
return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))

View File

@ -23,7 +23,10 @@ import cgi
import logging
from datetime import timedelta, datetime
import gettext
gettext.install("epour", unicode=True)
try:
gettext.install("epour", unicode=True)
except Exception:
gettext.install("epour")
import libtorrent as lt
@ -454,8 +457,8 @@ class TorrentClass(GenlistItemClass):
if qp == -1:
qp = "seeding"
return _("{:.0%} complete, ETA: {} "
"(Down: {}/s Up: {}/s Queue pos: {})").format(
return _("{0:.0%} complete, ETA: {1} "
"(Down: {2}/s Up: {3}/s Queue pos: {4})").format(
s.progress,
timedelta(seconds=self.get_eta(s)),
intrepr(s.download_payload_rate, precision=0),
@ -521,10 +524,7 @@ class TorrentClass(GenlistItemClass):
if left <= 0 or s.download_payload_rate == 0:
return 0
try:
eta = left / s.download_payload_rate
except ZeroDivisionError:
eta = 0
eta = int(round(left / s.download_payload_rate))
return eta

View File

@ -115,9 +115,7 @@ class Session(lt.session):
ihash = str(h.info_hash())
self.log.debug("Metadata received.")
t_info = h.get_torrent_info()
t = {}
t["info"] = lt.bdecode(t_info.metadata())
self.torrents[ihash]["ti"] = lt.bencode(t)
self.torrents[ihash]["ti"] = t_info
def load_state(self):
for p in load_data_paths("epour"):
@ -167,12 +165,8 @@ class Session(lt.session):
self.log.warning("Could not open the list of torrents.")
else:
try:
if sys.hexversion >= 0x030000F0:
torrents = cPickle.load(
pkl_file, fix_imports=True, encoding="utf-8")
else:
torrents = cPickle.load(pkl_file)
except EOFError:
torrents = cPickle.load(pkl_file)
except Exception:
self.log.exception("Opening the list of torrents failed.")
else:
self.log.debug(
@ -181,28 +175,17 @@ class Session(lt.session):
)
for i, t in torrents.items():
try:
if isinstance(t, dict):
for k, v in t.items():
if v is None:
continue
elif k == "ti":
for k, v in t.items():
if v is None:
continue
elif k == "ti":
# Epour <= 0.6 compat
if isinstance(v, dict):
t[k] = lt.torrent_info(lt.bdecode(v))
# with open(v, "rb") as f:
# torrents[i][k] = \
# lt.torrent_info(lt.bdecode(f.read()))
elif k == "info_hash":
torrents[i][k] = lt.big_number(v)
else:
# Upgrade from older versions where t is file path
p = t
t = {}
with open(p, "rb") as f:
t["ti"] = \
lt.torrent_info(lt.bdecode(f.read()))
# rp = os.path.join(data_dir, i + ".fastresume")
# if os.path.exists(rp):
# with open(rp, "rb") as f:
# t["resume_data"] = f.read()
else:
t[k] = lt.bdecode(v)
# elif k == "info_hash":
# torrents[i][k] = lt.big_number(v)
except Exception:
self.log.exception("Opening torrent %s failed", i)
continue
@ -216,13 +199,11 @@ class Session(lt.session):
for i, t in self.torrents.items():
for k, v in t.items():
# if k == "ti":
# self.torrents[i][k] = torrent_path_get(i)
if k == "info_hash":
if v.is_all_zeros():
del self.torrents[i][k]
else:
self.torrents[i][k] = v.to_string()
self.torrents[i][k] = v.to_bytes()
handles = self.get_torrents()
for h in handles:
@ -235,15 +216,13 @@ class Session(lt.session):
resume_data = lt.bencode(h.write_resume_data())
t_dict["resume_data"] = resume_data
t_info = h.get_torrent_info()
t = {}
t["info"] = lt.bdecode(t_info.metadata())
t_dict["ti"] = lt.bencode(t)
t_dict["ti"] = lt.bencode(t_info)
else:
self.log.debug("Handle is invalid, skipping")
path = os.path.join(save_data_path("epour"), "torrents")
with open(path, 'wb') as f:
cPickle.dump(self.torrents, f, protocol=2)
cPickle.dump(self.torrents, f, protocol=cPickle.HIGHEST_PROTOCOL)
self.log.debug("List of torrents saved.")
@ -273,8 +252,6 @@ class Session(lt.session):
def remove_torrent(self, h, with_data=False):
ihash = str(h.info_hash())
#t_dict = self.torrents[ihash]
del self.torrents[ihash]
lt.session.remove_torrent(self, h, option=with_data)
@ -367,15 +344,15 @@ class Session(lt.session):
def add_torrent_from_magnet(self, add_dict, t_uri):
self.log.debug("Adding %r", t_uri)
tmp_dict = lt.parse_magnet_uri(bytes(t_uri))
t_uri = t_uri.encode("ascii")
tmp_dict = lt.parse_magnet_uri(t_uri)
tmp_dict.update(add_dict)
tmp_dict["info_hash"] = tmp_dict["info_hash"].to_bytes()
self.async_add_torrent(tmp_dict)
def add_torrent_from_hash(self, add_dict, t_uri):
if "sha1_hash" in dir(lt):
add_dict["info_hash"] = lt.sha1_hash(bytes(t_uri))
else:
add_dict["info_hash"] = lt.big_number(bytes(t_uri))
t_uri = t_uri.encode("ascii")
add_dict["info_hash"] = t_uri
self.log.debug("Adding %s", t_uri)
self.async_add_torrent(add_dict)

View File

@ -24,14 +24,11 @@ auto.setup(
license='GNU GPL',
platforms='linux',
requires=[
'libtorrent',
'libtorrent (>=1.0)',
'efl',
'xdg',
'dbus',
],
provides=[
'epour',
],
cmdclass={
'sdist': sdist_auto
}