Bugzilla – Attachment 60732 Details for
Bug 12836
Add a script to regenerate Explain files from configs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12836 - Add script to rewrite SRU Explain file
Bug-12836---Add-script-to-rewrite-SRU-Explain-file.patch (text/plain), 18.97 KB, created by
Magnus Enger
on 2017-02-28 15:07:01 UTC
(
hide
)
Description:
Bug 12836 - Add script to rewrite SRU Explain file
Filename:
MIME Type:
Creator:
Magnus Enger
Created:
2017-02-28 15:07:01 UTC
Size:
18.97 KB
patch
obsolete
>From 3f418ee278753d31523d98fd78d6d8a6a8afed18 Mon Sep 17 00:00:00 2001 >From: Magnus Enger <magnus@libriotech.no> >Date: Tue, 28 Feb 2017 13:12:28 +0000 >Subject: [PATCH] Bug 12836 - Add script to rewrite SRU Explain file > >The standard SRU Explain file provided with Koha is static and out of >date. This patch adds a script in misc/maintenance/generate_explain.pl >that can generate a new Explain file, based on Koha's config files and >an optional extra config file. See the POD in the script for more >details. > >This is a preview, NOT READY FOR SIGNOFF. >--- > .../prog/en/modules/services/explain-biblios.tt | 239 ++++++++++++++++ > misc/maintenance/generate_explain.pl | 302 +++++++++++++++++++++ > 2 files changed, 541 insertions(+) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/services/explain-biblios.tt > create mode 100644 misc/maintenance/generate_explain.pl > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/services/explain-biblios.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/services/explain-biblios.tt >new file mode 100644 >index 0000000..ab02651 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/services/explain-biblios.tt >@@ -0,0 +1,239 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+ >+[%- USE Koha -%] >+[%- USE date( format = '%Y-%m-%d %H:%M:%S' ) -%] >+ >+<!-- this file configures the SRU/SRW explain response --> >+<!-- see: http://explain.z3950.org/dtd/commentary.html --> >+<!-- validate this using zeerex-2.0.xsd --> >+<!-- Extensions see: http://explain.z3950.org/dtd/extensions.html --> >+ >+<explain xmlns="http://explain.z3950.org/dtd/2.0/"> >+ >+ <serverInfo protocol="[% IF ( config.protocol ) %][% config.protocol %][% ELSE %]SRW/SRU/Z39.50[% END %]" >+ version="2.0" >+ transport="[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]"> >+ <host>[% host %]</host> >+ <port>[% port %]</port> >+ <database>biblios</database> >+ </serverInfo> >+ >+ <databaseInfo> >+ >+ [% IF ( config.title ) -%] >+ [%- FOREACH title IN config.title -%] >+ <title lang="[% title.lang %]"[% IF ( title.primary ) %] primary="true"[% END %]>[% title.text %]</title> >+ [% END -%] >+ [% ELSE -%] >+ <title lang="en" primary="true">Koha Bibliographic SRU/SRW/Z39.50 server</title> >+ [% END -%] >+ >+ [%- IF ( config.description ) -%] >+ [%- FOREACH description IN config.description -%] >+ <description lang="[% description.lang %]"[% IF ( description.primary ) %] primary="true"[% END %]>[% description.text %]</description> >+ [% END -%] >+ [% ELSE -%] >+ <description lang="en" primary="true">Koha Bibliographic Server</description> >+ [% END -%] >+ >+ <author> >+ [%- IF ( config.author ) -%] >+ [%- config.author -%] >+ [%- ELSIF ( Koha.Preference( 'LibraryName' ) != '' ) -%] >+ [% Koha.Preference( 'LibraryName' ) -%] >+ [%- ELSE -%] >+ Koha >+ [%- END -%]</author> >+ >+ <contact> >+ [%- IF ( config.contact ) -%] >+ [%- config.contact -%] >+ [%- ELSIF ( Koha.Preference( 'KohaAdminEmailAddress' ) != '' ) -%] >+ [%- Koha.Preference( 'KohaAdminEmailAddress' ) -%] >+ [%- END -%]</contact> >+ >+ [% IF ( config.extent ) -%] >+ [%- FOREACH extent IN config.extent -%] >+ <extent lang="[% extent.lang %]"[% IF ( extent.primary ) %] primary="true"[% END %]>[% extent.text %]</extent> >+ [% END -%] >+ [% END -%] >+ >+ [% IF ( config.history ) -%] >+ [%- FOREACH history IN config.history -%] >+ <history lang="[% history.lang %]"[% IF ( history.primary ) %] primary="true"[% END %]>[% history.text %]</history> >+ [% END -%] >+ [% END -%] >+ >+ [% IF ( config.langUsage ) %] >+ [% FOREACH lang IN config.langUsage %] >+ <langUsage lang="[% lang.lang %]"[% IF ( lang.primary ) %] primary="true"[% END %][% IF ( lang.codes ) %] codes="[% lang.codes %]"[% END %]>[% lang.text %]</langUsage> >+ [% END %] >+ [% END %] >+ >+ [% IF ( config.restrictions ) -%] >+ [%- FOREACH restriction IN config.restrictions -%] >+ <restrictions lang="[% restriction.lang %]"[% IF ( restriction.primary ) %] primary="true"[% END %]>[% restriction.text %]</restrictions> >+ [% END -%] >+ [% END -%] >+ >+ [% IF ( config.subjects ) -%] >+ <subjects> >+ [% FOREACH sub IN config.subjects -%] >+ <subject>[% sub %]</subject> >+ [% END -%] >+ </subjects> >+ [% END %] >+ >+ <implementation identifier="zebra" version="2.0"> >+ <title>Index Data YAZ/ZEBRA http://www.indexdata.dk/zebra</title> >+ </implementation> >+ >+ <links> >+ [% IF ( Koha.Preference( 'OPACBaseURL' ) ) %]<link type="www">[% Koha.Preference( 'OPACBaseURL' ) %]/</link>[% END %] >+ <link type="z39.50">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link> >+ <link type="srw">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link> >+ <link type="sru">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link> >+ [% IF ( Koha.Preference( 'OAI-PMH' ) ) %]<link type="oai">[% Koha.Preference( 'OPACBaseURL' ) %]/cgi-bin/koha/oai.pl</link>[% END %] >+ [% IF ( Koha.Preference( 'OpacFavicon' ) ) %]<link type="icon">[% Koha.Preference( 'OpacFavicon' ) %]</link>[% END %] >+ </links> >+ >+ </databaseInfo> >+ >+ <metaInfo> >+ <dateModified>[% date.format %]</dateModified> >+ </metaInfo> >+ >+ <indexInfo> >+ >+ [% FOREACH set IN pqf.sets -%] >+ <set identifier="[% set.identifier %]" name="[% set.name %]"/> >+ [% END -%] >+ >+ [% FOREACH index IN pqf.indexes %] >+ <index search="true" scan="true" sort="false"> >+ [%- IF config.indexnames.${index.id} -%] >+ [%- FOREACH this IN config.indexnames.${index.id} %] >+ <title lang="[% this.lang %]">[% this.title %]</title> >+ [%- END %] >+ [%- END %] >+ <map><name set="[% index.set %]">[% index.index %]</name></map> >+ <map primary="true"> >+ <attr type="[% index.type %]">[% index.value %]</attr> >+ </map> >+ </index> >+ [% END -%] >+ >+ </indexInfo> >+ >+ <configInfo> >+ >+ <!-- searchRetrieve settings --> >+ >+ <!-- default context set --> >+ <default type="contextSet">cql</default> >+ >+ <default type="index">all</default> >+ >+ <!-- default relation --> >+ <default type="relation">=</default> >+ >+ <!-- relation supported by the server or index --> >+ <supports type="relation"><</supports> <!-- 2=1 OK --> >+ <supports type="relation"><=</supports> <!-- 2=2 OK --> >+ <supports type="relation">=</supports> <!-- 2=3 OK --> >+ <supports type="relation">>=</supports> <!-- 2=4 OK --> >+ <supports type="relation">></supports> <!-- 2=5 OK --> >+ <!-- <supports type="relation"><></supports> --><!-- 2=6 DEAD !!! --> >+ <!-- <supports type="relation">all</supports> --><!-- 2=3 OK --> >+ <!-- <supports type="relation">any</supports> --><!-- 2=3 OK --> >+ >+ <!-- relation modifier supported by the server or index --> >+ <!-- <supports type="relationModifier">relevant</supports> --><!-- 2=102 OK, makes no difference .. sic --> >+ <!-- <supports type="relationModifier">phonetic</supports> --> <!-- 2=100 DEAD --> >+ <!-- <supports type="relationModifier">stem</supports> --> <!-- 2=101 DEAD !! --> >+ >+ <!-- support proximity (Empty) --> >+ <!-- <supports type="proximity"></supports> --> <!-- DEAD, title = (house prox/distance=1/unit=word the) FAILS --> >+ >+ <!-- proximity modifier supported by the server or index >+ (relation, distance, unit, ordering) --> >+ <!-- <supports type="proximityModifier"></supports> --> >+ >+ <!-- boolean modifier supported by the server or index --> >+ <!-- <supports type="booleanModifier"></supports> --> >+ >+ <!-- masking character supported (* or ?) --> >+ <supports type="maskingCharacter">*</supports> >+ <supports type="maskingCharacter">?</supports> >+ >+ <!-- anchoring supported? (^ character) --> >+ <!-- empty terms supported (Empty) --> >+ <supports type="emptyTerm"></supports> >+ >+ <!-- sorting settings --> >+ >+ <!-- default schema used in sorting, in short name form --> >+ <!-- <default type="sortSchema"></default> --> >+ <!-- MIKE: deprecated --> >+ >+ <!-- server support sort --> >+ >+ <!-- supported sortmodifier (ascending, missingValue, caseSensitive) --> >+ <!-- <supports type="sortModifier"></supports> --> >+ >+ <!-- presentation settings --> >+ >+ <!-- default number of records that a server will return at once --> >+ <default type="numberOfRecords">0</default> >+ >+ <!-- default schema used for retrieved records --> >+ <default type="retrieveSchema">index</default> >+ <!-- default stylesheet URL, or if stylesheets are supported --> >+ <setting type="stylesheet">docpath/sru.xsl</setting> >+ >+ <!-- default record packing returned (string or xml) --> >+ <default type="recordPacking">xml</default> >+ >+ <!-- maximum number of records that a server will return at once --> >+ <!-- <setting type="maximumRecords">1000</setting> --> >+ >+ <!-- support result sets (Empty) --> >+ <!-- <supports type="resultSets"></supports> --> >+ >+ <!-- XPath retrieval supported --> >+ <!-- <supports type="recordXPath"></supports> --> >+ >+ <!-- scan settings --> >+ >+ <!-- scan operation supported --> >+ <supports type="scan"></supports> >+ >+ <!-- default number of terms to be returned in scan --> >+ <default type="numberOfTerms">20</default> >+ >+ <!-- other server settings --> >+ >+ <!-- older version of the protocol supported --> >+ <!-- <supports type="version">1.1</supports> --> >+ >+ <!-- number of seconds that a result set will be maintained for --> >+ <setting type="resultSetTTL">0</setting> >+ >+ <!-- A type of extraRequestData available in the >+ searchRetrieveRequest. The extra*Data fields are represented as two >+ space separated words, the first the identifier for the extension and >+ the second the individual element name from the extension. If there is >+ only one word, then it is the extension id and all elements from >+ within are supported. --> >+ <!-- <supports type="extraSearchData"></supports> --> >+ >+ <!-- A type of extraRequestData available in the explainRequest --> >+ <!-- <supports type="extraExplainData"></supports> --> >+ >+ <!-- A type of extraRequestData available in the scanRequest --> >+ <!-- <supports type="extraScanData"></supports> --> >+ <!-- The URI identifier of a supported profile --> >+ <!-- <supports type="profile"></supports> --> >+ </configInfo> >+ >+</explain> >diff --git a/misc/maintenance/generate_explain.pl b/misc/maintenance/generate_explain.pl >new file mode 100644 >index 0000000..d0cb5d8 >--- /dev/null >+++ b/misc/maintenance/generate_explain.pl >@@ -0,0 +1,302 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 Magnus Enger Libriotech >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+generate_explain.pl >+ >+=head1 SYNOPSIS >+ >+sudo koha-shell -c "perl generate_explain.pl -v" mykoha >+ >+sudo PERL5LIB=/usr/share/koha/lib KOHA_CONF=/etc/koha/sites/kohadev/koha-conf.xml perl generate_explain.pl -c /path/to/explain.yaml --overwrite -v >+ >+=head1 DESCRIPTION >+ >+Reads an optional config file, some of Koha's config files and generates an >+Explain document that can be served by the Zebra SRU server. >+ >+By default, the generated Explain document will be written to STDOUT. Specify >+the --overwrite command line option to actually overwrite the existing Explain >+document. >+ >+=cut >+ >+use File::Slurp; >+use YAML::Syck qw( LoadFile ); >+use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy >+use XML::Simple; >+use Modern::Perl; >+use Getopt::Long; >+use Pod::Usage; >+use Data::Dumper; # Debug >+ >+use C4::Context; >+use C4::Templates; >+ >+=head1 OPTIONS >+ >+=over 8 >+ >+=item B<-c | --configfile> >+ >+Path to a configfile that should be used to generate parts of the Explain >+document. >+ >+=item B<--overwrite> >+ >+Actually overwrite the existing explain document. If this is not specified, the >+generated Explain document will be written to STDOUT and no files will be >+overwritten. >+ >+=item B<-h | --help> >+ >+Print this usage statement. >+ >+=item B<-v | --verbose> >+ >+More verbose output. >+ >+=back >+ >+=cut >+ >+my ( $configfile, $overwrite, $help, $verbose ); >+GetOptions( >+ 'c|configfile=s' => \$configfile, >+ 'o|overwrite' => \$overwrite, >+ 'h|help' => \$help, >+ 'v|verbose' => \$verbose, >+); >+ >+if ( $help ) { >+ pod2usage( -verbose => 2 ); >+ exit; >+} >+ >+=head1 CONFIG FILE >+ >+The config file should be in YAML format. Here is an example config that shows >+all the available options. See http://zeerex.z3950.org/dtd/commentary.html for >+further details about the options. >+ >+ --- >+ # Protocol >+ # Default: SRW/SRU/Z39.50 >+ protocol: "SRU" >+ >+ # Transport >+ # Default: http >+ transport: "https" >+ >+ # Title >+ # Should have a two letter language code. >+ # One title can be marked as primary >+ title: >+ - text: This is some title >+ lang: en >+ primary: true >+ - text: Dette er en tittel >+ lang: nb >+ >+ # Description >+ # Should have a two letter language code. >+ # One description can be marked as primary >+ description: >+ - text: This is some description >+ lang: en >+ primary: true >+ - text: Dette er en beskrivelse >+ lang: nb >+ >+ # Author >+ # If author is not set in the config, the LibraryName syspref will be used. If >+ # that is not set, the string "Koha" will be used. >+ author: "The librarian" >+ >+ # Contact >+ # If the contact is not set in the config, the KohaAdminEmailAddress syspref >+ # will be used. >+ contact: "librarian@example.org" >+ >+ # Extent >+ extent: >+ - text: "This is the extent of the database." >+ lang: "en" >+ primary: "true" >+ >+ # History >+ history: >+ - text: "This is the history of the database." >+ lang: "en" >+ primary: "true" >+ >+ # langUsage >+ langUsage: >+ - text: "Records are in English and Norwegian" >+ codes: "en nb" >+ lang: "en" >+ primary: "true" >+ >+ # Restrictions >+ restrictions: >+ - text: "Free for all!" >+ lang: "en" >+ primary: "true" >+ >+ # Subjects >+ subjects: >+ - "Subject A" >+ - "Subject B" >+ >+ # Index names >+ # Indexes can be given more explanatory names, but this is optional. >+ indexnames: >+ dc_title: >+ - title: "Title" >+ lang: "en" >+ - title: "Tittel" >+ lang: "nb" >+ dc_subject: >+ - title: "Subject" >+ lang: "en" >+ rec_identifier: >+ - title: "Record identifier" >+ lang: "en" >+ >+=cut >+ >+# Load the config file, if one is specified >+my $config; >+if ( $configfile ) { >+ if ( -e $configfile ) { >+ say "Reading config from $configfile" if $verbose; >+ $config = LoadFile( $configfile ); >+ } else { >+ die "$configfile not found"; >+ } >+} >+ >+# Get the path to he Koha config file from the KOHA_CONF environment variable >+my $koha_conf = $ENV{ 'KOHA_CONF' }; >+say "Looking at $koha_conf" if $verbose; >+ >+# Read the Koha config file >+my $conf = XMLin( >+ $koha_conf, >+ keyattr => ['id'], >+ forcearray => ['listen', 'server', 'serverinfo'], >+ suppressempty => '' >+); >+ >+# Get the SRU host and port from the Koha config file >+my $publicserver = $conf->{'listen'}->{'publicserver'}->{'content'}; >+my ( $tcp, $host, $port ) = split /:/, $publicserver; >+say "SRU is listening on port $port" if $verbose; >+ >+# Find the path to pqf.properties file >+my $pqf_properties_file = $conf->{'server'}->{'publicserver'}->{'cql2rpn'}; >+say "Looking at $pqf_properties_file" if $verbose; >+ >+# Read the pqf.properties file, and extract the information we need >+my %pqf; >+my @lines = read_file( $pqf_properties_file ); >+foreach my $line ( @lines ) { >+ >+ # Remove trailing whitespace >+ chomp $line; >+ # Skip commented lines - start of line, zero or more spaces, comment sign >+ next if $line =~ m/^ {0,}#/; >+ # Skip empty lines - start of line, zero or more spaces, end of line >+ next if $line =~ m/^ {0,}$/; >+ >+ # Look for lines that start with "set." >+ if ( $line =~ m/^set\.(.*?) {0,}= {0,}(.*)/ ) { >+ push @{ $pqf{'sets'} }, { >+ 'name' => $1, >+ 'identifier' => $2, >+ }; >+ } >+ >+ # Look for lines that start with "index." >+ if ( $line =~ m/^index\.(.*?)\.(.*?) {0,}= (.*?)=(.*?) {0,}$/ ) { >+ push @{ $pqf{'indexes'} }, { >+ 'set' => $1, >+ 'index' => $2, >+ 'id' => "$1_$2", >+ 'type' => $3, >+ 'value' => $4, >+ }; >+ } >+ >+} >+ >+# Set up the template >+my $template = C4::Templates::gettemplate( >+ 'services/explain-biblios.tt', >+ 'intranet', >+ new CGI >+); >+ >+# Pass some values to the template >+$template->param( >+ 'config' => $config, >+ 'pqf' => \%pqf, >+ 'host' => $host, >+ 'port' => $port, >+); >+ >+# Get the output from the template >+my $output = $template->output; >+if ( $overwrite ) { >+ # Find the path to the Explain doc >+ my $explain_doc; >+ foreach my $inc ( @{ $conf->{'server'}->{'publicserver'}->{'xi:include'} } ) { >+ my $href = $inc->{'href'}; >+ if ( $href =~ m/explain/ ) { >+ $explain_doc = $href; >+ } >+ } >+ say "Going to write to $explain_doc" if $verbose; >+ # Make a backup of the existing file >+ rename $explain_doc, "$explain_doc-old"; >+ # Do the actual write >+ write_file( $explain_doc, $output ); >+} else { >+ say $output; >+} >+ >+=head1 AUTHOR >+ >+Magnus Enger, <magnus [at] libriotech.no> >+ >+=head1 LICENSE >+ >+ This program is free software: you can redistribute it and/or modify >+ it under the terms of the GNU General Public License as published by >+ the Free Software Foundation, either version 3 of the License, or >+ (at your option) any later version. >+ This program is distributed in the hope that it will be useful, >+ but WITHOUT ANY WARRANTY; without even the implied warranty of >+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+ GNU General Public License for more details. >+ You should have received a copy of the GNU General Public License >+ along with this program. If not, see <http://www.gnu.org/licenses/>. >+ >+=cut >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12836
:
60732
|
60791