[yum-commits] urlgrabber/grabber.py

James Antill james at osuosl.org
Tue Dec 7 16:11:23 UTC 2010


 urlgrabber/grabber.py |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

New commits:
commit 86c9941d80fd380580a44178a0fa9654891ffbb1
Author: James Antill <james at and.org>
Date:   Mon Dec 6 10:38:29 2010 -0500

    Save where we downloaded the file from, in an xattr (requires pyxattr).

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 65e0720..134050d 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -443,6 +443,13 @@ from httplib import HTTPException
 import socket
 from byterange import range_tuple_normalize, range_tuple_to_header, RangeError
 
+try:
+    import xattr
+    if not hasattr(xattr, 'set'):
+        xattr = None # This is a "newer" API.
+except ImportError:
+    xattr = None
+
 ########################################################################
 #                     MODULE INITIALIZATION
 ########################################################################
@@ -1591,12 +1598,19 @@ class PyCurlFileObject(object):
             self.fo.close()
             raise e
     
-
-
         if _was_filename:
             # close it up
             self.fo.flush()
             self.fo.close()
+
+            # Set the URL where we got it from:
+            if xattr is not None:
+                # See: http://www.freedesktop.org/wiki/CommonExtendedAttributes
+                try:
+                    xattr.set(self.filename, 'user.xdg.origin.url', self.url)
+                except:
+                    pass # URL too long. = IOError ... ignore everything.
+
             # set the time
             mod_time = self.curl_obj.getinfo(pycurl.INFO_FILETIME)
             if mod_time != -1:


More information about the Yum-commits mailing list