#!/usr/local/bin/maxx-python
# report number of objects/rows in each Class/table
# intended to be run with something like:
# ... /home/generic /etc/httpd/conf/aacrao.conf 

import warnings
# make the deprication warnings go away
warnings.filterwarnings('ignore',
                        '.*depreca.*',
                        module='.*')

import sys
import string
import os

if len(sys.argv) == 3:
    pathToRoot = sys.argv[1]
    confFileName = sys.argv[2]
else:
    print "usage: ... pathToRoot confFileName"
    sys.exit(-1)

sys.path.append(pathToRoot+"/libs") # first arg is path to co root
sys.path.append(pathToRoot+"/generic")
import framework.CLHandler
h,pb = framework.CLHandler.makeHandlerAndPB(confFileName)

objs = {} # id->list of classnames
objCount = 0
for clas in pb.classmapsbyname:
    tablename = pb.classmapsbyname[clas].getIDColumn().table.name
    columnname = pb.classmapsbyname[clas].getIDColumn().name
    sql = "select %s as id from %s" % (columnname, tablename)
    try:
        rs = pb.processSql(sql)
        for row in rs:
            if objs.has_key(row['id']):
                objs[row['id']].append(clas)
            else:
                objs[row['id']] = [clas]
            objCount += 1
    except:
        print 'Warning exception processing %s' % clas

print "%d objects processed" % objCount
for id in objs:
    if len(objs[id]) > 1:
        print '%s %s' % (id, objs[id])