From 9e10edb996b206d531caa5f929a117cefb790355 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 10 Jul 2002 16:22:49 +0000 Subject: Changed thesaurus filenames from nn-foo to nn.foo Moved save_thesaurus() from Conf.pm to Thesaurus.pm --- Echolot/Conf.pm | 32 ++++++------------------------ Echolot/Thesaurus.pm | 24 +++++++++++++++++++++-- NEWS | 6 ++++++ tools/change-thesaurus-filenames | 42 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 28 deletions(-) create mode 100755 tools/change-thesaurus-filenames diff --git a/Echolot/Conf.pm b/Echolot/Conf.pm index d240e84..0e669eb 100644 --- a/Echolot/Conf.pm +++ b/Echolot/Conf.pm @@ -1,7 +1,7 @@ package Echolot::Conf; # (c) 2002 Peter Palfrader -# $Id: Conf.pm,v 1.14 2002/07/07 01:12:00 weasel Exp $ +# $Id: Conf.pm,v 1.15 2002/07/10 16:22:49 weasel Exp $ # =pod @@ -24,26 +24,6 @@ use GnuPG::Interface; use IO::Handle; -sub save_thesaurus($$$) { - my ($otype, $oid, $data) = @_; - - return 1 unless Echolot::Config::get()->{'thesaurus'}; - - my ($type) = $otype =~ /^([a-z-]+)$/; - cluck("type '$otype' is not clean in save_thesaurus"), return 0 unless defined $type; - my ($id) = $oid =~ /^([0-9]+)$/; - cluck("id '$oid' is not clean in save_thesaurus"), return 0 unless defined $id; - - my $file = Echolot::Config::get()->{'thesaurusdir'}.'/'.$id.'-'.$type; - open (F, ">$file") or - cluck ("Cannot open '$file': $!"), - return 0; - print F $data; - close (F); - - return 1; -}; - sub send_requests() { Echolot::Globals::get()->{'storage'}->delay_commit(); for my $remailer (Echolot::Globals::get()->{'storage'}->get_addresses()) { @@ -169,7 +149,7 @@ sub remailer_conf($$$) { cluck ("Returned token '$token' has no id at all"), return 0; - save_thesaurus('conf', $id, $reply); + Echolot::Thesaurus::save_thesaurus('conf', $id, $reply); remailer_caps($reply, $token, $time); }; @@ -386,7 +366,7 @@ sub remailer_key($$$) { cluck ("Returned token '$token' has no id at all"), return 0; - save_thesaurus('key', $id, $reply); + Echolot::Thesaurus::save_thesaurus('key', $id, $reply); my $remailer = Echolot::Globals::get()->{'storage'}->get_address_by_id($id); cluck("No remailer found for id '$id'"), return 0 unless defined $remailer; @@ -405,7 +385,7 @@ sub remailer_stats($$$) { cluck ("Returned token '$token' has no id at all"), return 0; - save_thesaurus('stats', $id, $reply); + Echolot::Thesaurus::save_thesaurus('stats', $id, $reply); }; sub remailer_help($$$) { @@ -416,7 +396,7 @@ sub remailer_help($$$) { cluck ("Returned token '$token' has no id at all"), return 0; - save_thesaurus('help', $id, $reply); + Echolot::Thesaurus::save_thesaurus('help', $id, $reply); }; sub remailer_adminkey($$$) { @@ -427,7 +407,7 @@ sub remailer_adminkey($$$) { cluck ("Returned token '$token' has no id at all"), return 0; - save_thesaurus('adminkey', $id, $reply); + Echolot::Thesaurus::save_thesaurus('adminkey', $id, $reply); }; 1; diff --git a/Echolot/Thesaurus.pm b/Echolot/Thesaurus.pm index ba68a69..be97446 100644 --- a/Echolot/Thesaurus.pm +++ b/Echolot/Thesaurus.pm @@ -1,7 +1,7 @@ package Echolot::Thesaurus; # (c) 2002 Peter Palfrader -# $Id: Thesaurus.pm,v 1.5 2002/07/07 01:12:00 weasel Exp $ +# $Id: Thesaurus.pm,v 1.6 2002/07/10 16:22:49 weasel Exp $ # =pod @@ -23,6 +23,26 @@ use English; use HTML::Template; +sub save_thesaurus($$$) { + my ($otype, $oid, $data) = @_; + + return 1 unless Echolot::Config::get()->{'thesaurus'}; + + my ($type) = $otype =~ /^([a-z-]+)$/; + cluck("type '$otype' is not clean in save_thesaurus"), return 0 unless defined $type; + my ($id) = $oid =~ /^([0-9]+)$/; + cluck("id '$oid' is not clean in save_thesaurus"), return 0 unless defined $id; + + my $file = Echolot::Config::get()->{'thesaurusdir'}.'/'.$id.'.'.$type; + open (F, ">$file") or + cluck ("Cannot open '$file': $!"), + return 0; + print F $data; + close (F); + + return 1; +}; + sub build_thesaurus() { return 1 unless Echolot::Config::get()->{'thesaurus'}; @@ -38,7 +58,7 @@ sub build_thesaurus() { my $data; for my $filename (@files) { - my ($id, $what) = $filename =~ /^(\d+)-(adminkey|conf|help|key|stats)$/; + my ($id, $what) = $filename =~ /^(\d+)\.(adminkey|conf|help|key|stats)$/; next unless (defined $id && defined $what); my $remailer = Echolot::Globals::get()->{'storage'}->get_address_by_id($id); diff --git a/NEWS b/NEWS index 53978fe..fdb0240 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +Changes in + * Thesaurus filenames changed from nn-foo to nn.foo. + Use the change-thesaurus-filenames script in the tools + directory to convert your current thesaurus if you wish + to keep the data. + Changes in version 2.0 beta4 - 2002-07-10 * Minor documentation fixes * Added --process switch diff --git a/tools/change-thesaurus-filenames b/tools/change-thesaurus-filenames new file mode 100755 index 0000000..735791d --- /dev/null +++ b/tools/change-thesaurus-filenames @@ -0,0 +1,42 @@ +#! /bin/sh + +# In 2.0beta4 files in the Thesaurus were named -. E.g: 25-adminkey +# 2.0beta5 uses dots now instead of dashes: 25.adminkey + +# This script reads renames files in the Thesaurus + +# It is assumed that the largest id in use is 999 + +set -e + +FILES=`ls [0-9]-conf [0-9]-key [0-9]-stats [0-9]-help [0-9]-adminkey [0-9][0-9]-conf \ + [0-9][0-9]-key [0-9][0-9]-stats [0-9][0-9]-help [0-9][0-9]-adminkey \ + [0-9][0-9][0-9]-key [0-9][0-9][0-9]-stats [0-9][0-9][0-9]-help [0-9][0-9][0-9]-adminkey 2>/dev/null` || true + +if [ -z "$FILES" -a -d "results/thesaurus/" ]; then + echo Changing to directory results/thesaurus/ + cd results/thesaurus/ + FILES=`ls [0-9]-conf [0-9]-key [0-9]-stats [0-9]-help [0-9]-adminkey [0-9][0-9]-conf \ + [0-9][0-9]-key [0-9][0-9]-stats [0-9][0-9]-help [0-9][0-9]-adminkey \ + [0-9][0-9][0-9]-key [0-9][0-9][0-9]-stats [0-9][0-9][0-9]-help [0-9][0-9][0-9]-adminkey 2>/dev/null` || true +fi +if [ -z "$FILES" -a -d "thesaurus/" ]; then + echo Changing to directory thesaurus/ + cd results/thesaurus/ + FILES=`ls [0-9]-conf [0-9]-key [0-9]-stats [0-9]-help [0-9]-adminkey [0-9][0-9]-conf \ + [0-9][0-9]-key [0-9][0-9]-stats [0-9][0-9]-help [0-9][0-9]-adminkey \ + [0-9][0-9][0-9]-key [0-9][0-9][0-9]-stats [0-9][0-9][0-9]-help [0-9][0-9][0-9]-adminkey 2>/dev/null` || true +fi + +if [ -z "$FILES" ]; then + echo "Could not find any old style filenames in '.', 'results/thesaurus/', or 'thesaurus/'" >&2 + exit 1 +fi + +echo "Renaming files..." +for file in $FILES ; do + mv $file `echo $file | tr '-' '.'` +done + +echo "done." +echo "The next buildthesaurus run (per default every hour) will fix the index file" -- cgit v1.2.3