Author: damoxc

Revision: 5007

Log:
        actually commit ui.common this time

Diff:
Modified: trunk/deluge/ui/common.py
===================================================================
--- trunk/deluge/ui/common.py   2009-04-04 11:31:07 UTC (rev 5006)
+++ trunk/deluge/ui/common.py   2009-04-04 11:32:34 UTC (rev 5007)
@@ -91,6 +91,15 @@
                 "size": self.__m_metadata["info"]["length"],
                 "download": True
         })
+    
+    def as_dict(self, *keys):
+        """
+        Return the torrent info as a dictionary, only including the passed in
+        keys.
+        
+        :param *keys: str, a number of key strings
+        """
+        return dict([(key, getattr(self, key)) for key in keys])
 
     @property
     def name(self):
@@ -184,52 +193,6 @@
         self.walk(write)
         return "\n".join(lines)
 
-def get_torrent_info(filename):
-    """
-    Return the metadata of a torrent file
-    """
-
-    # Get the torrent data from the torrent file
-    try:
-        log.debug("Attempting to open %s.", filename)
-        metadata = bencode.bdecode(open(filename, "rb").read())
-    except Exception, e:
-        log.warning("Unable to open %s: %s", filename, e)
-        raise e
-
-    info_hash = sha(bencode.bencode(metadata["info"])).hexdigest()
-
-    # Get list of files from torrent info
-    paths = {}
-    if metadata["info"].has_key("files"):
-        prefix = ""
-        if len(metadata["info"]["files"]) > 1:
-            prefix = metadata["info"]["name"]
-
-        for f in metadata["info"]["files"]:
-            path = os.path.join(prefix, *f["path"])
-            paths[path] = f
-
-        def walk(path, item):
-            if type(item) is dict:
-                return item
-            return [paths[path]['length'], True]
-
-        file_tree = FileTree(paths)
-        file_tree.walk(walk)
-        files = file_tree.get_tree()
-    else:
-        files = {
-            metadata["info"]["name"]: (metadata["info"]["length"], True)
-        }
-
-    return {
-        "filename": filename,
-        "name": metadata["info"]["name"],
-        "files": files,
-        "info_hash": info_hash
-    }
-
 def get_localhost_auth():
     """
     Grabs the localclient auth line from the 'auth' file and creates a 
localhost uri



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to