From c40f6d2e768d0d6fc4b827dfd4eaf4ee13b3b32b Mon Sep 17 00:00:00 2001 From: Kai Huuhko Date: Thu, 10 Jul 2014 23:12:24 +0300 Subject: [PATCH] Switch to using pyxdg, update README --- README | 18 +++++++--- TODO | 13 +++++++ epour/Epour.py | 15 ++++---- epour/Globals.py | 5 --- epour/session.py | 94 ++++++++++++++++++++++++++++-------------------- setup.py | 6 ++-- 6 files changed, 94 insertions(+), 57 deletions(-) diff --git a/README b/README index 34d2049..45e5a68 100644 --- a/README +++ b/README @@ -2,9 +2,10 @@ REQUIREMENTS ============ -* libtorrent-rasterbar 0.16.0 or later, tested and developed with 0.16.16 +* libtorrent-rasterbar 0.16.0 or later, currently tested and developed with + version 0.16.16 - http://www.rasterbar.com/products/libtorrent/ + http://www.libtorrent.org/ * Enlightenment Foundation Libraries 1.8 or later @@ -24,6 +25,12 @@ REQUIREMENTS * dbus-python + http://www.freedesktop.org/wiki/Software/DBusBindings/#dbus-python + +* python-xdg / pyxdg + + http://www.freedesktop.org/wiki/Software/pyxdg/ + ======= INSTALL ======= @@ -34,6 +41,7 @@ sudo ./setup.py install CONTACT/BUGS ============ -Launchpad: https://launchpad.net/epour -Email: kai.huuhko@gmail.com -Forums: http://forums.bodhilinux.com/index.php?/topic/7722-epour/ +Email: kai.huuhko@gmail.com +Mailing list: enlightenment-users@lists.sourceforge.net +Forums: http://forums.bodhilinux.com/index.php?/topic/7722-epour/ +Launchpad: https://launchpad.net/epour diff --git a/TODO b/TODO index e97998d..e30a0f3 100644 --- a/TODO +++ b/TODO @@ -70,6 +70,19 @@ Misc: ☐ Save resume data periodically http://libtorrent.org/reference-Core.html#save_resume_data() http://libtorrent.org/reference-Core.html#need_save_resume_data() +Error handling: + ☐ Torrent errors + http://libtorrent.org/reference-Alerts.html#torrent_error_alert + ☐ Tracker errors + http://libtorrent.org/reference-Alerts.html#tracker_error_alert + ☐ Display authentication dialog when tracker requires it + ☐ Performance notifications + http://libtorrent.org/reference-Alerts.html#performance_alert + ☐ File errors + http://libtorrent.org/reference-Alerts.html#file_error_alert + ☐ Listen failed/succeeded + http://libtorrent.org/reference-Alerts.html#listen_failed_alert + http://libtorrent.org/reference-Alerts.html#listen_succeeded_alert I18N: This should wait until most of the features are in and the strings are stable. ☐ Make strings localizable diff --git a/epour/Epour.py b/epour/Epour.py index 42013e7..a56a9d2 100644 --- a/epour/Epour.py +++ b/epour/Epour.py @@ -59,12 +59,10 @@ else: import os from ConfigParser import SafeConfigParser -from Globals import conf_dir, conf_path, data_dir import logging -for d in conf_dir, data_dir: - if not os.path.exists(d): - os.mkdir(d, 0700) +from xdg.BaseDirectory import save_data_path, save_config_path, \ + load_config_paths from session import Session from gui import MainInterface @@ -120,7 +118,9 @@ class Epour(object): ch.setLevel(log_level) log.addHandler(ch) - fh = logging.FileHandler(os.path.join(data_dir, "epour.log")) + fh = logging.FileHandler( + os.path.join(save_data_path("epour"), "epour.log") + ) fh_formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) @@ -146,7 +146,9 @@ class Epour(object): "listen_high": str(0), }) - conf.read(conf_path) + for p in load_config_paths("epour"): + if conf.read(os.path.join(p, "epour.conf")): + break if not conf.has_section("Settings"): conf.add_section("Settings") @@ -154,6 +156,7 @@ class Epour(object): return conf 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) diff --git a/epour/Globals.py b/epour/Globals.py index b60a621..aaf05b3 100644 --- a/epour/Globals.py +++ b/epour/Globals.py @@ -1,6 +1 @@ -import os - version = "0.6.0" -conf_dir = os.path.expanduser(os.path.join("~", ".config", "epour")) -conf_path = os.path.join(conf_dir, "epour.conf") -data_dir = os.path.expanduser(os.path.join("~", ".local", "share", "epour")) diff --git a/epour/session.py b/epour/session.py index ca822d6..265b0b4 100644 --- a/epour/session.py +++ b/epour/session.py @@ -32,11 +32,14 @@ import libtorrent as lt from efl.ecore import Timer -from Globals import data_dir +from xdg.BaseDirectory import save_data_path, load_data_paths def torrent_path_get(ihash): - return os.path.join(data_dir, "{}.torrent".format(ihash)) + for p in load_data_paths("epour"): + path = os.path.join(p, "{0}.torrent".format(ihash)) + if os.path.isfile(path): + return path class Session(lt.session): @@ -118,15 +121,19 @@ class Session(lt.session): self.torrents[ihash]["ti"] = lt.bencode(t) def load_state(self): - try: - with open(os.path.join(data_dir, "session"), 'rb') as f: - state = lt.bdecode(f.read()) - lt.session.load_state(self, state) - except Exception as e: - self.log.debug("Could not load previous session state.") - self.log.debug(e) - else: - self.log.info("Session restored from disk.") + for p in load_data_paths("epour"): + path = os.path.join(p, "session") + if os.path.isfile(path): + try: + with open(path, 'rb') as f: + state = lt.bdecode(f.read()) + lt.session.load_state(self, state) + except Exception as e: + self.log.debug("Could not load previous session state.") + self.log.debug(e) + else: + self.log.info("Session restored from disk.") + break settings = self.settings() from Globals import version @@ -139,15 +146,20 @@ class Session(lt.session): def save_state(self): state = lt.session.save_state(self) - with open(os.path.join(data_dir, "session"), 'wb') as f: + path = os.path.join(save_data_path("epour"), "session") + with open(path, 'wb') as f: f.write(lt.bencode(state)) self.log.debug("Session state saved.") def load_torrents(self): - torrents_path = os.path.join(data_dir, "torrents") - if not os.path.exists(torrents_path): - self.log.debug("No list of torrents found.") + for p in load_data_paths("epour"): + torrents_path = os.path.join(p, "torrents") + if os.path.isfile(torrents_path): + break + + if not torrents_path: + self.info.debug("No previous list of torrents found.") return try: @@ -219,7 +231,8 @@ class Session(lt.session): resume_data = lt.bencode(h.write_resume_data()) t_dict["resume_data"] = resume_data - with open(os.path.join(data_dir, "torrents"), 'wb') as f: + path = os.path.join(save_data_path("epour"), "torrents") + with open(path, 'wb') as f: cPickle.dump(self.torrents, f, protocol=2) self.log.debug("List of torrents saved.") @@ -258,21 +271,23 @@ class Session(lt.session): def remove_torrent(self, h, with_data=False): ihash = str(h.info_hash()) - fr_path = os.path.join( - data_dir, "{}.fastresume".format(ihash) - ) #t_dict = self.torrents[ihash] del self.torrents[ihash] lt.session.remove_torrent(self, h, option=with_data) - try: - with open(fr_path): - pass - except IOError: - self.log.debug("Could not remove fast resume data.") - else: - os.remove(fr_path) + for p in load_data_paths("epour"): + fr_path = os.path.join( + p, "{0}.fastresume".format(ihash) + ) + + try: + with open(fr_path): + pass + except IOError: + self.log.debug("Could not remove %s", fr_path) + else: + os.remove(fr_path) try: with open(torrent_path_get(ihash)): @@ -310,22 +325,23 @@ class Session(lt.session): add_dict["ti"] = info rd = None - try: - with open(os.path.join( - data_dir, "{}.fastresume".format(info.info_hash()) - ), "rb" - ) as f: - rd = f.read() - except Exception: - self.log.debug("Invalid resume data") - else: - add_dict["resume_data"] = rd + fr_file_name = "{}.fastresume".format(info.info_hash()) + for p in load_data_paths("epour"): + path = os.path.join(p, fr_file_name) + if os.path.isfile(path): + try: + with open(path, "rb") as f: + rd = f.read() + except Exception: + self.log.debug("Invalid resume data") + else: + add_dict["resume_data"] = rd + break ihash = str(info.info_hash()) - new_uri = os.path.join( - data_dir, "{}.torrent".format(ihash) - ) + path = save_data_path("epour") + new_uri = os.path.join(path, "{0}.torrent".format(ihash)) if t_uri == new_uri: pass diff --git a/setup.py b/setup.py index 6dfa4f2..c98de06 100755 --- a/setup.py +++ b/setup.py @@ -11,9 +11,9 @@ setup( author_email='kai.huuhko@gmail.com', maintainer='Kai Huuhko', maintainer_email='kai.huuhko@gmail.com', - description='A torrent client', + description='A BitTorrent client', long_description=( - 'Epour is a torrent client based on EFL and rb-libtorrent.' + 'Epour is a BitTorrent client based on EFL and rb-libtorrent.' ), #url='', #download_url='', @@ -22,6 +22,8 @@ setup( requires=[ 'libtorrent', 'efl', + 'xdg', + 'dbus', ], provides=[ 'epour',