[Yum-devel] [PATCH] Save where we downloaded the file from, in an xattr (requires pyxattr).

James Antill james at and.org
Mon Dec 6 15:40:23 UTC 2010


---
 urlgrabber/grabber.py |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 65e0720..4b34c22 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
 ########################################################################
@@ -1447,8 +1454,8 @@ class PyCurlFileObject(object):
                 raise err
 
     def _do_open(self):
-        self.curl_obj = _curl_cache
-        self.curl_obj.reset() # reset all old settings away, just in case
+        self.curl_obj = pycurl.Curl()
+        # self.curl_obj.reset() # reset all old settings away, just in case
         # setup any ranges
         self._set_opts()
         self._do_grab()
@@ -1591,12 +1598,15 @@ 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:
+                xattr.set(self.filename, 'user.url', self.url)
+
             # set the time
             mod_time = self.curl_obj.getinfo(pycurl.INFO_FILETIME)
             if mod_time != -1:
-- 
1.7.2.3



More information about the Yum-devel mailing list