kuuko pushed a commit to branch master.

http://git.enlightenment.org/apps/epour.git/commit/?id=9d83e78579971827bf5081715b83a3b821ae78af

commit 9d83e78579971827bf5081715b83a3b821ae78af
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Wed Apr 15 14:25:47 2015 +0300

    Fix error on torrent removal
---
 epour/session.py | 72 ++++++++++++++++++++++++--------------------------------
 1 file changed, 31 insertions(+), 41 deletions(-)

diff --git a/epour/session.py b/epour/session.py
index 3fe99f1..8164777 100644
--- a/epour/session.py
+++ b/epour/session.py
@@ -42,13 +42,6 @@ from efl.ecore import Timer
 from xdg.BaseDirectory import save_data_path, load_data_paths
 
 
-def torrent_path_get(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):
     def __init__(self, conf):
         self.conf = conf
@@ -121,7 +114,6 @@ class Session(lt.session):
         h = a.handle
         ihash = str(h.info_hash())
         self.log.debug("Metadata received.")
-        #self.write_torrent(h)
         t_info = h.get_torrent_info()
         t = {}
         t["info"] = lt.bdecode(t_info.metadata())
@@ -255,36 +247,28 @@ class Session(lt.session):
 
         self.log.debug("List of torrents saved.")
 
-        # Save fast resume data
-        # for h in self.get_torrents():
-        #     if not h.is_valid() or not h.has_metadata():
-        #         continue
-        #     data = lt.bencode(h.write_resume_data())
-        #     with open(os.path.join(
-        #         data_dir, str(h.info_hash()) + ".fastresume"
-        #             ), 'wb') as f:
-        #         f.write(data)
-
-        # self.log.debug("Fast resume data saved.")
-
-    def write_torrent(self, h):
-        if h is None:
-            self.log.debug("Tried to write torrent while handle was empty.")
-            return
+    # def write_torrent(self, h):
+    #     if h is None:
+    #         self.log.debug("Tried to write torrent while handle was empty.")
+    #         return
 
-        t_info = h.get_torrent_info()
-        ihash = str(h.info_hash())
+    #     t_info = h.get_torrent_info()
+    #     ihash = str(h.info_hash())
 
-        self.log.debug("Writing torrent file {}".format(ihash))
+    #     self.log.debug("Writing torrent file {}".format(ihash))
 
-        md = lt.bdecode(t_info.metadata())
-        t = {}
-        t["info"] = md
-        t_path = torrent_path_get(ihash)
-        with open(t_path, "wb") as f:
-            f.write(lt.bencode(t))
+    #     md = lt.bdecode(t_info.metadata())
+    #     t = {}
+    #     t["info"] = md
+
+    #     p = save_data_path("epour")
+    #     t_path = os.path.join(p, "{0}.torrent".format(ihash))
 
-        return t_path
+    #     if t_path:
+    #         with open(t_path, "wb") as f:
+    #             f.write(lt.bencode(t))
+
+    #     return t_path
 
     def remove_torrent(self, h, with_data=False):
         ihash = str(h.info_hash())
@@ -307,13 +291,19 @@ class Session(lt.session):
             else:
                 os.remove(fr_path)
 
-        try:
-            with open(torrent_path_get(ihash)):
-                pass
-        except IOError:
-            self.log.debug("Could not remove torrent file.")
-        else:
-            os.remove(torrent_path_get(ihash))
+        t_path = None
+        for p in load_data_paths("epour"):
+            t_path = os.path.join(p, "{0}.torrent".format(ihash))
+            break
+
+        if t_path:
+            try:
+                with open(t_path):
+                    pass
+            except IOError:
+                self.log.debug("Could not remove torrent file.")
+            else:
+                os.remove(t_path)
 
         if not hasattr(lt, "torrent_removed_alert"):
             class torrent_removed_alert(object):

-- 


Reply via email to