From 0307dcaea9ec7c1d3e9af5951020f9a4781834b4 Mon Sep 17 00:00:00 2001 From: Alexey Zelkin <phantom@FreeBSD.org> Date: Sat, 1 Sep 2001 14:52:30 +0000 Subject: [PATCH] add two helper scirpts which are dedicated to simplify task of maintaince of the gallery entries. I have wrote these ones just right now, because I lost previous versions due to HDD crash, therefore comments on them are welcome. --- en/gallery/fixurls.pl | 54 ++++++++++++++++++++++++++++++++++++++++ en/gallery/merge-mbox.sh | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100755 en/gallery/fixurls.pl create mode 100755 en/gallery/merge-mbox.sh diff --git a/en/gallery/fixurls.pl b/en/gallery/fixurls.pl new file mode 100755 index 0000000000..e4dd3ae804 --- /dev/null +++ b/en/gallery/fixurls.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# This script is dedicated to check existing gallery XML file. +# Check its URLs for duplicates and fixup incorrectly submitted ones. +# +# History: +# 31082001 Alexey Zelkin Initial version +# +# Usage: +# fixurls.pl gallery.xml output.xml +# +# $FreeBSD$ + +if (-f $ARGV[0]) { + $src = $ARGV[0]; +} else { + die "Could not open source file!" +} + +if ($ARGV[1] eq "") { + die "Could not open output file!" +} else { + $dst = $ARGV[1]; +} + +open (SRC, $src); +open (DST, ">$dst"); + +while (<SRC>) { + if ($_ =~ /\<url\>.*\<\/url\>/) { + chomp; + s/.*url\>(.*)\<\/url.*/$1/; + next if ($_ eq ""); + # add "http://" at the begining of the url unless it (or any + # other (like "ftp://") protocol is already specified + $_ = "http://" . $_ unless (m/^[a-z]*:\/\/.*$/); + if (defined $hhash{$_}) { + $hhash{$_}++; + } else { + $hhash{$_} = 1; + } + print DST " <url>$_</url>\n"; + } else { + print DST $_; + } +} + +close (SRC); +close (DST); + +print "Duplicated URLs:\n"; +foreach $key (sort keys %hhash) { + print "$hhash{$key}: $key\n" if ($hhash{$key} > 1); +} diff --git a/en/gallery/merge-mbox.sh b/en/gallery/merge-mbox.sh new file mode 100755 index 0000000000..fea393a244 --- /dev/null +++ b/en/gallery/merge-mbox.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script is dedicated to help gallery maintainer to parse source +# mailbox which contains letters submitted by +# http://www.FreeBSD.org/cgi/gallery.cgi and merge parsed information into +# existing gallery.xml file. +# +# History: +# 31082001 Alexey Zelkin Initial version +# +# Usage: +# merge-mbox.sh src.mbox output.xml +# +# $FreeBSD$ + +# source file +if ! [ -f "$1" ]; then + echo "Could not open source mbox!" + exit 1 +fi + +# destination file (copy of gallery.xml plus new items) +if [ "$2" = "" ]; then + echo "You must specify output file name!" + exit 1 +fi + +# cleanup mailbox +/usr/bin/egrep "^[commercial,nonprofit,personal]" $1 | /usr/bin/uniq | /usr/bin/sort > TMP.mbox + +# make a copy of gallery.xml except closing </gallery> tag +/usr/bin/grep -v "^<\/gallery>$" gallery.xml > $2 + +# add XMLized new items +awk -F'\t' '{ \ + print " <entry type=\""$1"\">"; \ + print " <name>"$2"</name>"; \ + print " <url>"$3"</url>"; \ + print " <descr>"$4"</descr>"; \ + print " <email>"$5"</email>"; \ + print " </entry>"; \ + print ""; \ +}' TMP.mbox >> $2 + +# add closing XML tag +echo "</gallery>" >> $2 + +# fixup URLs +mv $2 $2.tmp +/usr/bin/perl fixurls.pl $2.tmp $2 + +# cleanup +rm $2.tmp +rm TMP.mbox