--- /dev/null
+#!/usr/bin/perl -w
+
+# perl -I ../lib irspy-rewrite-records.pl localhost:8018/IR-Explain---1
+
+use strict;
+use warnings;
+use ZOOM::IRSpy;
+use ZOOM::IRSpy::Utils qw(render_record);
+
+my($dbname) = @ARGV;
+die "$0 no database name specified" if !defined $dbname;
+my $spy = new ZOOM::IRSpy($dbname, "admin", "fruitbat");
+my $rs = $spy->{conn}->search(new ZOOM::Query::CQL("cql.allRecords=1"));
+print STDERR "rewriting ", $rs->size(), " target records";
+
+foreach my $i (1 .. $rs->size()) {
+ my $xml = render_record($rs, $i-1, "zeerex");
+ my $rec = $spy->{libxml}->parse_string($xml)->documentElement();
+ ZOOM::IRSpy::_rewrite_zeerex_record($spy->{conn}, $rec);
+ print STDERR ".";
+}
+print STDERR "\nDone\n";
use Getopt::Std;
use ZOOM;
use ZOOM::IRSpy::Utils qw(irspy_xpath_context modify_xml_document);
-use ZOOM::IRSpy; # For _really_rewrite_record()
+use ZOOM::IRSpy; # For _rewrite_zeerex_record()
# This array copied from ../web/htdocs/details/edit.mc
my @fields =
": ", join(", ", map { $_->[2] } @changedFields), "\n");
if ($opts{w}) {
- ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(), $id);
+ ZOOM::IRSpy::_rewrite_zeerex_record($conn, $xc->getContextNode(), $id);
print "Rewrote record '$id'\n";
}
use ZOOM::IRSpy::Stats;
use ZOOM::IRSpy::Utils qw(cql_target render_record
irspy_xpath_context irspy_make_identifier
- irspy_record2identifier);
+ irspy_record2identifier calc_reliability_stats
+ modify_xml_document);
our @ISA = qw();
our $VERSION = '1.02';
sub _irspy_to_zeerex {
my $this = shift();
- my($conn, $save_xml) = @_;
+ my($conn) = @_;
+
+ my $save_xml = $ENV{IRSPY_SAVE_XML};
my $irspy_doc = $conn->record()->{zeerex}->ownerDocument;
if ($save_xml) {
}
-sub _rewrite_record {
+sub _rewrite_irspy_record {
my $this = shift();
my($conn) = @_;
$conn->log("irspy", "rewriting XML record");
- my $rec = $this->_irspy_to_zeerex($conn, $ENV{IRSPY_SAVE_XML});
+ my $rec = $this->_irspy_to_zeerex($conn);
# Since IRSpy can run for a long time between writes back to the
# database, it's quite possible for the server to have closed the
# connection as idle. So re-establish it if necessary.
$this->{conn}->connect($conn->option("host"));
- _really_rewrite_record($this->{conn}, $rec);
+ _rewrite_zeerex_record($this->{conn}, $rec);
$conn->log("irspy", "rewrote XML record");
}
-sub _really_rewrite_record {
+my $_reliabilityField = {
+ reliability => [ reliability => 0,
+ "Calculated reliability of server",
+ "e:serverInfo/e:reliability" ],
+};
+
+sub _rewrite_zeerex_record {
my($conn, $rec, $oldid) = @_;
+ # Add reliability score
+ my $xc = irspy_xpath_context($rec);
+ my($nok, $nall, $percent) = calc_reliability_stats($xc);
+ modify_xml_document($xc, $_reliabilityField, { reliability => $percent });
+
my $p = $conn->package();
$p->option(action => "specialUpdate");
my $xml = $rec->toString();
# This is the expression in the ID-making stylesheet
# ../../zebra/zeerex2id.xsl
- my $xc = irspy_xpath_context($rec);
my $id = irspy_record2identifier($xc);
if (defined $oldid && $id ne $oldid) {
warn "IDs differ (old='$oldid' new='$id')";
}
if (!defined $nextaddr) {
$conn->log("irspy", "has no more tests: removing");
- $this->_rewrite_record($conn);
+ $this->_rewrite_irspy_record($conn);
$conn->option(rewrote_record => 1);
my $newconn = $this->_next_connection();
if (!defined $newconn) {
irspy_identifier2target
modify_xml_document
bib1_access_point
- render_record);
+ render_record
+ calc_reliability_string
+ calc_reliability_stats);
use XML::LibXML;
use XML::LibXML::XPathContext;
}
+# Modifies the XML document for which $xc is an XPath context by
+# inserting or replacing the values specified in the hash %$data. The
+# keys are fieldnames, which are looked up in the register
+# $fieldsByKey to determine, among other things, what their XPath is.
+
sub modify_xml_document {
my($xc, $fieldsByKey, $data) = @_;
}
+sub calc_reliability_string {
+ my($xc) = @_;
+
+ my($nok, $nall, $percent) = calc_reliability_stats($xc);
+ return "[untested]" if $nall == 0;
+ return "$nok/$nall = " . $percent . "%";
+}
+
+
+sub calc_reliability_stats {
+ my($xc) = @_;
+
+ my @allpings = $xc->findnodes("i:status/i:probe");
+ my $nall = @allpings;
+ return (0, 0, 0) if $nall == 0;
+ my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
+ my $nok = @okpings;
+ my $percent = int(100*$nok/$nall);
+ return ($nok, $nall, $percent);
+}
+
+
1;
--- /dev/null
+# This is the configuration that I use on the development machine xeno
+
+<VirtualHost *:80>
+ ServerName x.irspy.indexdata.com
+
+ ErrorLog /var/log/apache2/irspy-error.log
+ CustomLog /var/log/apache2/irspy-access.log combined
+ DocumentRoot /usr/local/src/git/irspy/web/htdocs
+ <FilesMatch "\.(html|css)$">
+ SetHandler perl-script
+ PerlHandler HTML::Mason::ApacheHandler
+ </FilesMatch>
+
+ PerlSetVar MasonArgsMethod mod_perl
+
+ PerlAddVar MasonCompRoot "private => /usr/local/src/git/irspy/web/htdocs"
+ PerlSetVar MasonDataDir /tmp/irspy-mason
+ # IRSpyLibDir is used only to find source for online documentation
+ PerlSetVar IRSpyLibDir /usr/local/src/git/irspy/lib
+ PerlSetEnv PERL5LIB /usr/local/src/git/irspy/lib
+
+ # We need +Parent to make PerlSwitches -I work properly ... don't ask.
+ PerlOptions +Parent
+ PerlSwitches -I/usr/local/src/git/irspy/lib
+
+ <Location /admin>
+ AuthType Basic
+ AuthName "IRSpy Administration"
+ AuthUserFile /usr/local/src/git/irspy/web/conf/htpasswd
+ Require user admin
+ </Location>
+</VirtualHost>
+
irspy_xpath_context irspy_make_identifier
irspy_record2identifier
irspy_identifier2target modify_xml_document
- bib1_access_point);
+ bib1_access_point calc_reliability_string);
</%once>
% $r->content_type("text/html; charset=utf-8");
% my $text = $m->scomp($component, %ARGS);
"e:metaInfo/e:dateModified" ] },
{ dateModified => isodate(time()) });
die "Didn't set dateModified!" if !@x;
- ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(),
+ ZOOM::IRSpy::_rewrite_zeerex_record($conn, $xc->getContextNode(),
$op eq "edit" ? $id : undef);
}
<th>Database Name</th>
<td><input type="text" name="net.path" size="20"/></td>
</tr>
+ <tr>
+ <th>Reliability at least</th>
+ <td><input type="text" name="zeerex.reliabilityAtLeast" size="20"/></td>
+ </tr>
<%doc>
<tr><td colspan="2"> </td></tr>
<tr>
return $url;
}
-# Identical to the same-named function in full.mc
-# So maybe this should go into IRSpy::Utils.pm?
-# Name changed (append 2) to prevent inadvertent clashes in Mason namespace
-#
-sub calc_reliability2 {
- my($xc) = @_;
-
- my @allpings = $xc->findnodes("i:status/i:probe");
- my $nall = @allpings;
- return "[untested]" if $nall == 0;
- my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
- my $nok = @okpings;
- return "$nok/$nall = " . int(100*$nok/$nall) . "%";
-}
-
-
# Just make this once; forge the connection on first use
our $conn = undef;
</%once>
<%perl>
my $xc = irspy_xpath_context($rs->record($i-1));
my $title = $xc->find("e:databaseInfo/e:title") || "[UNTITLED]";
-my $reliability = calc_reliability2($xc);
+my $reliability = calc_reliability_string($xc);
my $host = $xc->find("e:serverInfo/e:host");
my $port = $xc->find("e:serverInfo/e:port");
my $db = $xc->find("e:serverInfo/e:database");
[ "Implementation ID" => "i:status/i:implementationId" ],
[ "Implementation Name" => "i:status/i:implementationName" ],
[ "Implementation Version" => "i:status/i:implementationVersion" ],
- [ "Reliability/reliability" => \&calc_reliability, $xc ],
+ [ "Reliability/reliability" => \&calc_reliability_wrapper, $xc ],
[ "Services" => \&calc_init_options, $xc ],
[ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
[ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
% }
<%perl>
-sub calc_reliability {
+sub calc_reliability_wrapper {
my($id, $xc) = @_;
-
- my @allpings = $xc->findnodes("i:status/i:probe");
- my $nall = @allpings;
- return "[untested]" if $nall == 0;
- my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
- my $nok = @okpings;
- return "$nok/$nall = " . int(100*$nok/$nall) . "%";
+ return calc_reliability_string($xc);
}
sub calc_init_options {
my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1", 0,
user => "admin", password => "fruitbat",
elementSetName => "zeerex");
-ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
+ZOOM::IRSpy::_rewrite_zeerex_record($conn, $xc->getContextNode());
</%perl>
<p>
Upload OK.
records-2007-04-18
records-2007-05-01
records-2008-09-16
+records-2010-04-06
terse.properties
log
+db
zebraidx-2.0 commit
zebrasrv-2.0 -f yazserver.xml
-
--- /dev/null
+These files are the residue of an abandoned port of IRSpy's Zebra
+configuration from the Alvis filter to the DOM filter. We will
+probably return to this at some point.
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<dom xmlns="http://indexdata.com/zebra-2.0">
+ <input>
+ <xmlreader level="0"/>
+ </input>
+ <extract>
+ <xslt stylesheet="zeerex2index.xsl"/>
+ </extract>
+ <retrieve name="zeerex">
+ </retrieve>
+ <retrieve name="zeerexNoAuth">
+ <xslt stylesheet="zeerex2noauth.xsl"/>
+ </retrieve>
+ <retrieve name="id">
+ <xslt stylesheet="zeerex2id.xsl"/>
+ </retrieve>
+ <retrieve name="dc">
+ <xslt stylesheet="zeerex2dc.xsl"/>
+ </retrieve>
+</dom>
--- /dev/null
+# $Id: zebra.cfg,v 1.12 2006-12-19 12:53:16 sondberg Exp $
+
+# Where to look for config files
+profilePath: .:/usr/local/share/idzebra-2.0/tab:/usr/share/idzebra-2.0/tab
+
+# Where to look for loadable zebra modules. Both these path components
+# are necessary, since the former is used when installing from a Debian
+# package and the latter when installing from a CVS build.
+modulePath: /usr/lib/idzebra-2.0/modules
+#modulePath: /usr/local/lib/idzebra-2.0/modules
+
+# store records and record keys internally
+storeData: 1
+storeKeys: 1
+
+# Use the "dom" filter with config file "domfilterconf.xml"
+recordtype.xml: dom.domfilterconf.xml
+
+database: IR-Explain---1
+#database: Default
+
+# where to put registers, and other var content, and how large they may be
+register: db/register:100G
+shadow: db/shadow:100G
+lockdir: db/lock
+keytmpdir: db/tmp
+
+# Permissions for update
+perm.anonymous: ra
+perm.admin: rw
+passwd.c: htpasswd
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:z="http://indexdata.com/zebra-2.0"
+ xmlns:e="http://explain.z3950.org/dtd/2.0/"
+ xmlns:i="http://indexdata.com/irspy/1.0"
+ version="1.0">
+ <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
+ <xsl:template match="text()"/>
+ <xsl:template match="//e:explain">
+ <xsl:variable name="id"><xsl:value-of select="concat(
+ e:serverInfo/@protocol, ':',
+ e:serverInfo/e:host, ':',
+ e:serverInfo/e:port, '/',
+ e:serverInfo/e:database)"/></xsl:variable>
+ <z:record z:id="{$id}" type="update">
+ <z:index name="dc:title:w">
+ <xsl:value-of select="e:databaseInfo/e:title"/>
+ </z:index>
+ </z:record>
+ </xsl:template>
+</xsl:stylesheet>
index.net.host = 1=net:host 4=3
index.net.port = 1=net:port 4=3
index.net.path = 1=net:path 4=3
+index.zeerex.reliability = 1=zeerex:reliability 4=109
+index.zeerex.reliabilityAtLeast = 1=zeerex:reliability 2=4 4=109
index.dc.title = 1=dc:title
index.dc.creator = 1=dc:creator
index.dc.description = 1=dc:description
<z:index name="net:path" type="s">
<xsl:value-of select="e:serverInfo/e:database"/>
</z:index>
+ <z:index name="zeerex:reliability" type="n">
+ <xsl:value-of select="e:serverInfo/e:reliability"/>
+ </z:index>
<z:index name="dc:date" type="d">
<xsl:value-of select="e:serverInfo/e:database/@lastUpdate"/>
</z:index>