class name cleanups: s/FileNode/ImmutableFileNode/

also fix test/bench_dirnode.py for recent dirnode changes
This commit is contained in:
Brian Warner 2009-11-19 23:22:39 -08:00
parent 6e7fb1006d
commit d2badbea78
6 changed files with 33 additions and 26 deletions

View File

@ -72,9 +72,9 @@ class DownloadCache:
self.cachefile = None self.cachefile = None
self.download_in_progress = False self.download_in_progress = False
# five states: # five states:
# new FileNode, no downloads ever performed # new ImmutableFileNode, no downloads ever performed
# new FileNode, leftover file (partial) # new ImmutableFileNode, leftover file (partial)
# new FileNode, leftover file (whole) # new ImmutableFileNode, leftover file (whole)
# download in progress, not yet complete # download in progress, not yet complete
# download complete # download complete
@ -178,7 +178,7 @@ class DownloadCache:
pass pass
class FileNode(_ImmutableFileNodeBase, log.PrefixingLogMixin): class ImmutableFileNode(_ImmutableFileNodeBase, log.PrefixingLogMixin):
def __init__(self, filecap, storage_broker, secret_holder, def __init__(self, filecap, storage_broker, secret_holder,
downloader, history, cachedirectorymanager): downloader, history, cachedirectorymanager):
assert isinstance(filecap, CHKFileURI) assert isinstance(filecap, CHKFileURI)

View File

@ -956,9 +956,9 @@ class IDirectoryNode(IMutableFilesystemNode):
def add_file(name, uploadable, metadata=None, overwrite=True): def add_file(name, uploadable, metadata=None, overwrite=True):
"""I upload a file (using the given IUploadable), then attach the """I upload a file (using the given IUploadable), then attach the
resulting FileNode to the directory at the given name. I set metadata resulting ImmutableFileNode to the directory at the given name. I set
the same way as set_uri and set_node. The child name must be a metadata the same way as set_uri and set_node. The child name must be
unicode string. a unicode string.
I return a Deferred that fires (with the IFileNode of the uploaded I return a Deferred that fires (with the IFileNode of the uploaded
file) when the operation completes.""" file) when the operation completes."""
@ -2069,7 +2069,7 @@ class IClient(Interface):
@return: an instance that provides IFilesystemNode (or more usefully @return: an instance that provides IFilesystemNode (or more usefully
one of its subclasses). File-specifying URIs will result in one of its subclasses). File-specifying URIs will result in
IFileNode or IMutableFileNode -providing instances, like IFileNode or IMutableFileNode -providing instances, like
FileNode, LiteralFileNode, or MutableFileNode. ImmutableFileNode, LiteralFileNode, or MutableFileNode.
Directory-specifying URIs will result in Directory-specifying URIs will result in
IDirectoryNode-providing instances, like DirectoryNode. IDirectoryNode-providing instances, like DirectoryNode.
""" """

View File

@ -2,7 +2,7 @@ import weakref
from zope.interface import implements from zope.interface import implements
from allmydata.util.assertutil import precondition from allmydata.util.assertutil import precondition
from allmydata.interfaces import INodeMaker, NotDeepImmutableError from allmydata.interfaces import INodeMaker, NotDeepImmutableError
from allmydata.immutable.filenode import FileNode, LiteralFileNode from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode
from allmydata.immutable.upload import Data from allmydata.immutable.upload import Data
from allmydata.mutable.filenode import MutableFileNode from allmydata.mutable.filenode import MutableFileNode
from allmydata.dirnode import DirectoryNode, pack_children from allmydata.dirnode import DirectoryNode, pack_children
@ -33,9 +33,9 @@ class NodeMaker:
def _create_lit(self, cap): def _create_lit(self, cap):
return LiteralFileNode(cap) return LiteralFileNode(cap)
def _create_immutable(self, cap): def _create_immutable(self, cap):
return FileNode(cap, self.storage_broker, self.secret_holder, return ImmutableFileNode(cap, self.storage_broker, self.secret_holder,
self.downloader, self.history, self.downloader, self.history,
self.download_cache_dirman) self.download_cache_dirman)
def _create_mutable(self, cap): def _create_mutable(self, cap):
n = MutableFileNode(self.storage_broker, self.secret_holder, n = MutableFileNode(self.storage_broker, self.secret_holder,
self.default_encoding_parameters, self.default_encoding_parameters,

View File

@ -2,14 +2,17 @@ import hotshot.stats, os, random, sys
from pyutil import benchutil, randutil # http://allmydata.org/trac/pyutil from pyutil import benchutil, randutil # http://allmydata.org/trac/pyutil
from zope.interface import implements
from allmydata import dirnode, uri from allmydata import dirnode, uri
from allmydata.mutable import filenode as mut_filenode from allmydata.interfaces import IFileNode
from allmydata.immutable import filenode as immut_filenode from allmydata.mutable.filenode import MutableFileNode
from allmydata.immutable.filenode import ImmutableFileNode
children = [] # tuples of (k, v) (suitable for passing to dict()) children = [] # tuples of (k, v) (suitable for passing to dict())
packstr = None packstr = None
class ContainerNode: class ContainerNode:
implements(IFileNode)
# dirnodes sit on top of a "container" filenode, from which it extracts a # dirnodes sit on top of a "container" filenode, from which it extracts a
# writekey # writekey
def __init__(self): def __init__(self):
@ -18,6 +21,8 @@ class ContainerNode:
self._cap = uri.WriteableSSKFileURI(self._writekey, self._fingerprint) self._cap = uri.WriteableSSKFileURI(self._writekey, self._fingerprint)
def get_writekey(self): def get_writekey(self):
return self._writekey return self._writekey
def get_cap(self):
return self._cap
def get_uri(self): def get_uri(self):
return self._cap.to_string() return self._cap.to_string()
def is_readonly(self): def is_readonly(self):
@ -45,17 +50,17 @@ def random_fsnode():
random.randrange(1, 5), random.randrange(1, 5),
random.randrange(6, 15), random.randrange(6, 15),
random.randrange(99, 1000000000000)) random.randrange(99, 1000000000000))
return immut_filenode.FileNode(cap, None, None, None, None, None) return ImmutableFileNode(cap, None, None, None, None, None)
elif coin == 1: elif coin == 1:
cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16), cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16),
randutil.insecurerandstr(32)) randutil.insecurerandstr(32))
n = mut_filenode.MutableFileNode(None, None, encoding_parameters, None) n = MutableFileNode(None, None, encoding_parameters, None)
return n.init_from_cap(cap) return n.init_from_cap(cap)
else: else:
assert coin == 2 assert coin == 2
cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16), cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16),
randutil.insecurerandstr(32)) randutil.insecurerandstr(32))
n = mut_filenode.MutableFileNode(None, None, encoding_parameters, None) n = MutableFileNode(None, None, encoding_parameters, None)
n.init_from_cap(cap) n.init_from_cap(cap)
return dirnode.DirectoryNode(n, nodemaker, uploader=None) return dirnode.DirectoryNode(n, nodemaker, uploader=None)

