From: Brian Warner Date: Wed, 14 Jan 2009 23:41:06 +0000 (-0700) Subject: upload: move upload history into History object X-Git-Tag: allmydata-tahoe-1.3.0~195 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/bcase?a=commitdiff_plain;h=10268a4f7f9ded6eabcaf5e397a8ba045b872473;p=tahoe-lafs%2Ftahoe-lafs.git upload: move upload history into History object --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index f8ecef7a..321ec2fa 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -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() diff --git a/src/allmydata/history.py b/src/allmydata/history.py index b2c023c9..23798928 100644 --- a/src/allmydata/history.py +++ b/src/allmydata/history.py @@ -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 diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py index a27339fa..17155f44 100644 --- a/src/allmydata/immutable/upload.py +++ b/src/allmydata/immutable/upload.py @@ -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