kuuko pushed a commit to branch master. http://git.enlightenment.org/apps/epour.git/commit/?id=cb3c4b7f6618bc6f9230945c78eceaad54a7c588
commit cb3c4b7f6618bc6f9230945c78eceaad54a7c588 Author: Kai Huuhko <kai.huu...@gmail.com> Date: Sun May 17 02:34:25 2015 +0300 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 --- README | 12 ++++---- epour/Epour.py | 14 ++++++---- epour/__init__.py | 2 +- epour/gui/TorrentProps.py | 5 +++- epour/gui/TorrentSelector.py | 5 ++-- epour/gui/Widgets.py | 3 ++ epour/gui/__init__.py | 14 +++++----- epour/session.py | 65 ++++++++++++++------------------------------ setup.py | 5 +--- 9 files changed, 54 insertions(+), 71 deletions(-) diff --git a/README b/README index 45e5a68..007012d 100644 --- a/README +++ b/README @@ -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/ diff --git a/epour/Epour.py b/epour/Epour.py index c87f310..17cb8a4 100644 --- a/epour/Epour.py +++ b/epour/Epour.py @@ -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 diff --git a/epour/__init__.py b/epour/__init__.py index 906d362..5c2c6c5 100644 --- a/epour/__init__.py +++ b/epour/__init__.py @@ -1 +1 @@ -__version__ = "0.6.0" +__version__ = "0.6.9" diff --git a/epour/gui/TorrentProps.py b/epour/gui/TorrentProps.py index 116a231..ea10883 100644 --- a/epour/gui/TorrentProps.py +++ b/epour/gui/TorrentProps.py @@ -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: diff --git a/epour/gui/TorrentSelector.py b/epour/gui/TorrentSelector.py index 18b7cee..01142d7 100644 --- a/epour/gui/TorrentSelector.py +++ b/epour/gui/TorrentSelector.py @@ -241,14 +241,13 @@ 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 - fsb = Button(box, text=_("Select file")) fsb.callback_clicked_add(lambda x: TorrentFs(self, uri_entry)) hbox.pack_end(fsb) diff --git a/epour/gui/Widgets.py b/epour/gui/Widgets.py index 6e6a178..7aa0f06 100644 --- a/epour/gui/Widgets.py +++ b/epour/gui/Widgets.py @@ -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)) diff --git a/epour/gui/__init__.py b/epour/gui/__init__.py index c01309d..e16c77c 100644 --- a/epour/gui/__init__.py +++ b/epour/gui/__init__.py @@ -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 diff --git a/epour/session.py b/epour/session.py index 52471c7..e13d945 100644 --- a/epour/session.py +++ b/epour/session.py @@ -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) diff --git a/setup.py b/setup.py index e60eebb..83f61cb 100755 --- a/setup.py +++ b/setup.py @@ -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 } --