Re: Script to delete fake accounts

2010-07-05 Thread Christian Hammond
Hi David,

In Review Board 1.5, you can actually write custom management commands,
which would make it much easier to run this script. To do this, you create a
commands directory in your site directory and put the file in there as
mycommandname.py.

The command would need to follow the standard Django management command
format, described here:

http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

Yours looks to be simple, as it doesn't require parameters, so you could do:

from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
def handle_noargs(self, **options):
# All your existing logic below goes here

Then to run it: rb-site manage /path/to/site mycommandname

Christian

-- 
Christian Hammond - chip...@chipx86.com
Review Board - http://www.reviewboard.org
VMware, Inc. - http://www.vmware.com


On Wed, Jun 30, 2010 at 3:14 PM, David Solbach d...@vidsolbach.de wrote:

 Hi,

 a while ago I asked in this mailing list how to delete the accounts of
 'fake
 users' or spam accounts in a public reviewboard instance.

 Today I managed to do it via a little script that can be run from a python
 console. Maybe it can help some of you to do the same. The script walks
 over
 all users in the database and deletes all users who have never done
 anything
 else in reviewboard but registering and visiting a review.

 So every user who is associated to at least one ReviewComment or some other
 meaningful object in the database is spared.

 Here is the script:

 # -*- coding: utf-8 -*-

 from django.contrib.auth.models import User
 from django.db.models.query_utils import CollectedObjects

 spam = 0
 ham = 0

 for user in User.objects.all():
  print User: %s ... % user,
  isactive = False
  seen_objs = None
  seen_objs = CollectedObjects(seen_objs)
  user._collect_sub_objects(seen_objs)
  for obj in seen_objs.keys():
if (obj.__name__ != Profile) and (obj.__name__ !=
 ReviewRequestVisit):
  isactive = True
  break
  if (isactive):
print Active (found associated %s) % obj
ham = ham + 1
  else:
spam = spam + 1
#user.delete()
print DELETED

 print Total HAM  %d % ham
 print Total SPAM %d % spam


 You can simply run it by typing

 rb-site manage /path/to/site shell

 and then pasting the script above. (make sure you have a backup of you
 database!)

 Cheers,

 David

 PS: note that I commented the line that actually does the deletion, so you
 can
 do a dry run  before

 --
 Want to help the Review Board project? Donate today at
 http://www.reviewboard.org/donate/
 Happy user? Let us know at http://www.reviewboard.org/users/
 -~--~~~~--~~--~--~---
 To unsubscribe from this group, send email to
 reviewboard+unsubscr...@googlegroups.comreviewboard%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/reviewboard?hl=en

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~--~~~~--~~--~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en

Re: Script to delete fake accounts

2010-07-05 Thread David Solbach
Sounds cool. Thanks for the tip!

David

Am Montag, 5. Juli 2010, 23:19:55 schrieb Christian Hammond:
 Hi David,
 
 In Review Board 1.5, you can actually write custom management commands,
 which would make it much easier to run this script. To do this, you create
 a commands directory in your site directory and put the file in there as
 mycommandname.py.
 
 The command would need to follow the standard Django management command
 format, described here:
 
 http://docs.djangoproject.com/en/dev/howto/custom-management-commands/
 
 Yours looks to be simple, as it doesn't require parameters, so you could
 do:
 
 from django.core.management.base import NoArgsCommand
 
 class Command(NoArgsCommand):
 def handle_noargs(self, **options):
 # All your existing logic below goes here
 
 Then to run it: rb-site manage /path/to/site mycommandname
 
 Christian
 
  Hi,
  
  a while ago I asked in this mailing list how to delete the accounts of
  'fake
  users' or spam accounts in a public reviewboard instance.
  
  Today I managed to do it via a little script that can be run from a
  python console. Maybe it can help some of you to do the same. The script
  walks over
  all users in the database and deletes all users who have never done
  anything
  else in reviewboard but registering and visiting a review.
  
  So every user who is associated to at least one ReviewComment or some
  other meaningful object in the database is spared.
  
  Here is the script:
  
  # -*- coding: utf-8 -*-
  
  from django.contrib.auth.models import User
  from django.db.models.query_utils import CollectedObjects
  
  spam = 0
  ham = 0
  
  for user in User.objects.all():
   print User: %s ... % user,
   isactive = False
   seen_objs = None
   seen_objs = CollectedObjects(seen_objs)
   user._collect_sub_objects(seen_objs)
   
   for obj in seen_objs.keys():
 if (obj.__name__ != Profile) and (obj.__name__ !=
  
  ReviewRequestVisit):
   isactive = True
   break
   
   if (isactive):
 print Active (found associated %s) % obj
 ham = ham + 1
   
   else:
 spam = spam + 1
 #user.delete()
 print DELETED
  
  print Total HAM  %d % ham
  print Total SPAM %d % spam
  
  
  You can simply run it by typing
  
  rb-site manage /path/to/site shell
  
  and then pasting the script above. (make sure you have a backup of you
  database!)
  
  Cheers,
  
  David
  
  PS: note that I commented the line that actually does the deletion, so
  you can
  do a dry run  before
  
  --
  Want to help the Review Board project? Donate today at
  http://www.reviewboard.org/donate/
  Happy user? Let us know at http://www.reviewboard.org/users/
  -~--~~~~--~~--~--~---
  To unsubscribe from this group, send email to
  reviewboard+unsubscr...@googlegroups.comreviewboard%2bunsubscr...@google
  groups.com For more options, visit this group at
  http://groups.google.com/group/reviewboard?hl=en

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~--~~~~--~~--~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en