Beispiel #1
0
def quotacheck(sa_session, users, engine):
    sa_session.refresh(user)
    current = user.get_disk_usage()
    print user.username, '<' + user.email + '>:',
    if engine not in ('postgres', 'postgresql'):
        new = user.calculate_disk_usage()
        sa_session.refresh(user)
        # usage changed while calculating, do it again
        if user.get_disk_usage() != current:
            print 'usage changed while calculating, trying again...'
            return quotacheck(sa_session, user, engine)
    else:
        new = pgcalc(sa_session, user.id, dryrun=options.dryrun)
    # yes, still a small race condition between here and the flush
    print 'old usage:', nice_size(current), 'change:',
    if new in (current, None):
        print 'none'
    else:
        if new > current:
            print '+%s' % (nice_size(new - current))
        else:
            print '-%s' % (nice_size(current - new))
        if not options.dryrun and engine not in ('postgres', 'postgresql'):
            user.set_disk_usage(new)
            sa_session.add(user)
            sa_session.flush()
def quotacheck(sa_session, users, engine):
    sa_session.refresh(user)
    current = user.get_disk_usage()
    print user.username, "<" + user.email + ">:",
    if engine not in ("postgres", "postgresql"):
        new = user.calculate_disk_usage()
        sa_session.refresh(user)
        # usage changed while calculating, do it again
        if user.get_disk_usage() != current:
            print "usage changed while calculating, trying again..."
            return quotacheck(sa_session, user, engine)
    else:
        new = pgcalc(sa_session, user.id, dryrun=options.dryrun)
    # yes, still a small race condition between here and the flush
    print "old usage:", nice_size(current), "change:",
    if new in (current, None):
        print "none"
    else:
        if new > current:
            print "+%s" % (nice_size(new - current))
        else:
            print "-%s" % (nice_size(current - new))
        if not options.dryrun and engine not in ("postgres", "postgresql"):
            user.set_disk_usage(new)
            sa_session.add(user)
            sa_session.flush()
def quotacheck(sa_session, users, engine):
    sa_session.refresh(user)
    current = user.get_disk_usage()
    print(user.username, '<' + user.email + '>:', end=' ')
    if engine not in ('postgres', 'postgresql'):
        new = user.calculate_disk_usage()
        sa_session.refresh(user)
        # usage changed while calculating, do it again
        if user.get_disk_usage() != current:
            print('usage changed while calculating, trying again...')
            return quotacheck(sa_session, user, engine)
    else:
        new = pgcalc(sa_session, user.id, dryrun=args.dryrun)
    # yes, still a small race condition between here and the flush
    print('old usage:', nice_size(current), 'change:', end=' ')
    if new in (current, None):
        print('none')
    else:
        if new > current:
            print('+%s' % (nice_size(new - current)))
        else:
            print('-%s' % (nice_size(current - new)))
        if not args.dryrun and engine not in ('postgres', 'postgresql'):
            user.set_disk_usage(new)
            sa_session.add(user)
            sa_session.flush()
Beispiel #4
0
 def recalculate_user_disk_usage( self, trans, **kwd ):
     user_id = kwd.get( 'id', None )
     user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) )
     if not user:
         return trans.show_error_message( "User not found for id (%s)" % sanitize_text( str( user_id ) ) )
     engine = None
     if trans.app.config.database_connection:
         engine = trans.app.config.database_connection.split(':')[0]
     if engine not in ( 'postgres', 'postgresql' ):
         done = False
         while not done:
             current = user.get_disk_usage()
             new = user.calculate_disk_usage()
             trans.sa_session.refresh( user )
             # make sure usage didn't change while calculating, set done
             if user.get_disk_usage() == current:
                 done = True
             if new not in (current, None):
                 user.set_disk_usage( new )
                 trans.sa_session.add( user )
                 trans.sa_session.flush()
     else:
         # We can use the lightning fast pgcalc!
         current = user.get_disk_usage()
         new = pgcalc( self.sa_session, user.id )
     # yes, still a small race condition between here and the flush
     if new in ( current, None ):
         message = 'Usage is unchanged at %s.' % nice_size( current )
     else:
         message = 'Usage has changed by %s to %s.' % ( nice_size( new - current ), nice_size( new )  )
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='users',
                                                       message=sanitize_text( message ),
                                                       status='info' ) )
 def recalculate_user_disk_usage( self, trans, **kwd ):
     user_id = kwd.get( 'id', None )
     user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) )
     if not user:
         return trans.show_error_message( "User not found for id (%s)" % sanitize_text( str( user_id ) ) )
     engine = None
     if trans.app.config.database_connection:
         engine = trans.app.config.database_connection.split(':')[0]
     if engine not in ( 'postgres', 'postgresql' ):
         done = False
         while not done:
             current = user.get_disk_usage()
             new = user.calculate_disk_usage()
             trans.sa_session.refresh( user )
             # make sure usage didn't change while calculating, set done
             if user.get_disk_usage() == current:
                 done = True
             if new not in (current, None):
                 user.set_disk_usage( new )
                 trans.sa_session.add( user )
                 trans.sa_session.flush()
     else:
         # We can use the lightning fast pgcalc!
         current = user.get_disk_usage()
         new = pgcalc( self.sa_session, user.id )
     # yes, still a small race condition between here and the flush
     if new in ( current, None ):
         message = 'Usage is unchanged at %s.' % nice_size( current )
     else:
         message = 'Usage has changed by %s to %s.' % ( nice_size( new - current ), nice_size( new )  )
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='users',
                                                       message=sanitize_text( message ),
                                                       status='info' ) )
Beispiel #6
0
def recalculate_user_disk_usage(app, **kwargs):
    user_id = kwargs.get('user_id', None)
    sa_session = app.model.context
    if user_id:
        user = sa_session.query( app.model.User ).get( app.security.decode_id( user_id ) )
        if user:
            if sa_session.get_bind().dialect.name not in ( 'postgres', 'postgresql' ):
                new = user.calculate_disk_usage()
            else:
                new = pgcalc(sa_session, user.id)
            user.set_disk_usage(new)
            sa_session.add(user)
            sa_session.flush()