Dashboard > Pulse v2.1 > ... > Remote API Examples > Python Example - Getting Disk Usage Per Project
  Pulse v2.1 Log In | Sign Up   View a printable version of the current page.  
  Python Example - Getting Disk Usage Per Project
Added by Jason Sankey, last edited by Jason Sankey on Aug 23, 2009
Labels: 
(None)

Pulse Manual Index

Overview

This example allows you to see how much disk space the historical build results are using for each project. It requires a recent version of Pulse 2.0, particularly for the RemoteApi.getServerInfo method. For use with earlier 2.0 releases, you can replace the usage of this method by hard-coding the location of the Pulse data directory.

Note that this script must be run on the Pulse master, as it needs direct access to the data directory to determine disk space usage. It is also likely to take a while to execute, especially if your builds capture many artifact files.

Code

#! /usr/bin/env python

import os
import re
from os.path import join, getsize
from xmlrpclib import ServerProxy, Error

USER = 'jblogs'
PASSWORD = 'secret'

def isId(s):
    return re.match(r"[0-9]+", s) is not None

server = ServerProxy("http://localhost/xmlrpc")

try:
    token = server.RemoteApi.login(USER, PASSWORD)
    info = server.RemoteApi.getServerInfo(token)
    projectsDir = join(info['pulse.data.dir'], 'projects')
    projects = dict((id, server.RemoteApi.getProjectNameById(token, id)) for id in os.listdir(projectsDir) if isId(id))
    server.RemoteApi.logout(token)

    for id, name in projects.items():
        totalSize = 0
        for root, dirs, files in os.walk(join(projectsDir, id)):
            totalSize += sum(getsize(join(root, name)) for name in files)
        print "Project %s consumes %.02f megabytes" % (name, totalSize/1048576.0)
except Error, v:
    print "Error:", v

Zutubi wiki is Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators