Revision 2ff02341 snf-pithos-backend/pithos/backends/lib/sqlite/node.py

b/snf-pithos-backend/pithos/backends/lib/sqlite/node.py
302 302
        for r in self.fetchall():
303 303
            hashes += [r[0]]
304 304
            serials += [r[1]]
305
        
305

  
306 306
        q = ("delete from versions "
307 307
             "where node in (select node "
308 308
             "from nodes "
......
402 402
        )
403 403
        return dict(self.execute(q).fetchall())
404 404

  
405
    def node_account_usage(self, account_node, cluster):
406
        select_children = ("select node from nodes where parent = ?")
407
        select_descedents = ("select node from nodes "
408
                             "where parent in (%s) "
409
                             "or node in (%s) ") % ((select_children,)*2)
410
        args = [account_node]*2
411
        q = ("select sum(v.size) from versions v, nodes n "
412
             "where v.node = n.node "
413
             "and n.node in (%s) "
414
             "and v.cluster = ?") % select_descedents
415
        args += [cluster]
405
    def node_account_usage(self, account=None, cluster=0):
406
        """Return usage for a specific account.
416 407

  
408
        Keyword arguments:
409
        account -- (default None: list usage for all the accounts)
410
        cluster -- list current, history or deleted usage (default 0: normal)
411
        """
412

  
413
        q = ("select n3.path, sum(v.size) from "
414
             "versions v, nodes n1, nodes n2, nodes n3 "
415
             "where v.node = n1.node "
416
             "and v.cluster = ? "
417
             "and n1.parent = n2.node "
418
             "and n2.parent = n3.node "
419
             "and n3.parent = 0 "
420
             "and n3.node != 0 ")
421
        args = [cluster]
422
        if account:
423
            q += ("and n3.path = ? ")
424
            args += [account]
425
        q += ("group by n3.path")
426

  
427
        print '###', q, args
417 428
        self.execute(q, args)
418
        return self.fetchone()[0]
429
        return dict(self.fetchall())
419 430

  
420 431
    def policy_get(self, node):
421 432
        q = "select key, value from policy where node = ?"

Also available in: Unified diff