Exemplo n.º 1
0
def info(conf):
    '''A basic, incomplete short info.  Displays overall file size and
    account counts.'''

    con = Connection(conf['MONGODB_HOST'], conf['MONGODB_PORT'])
    db = con[conf['MONGODB_NAME']]
    fs = GridFS(db)

    overall_file_size = sum([f['length'] for f in fs._GridFS__files.find()])
    inactivated = [acc for acc in db.accounts.find() if not acc.get('activated_at', True)]
    print fs._GridFS__files.count(), 'files [%s]' % ppsize(overall_file_size)
    print db.accounts.count()-1, 'accounts total,', len(inactivated) , 'not activated'

    con.disconnect()
Exemplo n.º 2
0
def info(conf):
    '''A basic, incomplete short info.  Displays overall file size and
    account counts.'''

    con = Connection(conf['MONGODB_HOST'], conf['MONGODB_PORT'])
    db = con[conf['MONGODB_NAME']]
    fs = GridFS(db)

    overall_file_size = sum([f['length'] for f in fs._GridFS__files.find()])
    inactivated = [
        acc for acc in db.accounts.find() if not acc.get('activated_at', True)
    ]
    print fs._GridFS__files.count(), 'files [%s]' % ppsize(overall_file_size)
    print db.accounts.count() - 1, 'accounts total,', len(
        inactivated), 'not activated'

    con.disconnect()
Exemplo n.º 3
0
def account(conf, options, args):
    '''View details or summary of all accounts.'''

    con = Connection(conf['MONGODB_HOST'], conf['MONGODB_PORT'])
    db = con[conf['MONGODB_NAME']]
    fs = GridFS(db)

    if options.all:
        query = None
    elif len(args) == 2:
        query = {
            '_id': int(args[1])
        } if args[1].isdigit() else {
            'email': args[1]
        }
    else:
        log.error('account <email or _id> requires a valid email or _id')
        sys.exit(1)

    for acc in db.accounts.find(query):
        if str(acc['_id']).startswith('_'):
            continue
        print '%s [id:%s]' % (acc['email'], acc['id'])
        for key in acc:
            if key in ['email', '_id', 'id']:
                continue
            if key == 'items':
                try:
                    size = sum([fs.get(_id).length for _id in acc['items']])
                except NoFile:
                    log.warn('Account `%s` has some files missing:', _id)
                    # fail safe counting
                    size = 0
                    missing = []
                    for i in acc['items']:
                        if not fs.exists(i):
                            missing.append(i)
                        else:
                            size += fs.get(i).length
                print '    size: %s' % ppsize(size)
            print '    %s: %s' % (key, acc[key])
    if options.all:
        print db.accounts.count() - 1, 'accounts total'  # -1 for _autoinc

    con.disconnect()
Exemplo n.º 4
0
def account(conf, options, args):
    '''View details or summary of all accounts.'''

    con = Connection(conf['MONGODB_HOST'], conf['MONGODB_PORT'])
    db = con[conf['MONGODB_NAME']]
    fs = GridFS(db)

    if options.all:
        query = None
    elif len(args) == 2:
        query = {'_id': int(args[1])} if args[1].isdigit() else {'email': args[1]}
    else:
        log.error('account <email or _id> requires a valid email or _id')
        sys.exit(1)

    for acc in db.accounts.find(query):
        if str(acc['_id']).startswith('_'):
            continue
        print '%s [id:%s]' % (acc['email'], acc['id'])
        for key in acc:
            if key in ['email', '_id', 'id']:
                continue
            if key == 'items':
                try:
                    size = sum([fs.get(_id).length for _id in acc['items']])
                except NoFile:
                    log.warn('Account `%s` has some files missing:', _id)
                    # fail safe counting
                    size = 0
                    missing = []
                    for i in acc['items']:
                        if not fs.exists(i):
                            missing.append(i)
                        else:
                            size += fs.get(i).length
                print'    size: %s' % ppsize(size)
            print '    %s: %s' % (key, acc[key])
    if options.all:  print db.accounts.count()-1, 'accounts total' # -1 for _autoinc

    con.disconnect()