modifybatchpurls.pl revision cbc7f7ea90538f481b528959e9b6cf837b0dd785
#use strict;
############################################################
#
# David Wood (david.wood@talis.com)
# January 2011
#
# Script to modify PURLs in a PURLz v1.x server. PURLs are described in
# the same XML format used by sendbatchpurls.pl.
#
# Copyright 2011 Talis Inc. Licensed under the Apache License,
# Version 2.0 (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
# or agreed to in writing, software distributed under the License is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
###########################################################
package PURLz;
###########################################
my $userid = 'admin';
my $passwd = 'password';
my $directory = "batch_files";
###########################################
my $workurl = "http://$server/admin/purl";
my $cookiefile = 'lwpcookies.txt';
my $useoldfile = 0;
my $debug = 0;
# set up user agent with a cookie jar
my $res;
my $req;
file => $cookiefile,
autosave => 1,
ignore_discard => 1,
);
print STDERR "no old cookie jar file, so asking for new authorization\n"
if ($useoldfile && ! -e $cookiefile);
print STDERR "set up cookie jar\n";
unless ($useoldfile && -e $cookiefile) {
# try the authorization call, saving the cookie
referrer => '/docs/index.html',
]);
print STDERR "make auth request\n";
print STDERR "save cookie jar file\n";
$cookie_jar->save();
}
print STDERR "load cookie jar from the file\n";
$cookie_jar->load();
# Open log file.
# Get the contents of each file in the directory.
# Get content from file
local $/=undef;
binmode FILE;
# parse PURLs from the file;
# DBG
print "$purl\n\n" if $debug;
my $params;
$purlid = $1;
$params .= "type=$2&maintainers=";
my $maints = $1;
$params .= "$1,";
}
$params .= "$1,";
}
}
$params .= "&";
}
$params =~ s/,&/&/;
$params =~ s/&$//;
} else {
# Regexp failed to match. Either a bad XML entry or the tail end of the file.
next;
}
# DBG
if ( $debug ) {
}
# Report results.
print "$purlid OK\n";
print LOG "$purlid OK\n";
} else {
print "\nERROR: $purlid: $report\n\n";
print LOG "\nERROR: $purlid: $report\n\n";
}
}
close FILE;
}
close(LOG);