upload: move upload history into History object

This commit is contained in:
Brian Warner 2009-01-14 16:41:06 -07:00
parent 3920e6d1e7
commit 10268a4f7f
3 changed files with 19 additions and 20 deletions

View 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()

View 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

View 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