Anonymous user
User:ImplSearchBot/Code: Difference between revisions
m
ImplSearchBot:0
m (ImplSearchBot:0) |
m (ImplSearchBot:0) |
||
Line 4:
use MediaWiki::Bot;
use JSON qw/to_json from_json/;
my $usage = "Usage: $0 --username=(username) --password=(password) [--posttosite=yes]";
Line 17 ⟶ 16:
my $verbosity = 2; # verbosity level. 0 is silent. 1 is error only. 2 is updates. 3 is process, more is noisy.
my $post; # Is this an actual run?
my $cachepath = "cache/";
my $result = GetOptions(
"wiki=s" => \$wiki,
Line 22:
"password=s" => \$password,
"verbosity=s" => \$verbosity,
"post" => \$post
"cachepath=s" => \$cachepath);
$options{'wiki'} = $wiki;
Line 39 ⟶ 40:
$options{'verbosity'} = $verbosity;
$cachepath .= '/'
if('/' ne substr($cachepath, -1, 1));
$options{'cachepath'} = $cachepath;
}
Line 45 ⟶ 51:
my $starttime = time;
my $pagesedited = 0;
# Tracking for svn checkin at end.
# We *should* be the only ones writing to the cache path for now.
# Eventually, we'll keep track of the vision we last ran at, and update to that.
# In the mean time, since the structure of this is a bit unstable for the moment,
# we'll do an update to HEAD just to catch anything silly I might have done in the
# mean time.
&svn('update', $options{'cachepath'});
opendir(CACHEDIR, $options{'cachepath'})
or die "Unable to open cache directory";
my @initialcache = readdir(CACHEDIR);
closedir(CACHEDIR);
&out(scalar @initialcache . " categories initially cached\n", 3);
# Handles interaction with the wiki.
Line 191 ⟶ 211:
&postpage("User:ImplSearchBot/Code", "<$tag perl>$botsource</$tag>", 0);
&out("Updating cache\n", 3);
&commitcache();
&out("Done\n", 2);
Line 260 ⟶ 283:
unless( exists $options{'post'} )
{
# save it to disk, and out of the way.
$pagename = "test/" . &sanitizenamefs($pagename);
$pagename .= ".wikitxt";
Line 298 ⟶ 322:
my $dataname = shift;
my $data = shift;
my $filename = $options{'cachepath'} . &sanitizenamefs($dataname . ".json");
my $outfile;
unless(open $outfile, '>', $filename)
Line 315 ⟶ 339:
{
my $dataname = shift;
my $infile;
unless (open $infile, '<', $filename)
Line 388 ⟶ 412:
return {'impl' => \%impl,
'omit' => \%omit };
}
sub commitcache
{
# First, find out if we've added any files.
my $cachepath = $options{'cachepath'};
print "Cachepath: $cachepath\n";
opendir(CACHEDIR, $cachepath);
my @current = readdir(CACHEDIR);
close(CACHEDIR);
# We need to run svn adds if we've created any new files.
# Maybe we'll use SVN::Client some day. Not right now.
my ($added, $removed) = &diffcat(\@current, \@initialcache);
&out("Detected " . scalar @$added . " new cache files and " . scalar @$removed . " removed\n",2);
if ((scalar @$added + scalar @$removed ) > 0)
{
foreach my $cachefile (@$added)
{
print "cachepath: $cachepath, cachefile: $cachefile\n";
&svn('add', $cachepath . $cachefile);;
}
foreach my $cachefile (@$removed)
{
print "cachepath: $cachepath, cachefile: $cachefile\n";
&svn('remove', $cachepath . $cachefile);;
}
}
&svn('ci', '--message="ImplSearchBot run"', $cachepath);
&svn('update', $cachepath);
}
sub svn
{
my @args = @_;
my $string = "system 'svn'";
$string .= ", '$_'"
foreach (@args);
$string .= "\n";
&out($string, 2);
system 'svn', @args
if(exists $options{'post'});
}
</lang>
|