def remote_write(self, data):
self._bucket.write(data)
+ def remote_set_metadata(self, metadata):
+ self._bucket.set_metadata(metadata)
+
def remote_close(self):
self._bucket.close()
precondition(not os.path.exists(bucket_dir))
os.mkdir(bucket_dir)
+ self._open = True
self._size = size
self._data = file(os.path.join(self._bucket_dir, 'data'), 'wb')
self._bytes_written = 0
self._write_attr('leases', leaser)
def write(self, data):
+ precondition(self._open)
precondition(len(data) + self._bytes_written <= self._size)
self._data.write(data)
self._data.flush()
self._bytes_written += len(data)
+ def set_metadata(self, metadata):
+ precondition(self._open)
+ self._write_attr('metadata', metadata)
+
def close(self):
precondition(self._bytes_written == self._size)
self._data.close()
self._write_attr('closed', '')
+ self._open = False
def is_complete(self):
complete = Bucket.is_complete(self)
def read(self):
return self._read_attr('data')
remote_read = read
+
+ def get_metadata(self):
+ return self._read_attr('metadata')
+ remote_get_metadata = get_metadata
from zope.interface import Interface
-from foolscap.schema import StringConstraint, ListOf, TupleOf, Any, Nothing
+from foolscap.schema import StringConstraint, ListOf, TupleOf, Any
from foolscap import RemoteInterface
Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash
def get_service(name=str):
return Referenceable_
def add_peers(new_peers=ListOf(TupleOf(Nodeid, PBURL), maxLength=100)):
- return Nothing()
+ return None
def lost_peers(lost_peers=ListOf(Nodeid)):
- return Nothing()
+ return None
class RIStorageServer(RemoteInterface):
def allocate_bucket(verifierid=Verifierid, bucket_num=int, size=int,
class RIBucketWriter(RemoteInterface):
def write(data=ShareData):
- return Nothing()
-
+ return None
+ def set_metadata(metadata=str):
+ return None
def close():
- return Nothing()
+ return None
class RIBucketReader(RemoteInterface):
def read():
return ShareData
+ def get_metadata():
+ return str
class RIMutableDirectoryNode(RemoteInterface):
return RIMutableDirectoryNode_
def add_file(name=str, data=Verifierid):
- return Nothing()
+ return None
def remove(name=str):
- return Nothing()
+ return None
# need more to move directories
def write_to_bucket(bucket):
def write_some(junk, bytes):
return bucket.callRemote('write', data=bytes)
+ def set_metadata(junk, metadata):
+ return bucket.callRemote('set_metadata', metadata)
def finalise(junk):
return bucket.callRemote('close')
off1 = len(data) / 2
d = defer.succeed(None)
d.addCallback(write_some, data[:off1])
d.addCallback(write_some, data[off1:off2])
+ d.addCallback(set_metadata, "metadata")
d.addCallback(write_some, data[off2:])
d.addCallback(finalise)
return d
self.failUnlessEqual(bytes_read, data)
d = bucket.callRemote('read')
d.addCallback(check_data)
+
+ def check_metadata(metadata):
+ self.failUnlessEqual(metadata, 'metadata')
+ d.addCallback(lambda res: bucket.callRemote('get_metadata'))
+ d.addCallback(check_metadata)
return d
rssd.addCallback(read_buckets)