Changeset 9b3a32d in trunk


Ignore:
Timestamp:
2008-03-27T18:33:42Z (17 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
36f5c02
Parents:
c04c279
Message:

add GET /uri/URI/?t=deep-size, to compute the total size of immutable files reachable from a given directory

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified docs/webapi.txt

    rc04c279 r9b3a32d  
    562562  Return an HTML-formatted manifest of the given directory, for debugging.
    563563
     564GET $URL?t=deep-size
     565
     566  Return a number (in bytes) containing the sum of the filesize of all
     567  immutable files reachable from the given directory. This is a rough lower
     568  bound of the total space consumed by this subtree. It does not include
     569  space consumed by directories or immutable files, nor does it take
     570  expansion or encoding overhead into account. Later versions of the code may
     571  improve this estimate upwards.
     572
    5645736. XMLRPC (coming soon)
    565574
  • TabularUnified src/allmydata/test/test_web.py

    rc04c279 r9b3a32d  
    738738        def _got(manifest):
    739739            self.failUnless("Refresh Capabilities" in manifest)
     740        d.addCallback(_got)
     741        return d
     742
     743    def test_GET_DIRURL_deepsize(self):
     744        d = self.GET(self.public_url + "/foo?t=deep-size", followRedirect=True)
     745        def _got(manifest):
     746            self.failUnless(re.search(r'^\d+$', manifest), manifest)
     747            self.failUnlessEqual("57", manifest)
    740748        d.addCallback(_got)
    741749        return d
  • TabularUnified src/allmydata/web/directory.xhtml

    rc04c279 r9b3a32d  
    1717<div>Other representations of this directory:
    1818<a href="?t=manifest">manifest</a>,
     19<a href="?t=deep-size">total size</a>,
    1920<a href="?t=uri">URI</a>,
    2021<a href="?t=readonly-uri">read-only URI</a>,
  • TabularUnified src/allmydata/webish.py

    rc04c279 r9b3a32d  
    1313import allmydata # to display import path
    1414from allmydata import download
     15from allmydata.uri import from_string_verifier, CHKFileVerifierURI
    1516from allmydata.upload import FileHandle, FileName
    1617from allmydata import provisioning
     
    12241225        return ctx.tag
    12251226
     1227class DeepSize(rend.Page):
     1228
     1229    def __init__(self, dirnode, dirpath):
     1230        self._dirnode = dirnode
     1231        self._dirpath = dirpath
     1232
     1233    def renderHTTP(self, ctx):
     1234        inevow.IRequest(ctx).setHeader("content-type", "text/plain")
     1235        d = self._dirnode.build_manifest()
     1236        def _measure_size(manifest):
     1237            total = 0
     1238            for verifiercap in manifest:
     1239                u = from_string_verifier(verifiercap)
     1240                if isinstance(u, CHKFileVerifierURI):
     1241                    total += u.size
     1242            return str(total)
     1243        d.addCallback(_measure_size)
     1244        return d
     1245
    12261246class ChildError:
    12271247    implements(inevow.IResource)
     
    13161336                    elif t == "manifest":
    13171337                        return Manifest(node, path), ()
     1338                    elif t == "deep-size":
     1339                        return DeepSize(node, path), ()
    13181340                    elif t == 'rename-form':
    13191341                        return RenameForm(self.name, node, path), ()
Note: See TracChangeset for help on using the changeset viewer.