def getAunexesForColl(coll):
    aunexes=[]
    conn=getMongoDBConn()
    auvertCursor = getMongoDBColl(DB_NAME,coll,conn).find({'aunex':{'$exists':True}})
    if auvertCursor.count():
        print auvertCursor.count(),'records found'

        for record in auvertCursor:
            aunexes.append(record['aunex'])
            return aunexes
    conn.disconnect()
    return aunexes
def normAunexesInColl(collName):
    conn=getMongoDBConn()
    coll=getMongoDBColl(DB_NAME,collName,conn)
    auvertCursor = coll.find({'aunex':{'$exists':True}})
    if auvertCursor.count():
        for record in auvertCursor:
            aunex=record['aunex']
            # print 'Updating record for',aunex
            normAunex=normalizeName(aunex)
            coll.update({'aunex':aunex},{'$set':{'aunex':normAunex}})
            # print 'Record for',aunex,'updated with',normAunex
    conn.disconnect()
def populateMongoDBColl(collName='authorClaimUsers'):

    conn=getMongoDBConn()

    if getMongoDBColl('authorprofile','authorClaimUsers',conn).find_one({'authorClaimUser':{'$exists':True}}):
        print 'Database already populated!'
        exit()

    
    
    conn.disconnect()
    
    exit()
#!/usr/bin/python

import re
from os.path import join
from os import listdir
from authorprofile.common import getMongoDBColl,getMongoDBConn

conn=getMongoDBConn()
records=getMongoDBColl('authorprofile','auversion',conn).find({'amfCollection':{'$exists':True},'lastUpdateSuccessful':False})
numberOfRecords=records.count()
if numberOfRecords:
    print 'The auversion process has not finished for',numberOfRecords,'files:'
    for record in records:
        print record['filePath']
conn.disconnect()

conn=getMongoDBConn()
records=getMongoDBColl('authorprofile','auversion',conn).find({'aunex':{'$exists':True},'lastUpdateSuccessful':False})
if records.count():
    print 'Auversion insertion/updates have not finished for the following author-namestrings/aunexes:'
    for record in records.sort('timeLastUpdated'):
        print record['aunex']
conn.disconnect()

for pid in [pid for pid in listdir('/proc') if pid.isdigit()]:
#print open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
    cmdLineInvocation=open(join('/proc', pid, 'cmdline'), 'rb').read()
    if 'vertical.pl' in cmdLineInvocation:
        print 'Vertical integration calculations are currently being performed for:',re.search('p[a-zA-Z]{2}\d+',cmdLineInvocation).group(0)

conn=getMongoDBConn()