from allmydata.dirnode import NewDirectoryNode
from allmydata.mutable.filenode import MutableFileNode, MutableWatcher
from allmydata.stats import StatsProvider
+from allmydata.history import History
from allmydata.interfaces import IURI, INewDirectoryURI, IStatsProducer, \
IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient
convergence_s = self.get_or_create_private_config('convergence', _make_secret)
self.convergence = base32.a2b(convergence_s)
self._node_cache = weakref.WeakValueDictionary() # uri -> node
+ self.add_service(History())
self.add_service(Uploader(helper_furl, self.stats_provider))
download_cachedir = os.path.join(self.basedir,
"private", "cache", "download")
d.addErrback(log.err, facility="tahoe.init",
level=log.BAD, umid="OEHq3g")
+ def get_history(self):
+ return self.getServiceNamed("history")
+
def init_control(self):
d = self.when_tub_ready()
def _publish(res):
return uploader.list_all_upload_statuses()
def list_all_download_statuses(self):
- downloader = self.getServiceNamed("downloader")
- return downloader.list_all_download_statuses()
+ return self.get_history().list_all_download_statuses()
def list_all_mapupdate_statuses(self):
watcher = self.getServiceNamed("mutable-watcher")
--- /dev/null
+
+import weakref
+from twisted.application import service
+
+class History(service.Service):
+ """Keep track of recent operations, for a status display."""
+
+ name = "history"
+ MAX_DOWNLOAD_STATUSES = 10
+
+ def __init__(self):
+ self.all_downloads_statuses = weakref.WeakKeyDictionary()
+ self.recent_download_statuses = []
+
+ def add_download(self, download_status):
+ self.all_downloads_statuses[download_status] = None
+ self.recent_download_statuses.append(download_status)
+ while len(self.recent_download_statuses) > self.MAX_DOWNLOAD_STATUSES:
+ self.recent_download_statuses.pop(0)
+
+ def list_all_download_statuses(self):
+ for ds in self.all_downloads_statuses:
+ yield ds
# It is scheduled to go away, to be replaced by filenode.download()
implements(IDownloader)
name = "downloader"
- MAX_DOWNLOAD_STATUSES = 10
def __init__(self, stats_provider=None):
service.MultiService.__init__(self)
self.stats_provider = stats_provider
self._all_downloads = weakref.WeakKeyDictionary() # for debugging
- self._all_download_statuses = weakref.WeakKeyDictionary()
- self._recent_download_statuses = []
- def download(self, u, t, _log_msg_id=None, monitor=None):
+ def download(self, u, t, _log_msg_id=None, monitor=None, history=None):
assert self.parent
assert self.running
u = IFileURI(u)
if not monitor:
monitor=Monitor()
dl = CiphertextDownloader(self.parent, u.get_verify_cap(), target, monitor=monitor)
- self._add_download(dl)
+ self._all_downloads[dl] = None
+ s = dl.get_download_status()
+ if history:
+ history.add_download(s)
d = dl.start()
return d
# utility functions
- def download_to_data(self, uri, _log_msg_id=None):
- return self.download(uri, Data(), _log_msg_id=_log_msg_id)
+ def download_to_data(self, uri, _log_msg_id=None, history=None):
+ return self.download(uri, Data(), _log_msg_id=_log_msg_id, history=history)
def download_to_filename(self, uri, filename, _log_msg_id=None):
return self.download(uri, FileName(filename), _log_msg_id=_log_msg_id)
def download_to_filehandle(self, uri, filehandle, _log_msg_id=None):
return self.download(uri, FileHandle(filehandle), _log_msg_id=_log_msg_id)
-
- def _add_download(self, downloader):
- self._all_downloads[downloader] = None
- s = downloader.get_download_status()
- self._all_download_statuses[s] = None
- self._recent_download_statuses.append(s)
- while len(self._recent_download_statuses) > self.MAX_DOWNLOAD_STATUSES:
- self._recent_download_statuses.pop(0)
-
- def list_all_download_statuses(self):
- for ds in self._all_download_statuses:
- yield ds
def download(self, target):
downloader = self._client.getServiceNamed("downloader")
- return downloader.download(self.get_uri(), target, self._parentmsgid)
+ history = self._client.get_history()
+ return downloader.download(self.get_uri(), target, self._parentmsgid,
+ history=history)
def download_to_data(self):
downloader = self._client.getServiceNamed("downloader")
- return downloader.download_to_data(self.get_uri())
+ history = self._client.get_history()
+ return downloader.download_to_data(self.get_uri(), history=history)
class LiteralProducer:
implements(IPushProducer)