2009-01-14 23:14:24 +00:00
|
|
|
|
|
|
|
import weakref
|
|
|
|
|
2019-05-15 06:17:44 +00:00
|
|
|
class History(object):
|
2009-01-14 23:14:24 +00:00
|
|
|
"""Keep track of recent operations, for a status display."""
|
|
|
|
|
|
|
|
name = "history"
|
|
|
|
MAX_DOWNLOAD_STATUSES = 10
|
2009-01-14 23:41:06 +00:00
|
|
|
MAX_UPLOAD_STATUSES = 10
|
2009-01-15 00:36:20 +00:00
|
|
|
MAX_MAPUPDATE_STATUSES = 20
|
|
|
|
MAX_PUBLISH_STATUSES = 20
|
|
|
|
MAX_RETRIEVE_STATUSES = 20
|
|
|
|
|
|
|
|
def __init__(self, stats_provider=None):
|
|
|
|
self.stats_provider = stats_provider
|
2009-01-14 23:14:24 +00:00
|
|
|
|
|
|
|
self.all_downloads_statuses = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_download_statuses = []
|
2009-01-14 23:41:06 +00:00
|
|
|
self.all_upload_statuses = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_upload_statuses = []
|
2009-01-14 23:14:24 +00:00
|
|
|
|
2009-01-15 00:36:20 +00:00
|
|
|
self.all_mapupdate_status = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_mapupdate_status = []
|
|
|
|
self.all_publish_status = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_publish_status = []
|
|
|
|
self.all_retrieve_status = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_retrieve_status = []
|
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.all_helper_upload_statuses = weakref.WeakKeyDictionary()
|
|
|
|
self.recent_helper_upload_statuses = []
|
|
|
|
|
2009-01-15 00:36:20 +00:00
|
|
|
|
2009-01-14 23:14:24 +00:00
|
|
|
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
|
2009-01-14 23:41:06 +00:00
|
|
|
|
|
|
|
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
|
2009-01-15 00:36:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def notify_mapupdate(self, p):
|
|
|
|
self.all_mapupdate_status[p] = None
|
|
|
|
self.recent_mapupdate_status.append(p)
|
|
|
|
while len(self.recent_mapupdate_status) > self.MAX_MAPUPDATE_STATUSES:
|
|
|
|
self.recent_mapupdate_status.pop(0)
|
|
|
|
|
|
|
|
def notify_publish(self, p, size):
|
|
|
|
self.all_publish_status[p] = None
|
|
|
|
self.recent_publish_status.append(p)
|
|
|
|
if self.stats_provider:
|
|
|
|
self.stats_provider.count('mutable.files_published', 1)
|
|
|
|
# We must be told bytes_published as an argument, since the
|
|
|
|
# publish_status does not yet know how much data it will be asked
|
|
|
|
# to send. When we move to MDMF we'll need to find a better way
|
|
|
|
# to handle this.
|
|
|
|
self.stats_provider.count('mutable.bytes_published', size)
|
|
|
|
while len(self.recent_publish_status) > self.MAX_PUBLISH_STATUSES:
|
|
|
|
self.recent_publish_status.pop(0)
|
|
|
|
|
|
|
|
def notify_retrieve(self, r):
|
|
|
|
self.all_retrieve_status[r] = None
|
|
|
|
self.recent_retrieve_status.append(r)
|
|
|
|
if self.stats_provider:
|
|
|
|
self.stats_provider.count('mutable.files_retrieved', 1)
|
|
|
|
self.stats_provider.count('mutable.bytes_retrieved', r.get_size())
|
|
|
|
while len(self.recent_retrieve_status) > self.MAX_RETRIEVE_STATUSES:
|
|
|
|
self.recent_retrieve_status.pop(0)
|
|
|
|
|
|
|
|
|
|
|
|
def list_all_mapupdate_statuses(self):
|
|
|
|
for s in self.all_mapupdate_status:
|
|
|
|
yield s
|
|
|
|
def list_all_publish_statuses(self):
|
|
|
|
for s in self.all_publish_status:
|
|
|
|
yield s
|
|
|
|
def list_all_retrieve_statuses(self):
|
|
|
|
for s in self.all_retrieve_status:
|
|
|
|
yield s
|
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def notify_helper_upload(self, s):
|
|
|
|
self.all_helper_upload_statuses[s] = None
|
|
|
|
self.recent_helper_upload_statuses.append(s)
|
|
|
|
while len(self.recent_helper_upload_statuses) > self.MAX_UPLOAD_STATUSES:
|
|
|
|
self.recent_helper_upload_statuses.pop(0)
|
2009-01-15 00:36:20 +00:00
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def list_all_helper_statuses(self):
|
|
|
|
for s in self.all_helper_upload_statuses:
|
|
|
|
yield s
|
2009-01-15 00:36:20 +00:00
|
|
|
|