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.
This commit is contained in:
Alexey Zelkin 2001-09-01 14:52:30 +00:00
parent aaf034986b
commit 0307dcaea9
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/www/; revision=10524
2 changed files with 108 additions and 0 deletions

54
en/gallery/fixurls.pl Executable file
View file

@ -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);
}

54
en/gallery/merge-mbox.sh Executable file
View file

@ -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