5 namecheck - Check project names are not already taken.
9 This is a simple tool to automate the testing of project names at the most
10 common Open Source / Free Software hosting environments.
12 Each new project requires a name, and those names are ideally unique. To come
13 up with names is hard, and testing to ensure they're not already in use is
14 time-consuming - unless you have a tool such as this one.
18 The script, as-is, contains a list of sites, and patterns, to test against.
20 If those patterns aren't sufficient then you may create your own additions and
21 add them to the script. If you wish to have your own version of the patterns
22 you may save them into the file ~/.namecheckrc
26 The most recent version of this script may be found here:
28 http://mybin.repository.steve.org.uk/?raw-file/tip/namecheck
34 http://www.steve.org.uk/
38 Copyright (c) 2008 by Steve Kemp. All rights reserved.
40 This module is free software; you can redistribute it and/or modify it under
41 the same terms as Perl itself.
55 # A module for fetching webpages.
62 # Get the name from the command line.
65 if ( !defined($name) )
76 # Get the patterns we're going to use for testing.
78 my @lines = loadPatterns();
82 # Assuming we have patterns use them.
95 # Load the list of sites, and patterns, to test.
97 # By default these will come from the end of the script
98 # itself. A user may create the file ~/.namecheckrc with
99 # their own patterns if they prefer.
104 my $file = $ENV{ 'HOME' } . "/.namecheckrc";
109 open( FILE, "<", $file )
110 or die "Failed to open $file - $!";
129 # Test the given name against the patterns we've loaded from our
130 # own script, or the users configuration file.
135 my (@patterns) = (@_);
138 # Create and setup an agent for the downloading.
140 my $ua = LWP::UserAgent->new();
141 $ua->agent('Mozilla/5.0');
146 foreach my $entry (@patterns)
150 # Skip blank lines, and comments.
153 next if ( ( !$entry ) || ( !length($entry) ) );
154 next if ( $entry =~ /^#/ );
158 # Each line is an URL + a pattern, separated by a pipe.
160 my ( $url, $pattern ) = split( /\|/, $entry );
163 # Strip leading/trailing spaces.
165 $pattern =~ s/^\s+//;
166 $pattern =~ s/\s+$//;
170 # Interpolate the proposed project name in the string.
172 $url =~ s/\%s/$name/g if ( $url =~ /\%s/ );
175 # Find the hostname we're downloading; just to show the user
176 # something is happening.
179 if ( $urlname =~ /:\/\/([^\/]+)\// )
183 print sprintf "Testing %20s", $urlname;
189 my $response = $ua->get($url);
192 # If success we look at the returned text.
194 if ( $response->is_success() )
198 # Get the page content - collapsing linefeeds.
200 my $c = $response->content();
204 # Does the page have the pattern?
206 if ( $c !~ /\Q$pattern\E/i )
209 print "Aborting - name '$name' is currently used.\n";
214 print " - Available\n";
221 # Otherwise we'll assume that 404 means that the
222 # project isn't taken.
224 my $c = $response->status_line();
227 print " - Available\n";
233 # Other errors we can't handle.
235 print "ERROR fetching $url - $c\n";
243 # If we got here the name is free.
245 print "\n\nThe name '$name' doesn't appear to be in use.\n";
253 # The default patterns.
255 # If you want to customise them either do so here, or create the
256 # file ~/.namecheckrc with your own contents in the same format.
258 http://%s.tuxfamily.org/ | Not Found
259 http://alioth.debian.org/projects/%s | Invalid Project
260 http://developer.berlios.de/projects/%s | Invalid Project
261 http://freshmeat.net/projects/%s | We encounted an error
262 http://launchpad.net/%s | no page with this address
263 http://savannah.gnu.org/projects/%s | Invalid Group
264 http://sourceforge.net/projects/%s | Invalid Project
265 http://www.ohloh.net/projects/%s | Sorry, the page you are trying to view is not here
266 https://gna.org/projects/%s | Invalid Group
267 http://code.google.com/p/%s | Not Found