]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
upload: move upload history into History object
authorBrian Warner <warner@allmydata.com>
Wed, 14 Jan 2009 23:41:06 +0000 (16:41 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 14 Jan 2009 23:41:06 +0000 (16:41 -0700)
src/allmydata/client.py
src/allmydata/history.py
src/allmydata/immutable/upload.py

index f8ecef7ae053c859b4e1a180d84a0cec79c0b557..321ec2fa675c7888d23c58be283063fdaf2c2591 100644 (file)
@@ -411,12 +411,11 @@ class Client(node.Node, pollmixin.PollMixin):
 
     def upload(self, uploadable):
         uploader = self.getServiceNamed("uploader")
-        return uploader.upload(uploadable)
+        return uploader.upload(uploadable, history=self.get_history())
 
 
     def list_all_upload_statuses(self):
-        uploader = self.getServiceNamed("uploader")
-        return uploader.list_all_upload_statuses()
+        return self.get_history().list_all_upload_statuses()
 
     def list_all_download_statuses(self):
         return self.get_history().list_all_download_statuses()
index b2c023c947287d0a32e6f73450ab5eeb7c57b426..23798928166fb13aa2fd9ef6ef88420a196d3ad1 100644 (file)
@@ -7,10 +7,13 @@ class History(service.Service):
 
     name = "history"
     MAX_DOWNLOAD_STATUSES = 10
+    MAX_UPLOAD_STATUSES = 10
 
     def __init__(self):
         self.all_downloads_statuses = weakref.WeakKeyDictionary()
         self.recent_download_statuses = []
+        self.all_upload_statuses = weakref.WeakKeyDictionary()
+        self.recent_upload_statuses = []
 
     def add_download(self, download_status):
         self.all_downloads_statuses[download_status] = None
@@ -21,3 +24,13 @@ class History(service.Service):
     def list_all_download_statuses(self):
         for ds in self.all_downloads_statuses:
             yield ds
+
+    def add_upload(self, upload_status):
+        self.all_upload_statuses[upload_status] = None
+        self.recent_upload_statuses.append(upload_status)
+        while len(self.recent_upload_statuses) > self.MAX_UPLOAD_STATUSES:
+            self.recent_upload_statuses.pop(0)
+
+    def list_all_upload_statuses(self):
+        for us in self.all_upload_statuses:
+            yield us
index a27339fa6a3b3274bc825b9b2778b8331d9f0198..17155f44b0b8704ab9cce78f6742d532849fd5fb 100644 (file)
@@ -1182,15 +1182,12 @@ class Uploader(service.MultiService, log.PrefixingLogMixin):
     implements(IUploader)
     name = "uploader"
     URI_LIT_SIZE_THRESHOLD = 55
-    MAX_UPLOAD_STATUSES = 10
 
     def __init__(self, helper_furl=None, stats_provider=None):
         self._helper_furl = helper_furl
         self.stats_provider = stats_provider
         self._helper = None
         self._all_uploads = weakref.WeakKeyDictionary() # for debugging
-        self._all_upload_statuses = weakref.WeakKeyDictionary()
-        self._recent_upload_statuses = []
         log.PrefixingLogMixin.__init__(self, facility="tahoe.immutable.upload")
         service.MultiService.__init__(self)
 
@@ -1224,7 +1221,7 @@ class Uploader(service.MultiService, log.PrefixingLogMixin):
         return (self._helper_furl, bool(self._helper))
 
 
-    def upload(self, uploadable):
+    def upload(self, uploadable, history=None):
         """
         Returns a Deferred that will fire with the UploadResults instance.
         """
@@ -1257,7 +1254,9 @@ class Uploader(service.MultiService, log.PrefixingLogMixin):
                     uploader = CHKUploader(self.parent)
                     d2.addCallback(lambda x: uploader.start(eu))
 
-                self._add_upload(uploader)
+                self._all_uploads[uploader] = None
+                if history:
+                    history.add_upload(uploader.get_upload_status())
                 def turn_verifycap_into_read_cap(uploadresults):
                     # Generate the uri from the verifycap plus the key.
                     d3 = uploadable.get_encryption_key()
@@ -1276,15 +1275,3 @@ class Uploader(service.MultiService, log.PrefixingLogMixin):
             return res
         d.addBoth(_done)
         return d
-
-    def _add_upload(self, uploader):
-        s = uploader.get_upload_status()
-        self._all_uploads[uploader] = None
-        self._all_upload_statuses[s] = None
-        self._recent_upload_statuses.append(s)
-        while len(self._recent_upload_statuses) > self.MAX_UPLOAD_STATUSES:
-            self._recent_upload_statuses.pop(0)
-
-    def list_all_upload_statuses(self):
-        for us in self._all_upload_statuses:
-            yield us