View File

@ -2,7 +2,8 @@
from twisted.trial import unittest from twisted.trial import unittest
from allmydata import uri, client from allmydata import uri, client
from allmydata.monitor import Monitor from allmydata.monitor import Monitor
from allmydata.immutable import filenode, download from allmydata.immutable import download
from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode
from allmydata.mutable.filenode import MutableFileNode from allmydata.mutable.filenode import MutableFileNode
from allmydata.util import hashutil, cachedir from allmydata.util import hashutil, cachedir
from allmydata.test.common import download_to_data from allmydata.test.common import download_to_data
@ -32,8 +33,8 @@ class Node(unittest.TestCase):
size=1000) size=1000)
c = FakeClient() c = FakeClient()
cf = cachedir.CacheFile("none") cf = cachedir.CacheFile("none")
fn1 = filenode.FileNode(u, None, None, None, None, cf) fn1 = ImmutableFileNode(u, None, None, None, None, cf)
fn2 = filenode.FileNode(u, None, None, None, None, cf) fn2 = ImmutableFileNode(u, None, None, None, None, cf)
self.failUnlessEqual(fn1, fn2) self.failUnlessEqual(fn1, fn2)
self.failIfEqual(fn1, "I am not a filenode") self.failIfEqual(fn1, "I am not a filenode")
self.failIfEqual(fn1, NotANode()) self.failIfEqual(fn1, NotANode())
@ -56,8 +57,8 @@ class Node(unittest.TestCase):
DATA = "I am a short file." DATA = "I am a short file."
u = uri.LiteralFileURI(data=DATA) u = uri.LiteralFileURI(data=DATA)
c = None c = None
fn1 = filenode.LiteralFileNode(u) fn1 = LiteralFileNode(u)
fn2 = filenode.LiteralFileNode(u) fn2 = LiteralFileNode(u)
self.failUnlessEqual(fn1, fn2) self.failUnlessEqual(fn1, fn2)
self.failIfEqual(fn1, "I am not a filenode") self.failIfEqual(fn1, "I am not a filenode")
self.failIfEqual(fn1, NotANode()) self.failIfEqual(fn1, NotANode())
@ -151,7 +152,7 @@ class LiteralChecker(unittest.TestCase):
def test_literal_filenode(self): def test_literal_filenode(self):
DATA = "I am a short file." DATA = "I am a short file."
u = uri.LiteralFileURI(data=DATA) u = uri.LiteralFileURI(data=DATA)
fn1 = filenode.LiteralFileNode(u) fn1 = LiteralFileNode(u)
d = fn1.check(Monitor()) d = fn1.check(Monitor())
def _check_checker_results(cr): def _check_checker_results(cr):

View File

@ -11,7 +11,8 @@ import allmydata
from allmydata import uri from allmydata import uri
from allmydata.storage.mutable import MutableShareFile from allmydata.storage.mutable import MutableShareFile
from allmydata.storage.server import si_a2b from allmydata.storage.server import si_a2b
from allmydata.immutable import download, filenode, offloaded, upload from allmydata.immutable import download, offloaded, upload
from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode
from allmydata.util import idlib, mathutil from allmydata.util import idlib, mathutil
from allmydata.util import log, base32 from allmydata.util import log, base32
from allmydata.scripts import runner from allmydata.scripts import runner
@ -1770,7 +1771,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
d.addCallback(lambda res: self._personal_node.get(u"big file")) d.addCallback(lambda res: self._personal_node.get(u"big file"))
def _got_chk_filenode(n): def _got_chk_filenode(n):
self.failUnless(isinstance(n, filenode.FileNode)) self.failUnless(isinstance(n, ImmutableFileNode))
d = n.check(Monitor()) d = n.check(Monitor())
def _check_filenode_results(r): def _check_filenode_results(r):
self.failUnless(r.is_healthy()) self.failUnless(r.is_healthy())
@ -1782,7 +1783,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
d.addCallback(lambda res: self._personal_node.get(u"sekrit data")) d.addCallback(lambda res: self._personal_node.get(u"sekrit data"))
def _got_lit_filenode(n): def _got_lit_filenode(n):
self.failUnless(isinstance(n, filenode.LiteralFileNode)) self.failUnless(isinstance(n, LiteralFileNode))
d = n.check(Monitor()) d = n.check(Monitor())
def _check_lit_filenode_results(r): def _check_lit_filenode_results(r):
self.failUnlessEqual(r, None) self.failUnlessEqual(r, None)