Mass user-creation script
I've just put a mass user-creation script on the wiki. It allows you to create any number of users and have them be auto-validated. It will also randomly create watch/trust edges between the created users, and if you specify it, they will all join any given community. This makes it extremely useful when you have a bug that requires a large number of users to test, such as bug 2215: member list page: "jump to account" does not jump to username, which requires more than 100 users in a single community.
(I actually already had this script created some time ago, but hadn't released it publicly. However, when I saw
kjwcode manually creating 100 users in order to test the patch on the aforementioned bug, I added the community-joining ability and offered the script to him, and realised I should probably release it for all to use!)
There are a few things the script doesn't do yet. For example, while it can make all the users join a community, it won't make any of them subscribe to it. If anybody wants more features added, let me know!
And, in the interests of code preservation (in case the wiki ever disappears for some reason - not that it should), I'm reproducing the code as it is now inside a cut. Bear in mind that it's possible that the version on the wiki may be more up-to-date if it's been some time since this post was made, so you should probably check on the wiki first!
Source code follows:
(I actually already had this script created some time ago, but hadn't released it publicly. However, when I saw
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
There are a few things the script doesn't do yet. For example, while it can make all the users join a community, it won't make any of them subscribe to it. If anybody wants more features added, let me know!
And, in the interests of code preservation (in case the wiki ever disappears for some reason - not that it should), I'm reproducing the code as it is now inside a cut. Bear in mind that it's possible that the version on the wiki may be more up-to-date if it's been some time since this post was made, so you should probably check on the wiki first!
Source code follows:
#!/usr/bin/perl # alter these variables to alter the characteristics of the created accounts my $email = 'your-email@example.com'; my $password = "examplepassword"; my $validated = 1; # validate new accounts automatically? (no email will be sent in either case) # the next two variables are the percentage chance for each user that it'll grant # access to or subscribe to any of the users created by this script, including # itself except where trusting; a user cannot trust themselves. (so a 33% chance # for $accesschance means that on average, it'll grant access to a third of the # users created by this script) my $accesschance = 10; my $subscribechance = 20; # if you want the users to all join the same community, put the name of the # community in the variable below. Note that the community must exist! my $joincommunity = ""; # if undef or empty, do not join any community # ============== use strict; use lib "$ENV{LJHOME}/cgi-bin"; require "ljlib.pl"; my ( $prefix, $num ) = @ARGV; die "Usage: '$0 <prefix> <number of users to create>'\neg, '$0 circletest 100'; this would create circletest1 .. circletest100.\n" unless defined( $num ); die "Second argument must be a number greater than 0, not '$num'.\n" unless $num > 0; die "Prefix is too long for this many users; please shorten the prefix.\n" if length( $prefix ) + length( $num ) > 25; my $goodprefix = LJ::canonical_username( $prefix ); die "'$prefix' uses invalid characters; please use another prefix.\n" unless $goodprefix; print "Creating $num users using prefix '$goodprefix'...\n"; $| = 1; # disable buffering for (my $i = 1; $i <= $num; $i++) { my $user = $goodprefix . $i; LJ::MemCache::delete( 'uidof:' . $user ); my $u2 = LJ::load_user( $user ); if ( $u2 ) { print "User '$user' already exists, skipping\n"; next; } print "Creating '$user'... "; my $u = LJ::User->create_personal( user => $user, email => $email, password => $password ); if ( $u ) { print "(userid=" . $u->id . ") "; if ( $validated ) { print "validating... "; LJ::update_user($u, { status => 'A' }); $u->update_email_alias; LJ::Hooks::run_hook( 'email_verified', $u ); } print "done.\n"; } else { die "could not create user! Aborting.\n"; } } print "All users created, creating edges...\n"; for (my $i = 1; $i <= $num; $i++) { my $from_user = $goodprefix . $i; my $from_u = LJ::load_user( $from_user ); die "Could not load from_user '$from_user'" unless $from_u; for (my $j = 1; $j <= $num; $j++) { my $to_user = $goodprefix . $j; my $watch = ( ( int( rand( 100 ) ) + 1 ) <= $subscribechance ); my $trust = ( ( int( rand( 100 ) ) + 1 ) <= $accesschance ) && ( $from_user ne $to_user ); next unless ( $watch || $trust ); # skip loading the user unless we're actually going to do anything my $to_u = LJ::load_user( $to_user ); die "Could not load to_user '$to_user'" unless $to_u; my @actions = (); push(@actions, "watch") if $watch; push(@actions, "trust") if $trust; print "$from_user -> $to_user (" . join(", ", @actions) . ")\n"; $from_u->add_edge( $to_u, watch => { nonotify => 1 } ) if $watch; $from_u->add_edge( $to_u, trust => { nonotify => 1 } ) if $trust; } } if ($joincommunity ne "") { my $cu = LJ::load_user($joincommunity); die "Could not load community '$joincommunity'. Aborting.\n" unless $cu; print "Having all users join '" . $cu->username . "'...\n"; for (my $i = 1; $i <= $num; $i++) { my $user = $goodprefix . $i; my $u = LJ::load_user( $user ); die "Could not load user '$user'" unless $u; my $joined = $u->join_community( $cu ); unless ($joined) { die "Error while joining user '$user' to community '" . $cu->username . "'"; } } } print "All done!\n";
no subject
no subject
And exor has a tool repo? Where?
no subject
Personally, I think the 'dw' script is best kept for the really common operations such as updating, syncing, making patches, etc. But of course, it's your script, so feel free to do with it what you will!
And yes, Dre has a tools repo! Or more accurately, Dre and Afuna do. There's info on how to use it here: http://wiki.dwscoalition.org/notes/Dev_Tools
no subject
I still want a version of a user create script which is good for creating individual users and communities and works mostly with command line switches rather than edited defaults like yours does. Easy to alter yours to do that too if I ever feel like it!
Thanks :)
no subject
[edit: I don't think it auto-validates though. That could actually be a useful feature; in fact it's probably worth putting it in Bugzilla, I think :D]
no subject
no subject
no subject
I'd be interested in any detail you could provide - possibly via AIM or IRC next we meet? - as I'm struggling with asking so many questions in #dreamwidth-dev and feeling bad about it. I know it's silly but it's real to me :/
no subject
But yes, this is a generally useful thing, yay.