#!/usr/bin/python # This script will read info from an SQLite DB created by # the map_disk.py script and print a brief report. import sqlite3 as lite import sys import os from os.path import join, getsize, getatime, getmtime, getctime from os import stat from pwd import getpwuid # This routine stolen from the web ... def GetHumanReadable(size,precision=2): suffixes=['B','KB','MB','GB','TB'] suffixIndex = 0 while size > 1024: suffixIndex += 1 #increment the index of the suffix size = size/1024.0 #apply the division return "%.*f %s"%(precision,size,suffixes[suffixIndex]) # Connect to SQLite DB file, creating it in necessary con = lite.connect('map_disk.db') with con: # Specify that next cursor should be "dictionary" # (i.e. python's hash map) so columns can be indexed # by name con.row_factory = lite.Row # Create cursor cur = con.cursor() # Print top 10 biggest users print " " print "Biggest Users" print "---------------------" query = "SELECT * FROM Users ORDER BY tot_size DESC LIMIT 10" cur.execute(query) rows = cur.fetchall() for row in rows: size = GetHumanReadable(int(row["tot_size"])) print "%s %s" % (size, row["owner"]) print " " # Print top 10 biggest directories print "Biggest Directories" print "---------------------" query = "SELECT * FROM Dirs ORDER BY size DESC LIMIT 10" cur.execute(query) rows = cur.fetchall() for row in rows: size = GetHumanReadable(int(row["size"])) print "%s %s" % (size, row["fullpath"]) print " " # Print top 10 biggest files print "Biggest files" print "---------------------" query = "SELECT * FROM Files ORDER BY size DESC LIMIT 10" cur.execute(query) rows = cur.fetchall() for row in rows: size = GetHumanReadable(int(row["size"])) print "%s %s" % (size, row["fullpath"]) print " " # Scan info cur.execute("SELECT length(key) AS len FROM Info ORDER BY len DESC LIMIT 1") rows = cur.fetchall() len = rows[0]["len"] print "Scan Info." print "---------------------" query = "SELECT *,length(key) AS len FROM Info" cur.execute(query) rows = cur.fetchall() for row in rows: pad_spaces = len - row["len"] print "%s%s = %s" % (' '*pad_spaces, row["key"], row["val"]) print " "