[subversion-commit] SVN tetex-base commit + diffs: r1417 -
tetex-base/trunk/debian
Frank Küster
frank at costa.debian.org
Thu Jun 8 17:20:28 UTC 2006
Author: frank
Date: 2006-06-08 17:20:26 +0000 (Thu, 08 Jun 2006)
New Revision: 1417
Modified:
tetex-base/trunk/debian/searchbase35
Log:
rewrote searchbase35 in Perl
Modified: tetex-base/trunk/debian/searchbase35
===================================================================
--- tetex-base/trunk/debian/searchbase35 2006-06-06 14:11:02 UTC (rev 1416)
+++ tetex-base/trunk/debian/searchbase35 2006-06-08 17:20:26 UTC (rev 1417)
@@ -1,76 +1,220 @@
-#!/bin/bash
+#!/usr/bin/perl
-package=$1
-outfile=$2
+use strict;
+use warnings;
-shift 2
-otherlocations="$@"
+# customization
+my @psnfssArchives = ("lw35nfss","freenfss");
+my @otherArchivesZip = ("ly1-min");
+my @otherArchivesTar = ("cspsfonts");
+my $lw35nfss_archive = "/home/frank/area/lw35nfss.zip";
+my $freenfss_archive = "/home/frank/area/freenfss.zip";
+my $cspsfonts_archive = "/home/frank/area/cspsfonts.tar.gz";
+my $ly1min_archive = "/home/frank/area/ly1-min.zip";
-CTANmirror="ftp://cam.ctan.org/tex-archive/"
+my $outfile_base = "psnfss";
+# my @fontlist =
+# ("avantgar", "bookman", "charter", "courier", "helvetic", "ncntrsbk",
+# "palatino", "symbol", "times", "zapfchan", "zapfding");
+my @fontlist =
+ ("zapfding");
-filelist=~/src/Packages/CTAN.FILES.byname
+my $psnfssRequiredPattern = "urw/base35|lw35nfs|freenfss|charter/bch";
-if [ ! -f $filelist ]; then
- wget -O $filelist ${CTANmirror}FILES.byname
-fi
+my $tpmDir = "texmf-dist/tpm/";
-files=`grep '^[[:space:]]*texmf' $package`
+my $CTANmirror = "ftp://cam.ctan.org/tex-archive/";
+my $filelist = "/home/frank/src/Packages/CTAN.FILES.byname";
-#wgetFile="./wgetFile" # insecure, but who cares?
+my @otherlocations = @ARGV;
-exec > $outfile
-for longfile in $files; do
- file=`basename $longfile`
-# queryURL="http://www.tex.ac.uk/cgi-bin/ctan-index?$file"
-# wget -O $wgetFile $queryURL
- queryResult=`grep /$file$ $filelist | sed -e "s at .*| @@"`
- resultLines=`echo $queryResult | wc -w`
+use XML::DOM;
+use Archive::Zip qw(:ERROR_CODES);
+use Archive::Tar;
+use File::Slurp;
+use File::Basename;
- if [ "$resultLines" -eq 1 ]; then
- echo -e "$file:\t$queryResult"
- elif [ "$resultLines" -eq 0 ]; then
- found=false
- for archive in $otherlocations; do
- if [ ! -f $archive ]; then echo -e "$archive not found."; exit 1; fi
- extension=${archive#*.}
- case $extension in
- tar.gz)
- command="tar -tzf"
- ;;
- tar.bz2)
- command="tar -tjf"
- ;;
- zip)
- command="unzip -l"
- ;;
- esac
- queryResult=`$command $archive | grep ${longfile#texmf*/} | sed -e 's at .*[[:space:]]@@'`
- resultLines=`echo $queryResult | wc -w`
- if [ "$resultLines" -eq 1 ]; then
- echo -e "$file:\t$queryResult\tin `basename $archive`"
- found=true
- elif [ "$resultLines" -gt 1 ]; then
- echo -e "$file\tmultiple hits:"
- echo -e "$queryResult"
- echo
- found=true
- fi
- done
- if [ "$found" = false ]; then
- echo -e "$longfile:\tNo hits"
- fi
- else
- echo -e "File:\t$file multiple hits:"
- echo -e "$queryResult"
- echo
- fi
-done
+my ($mydir,$mmydir);
+BEGIN { # get our other local perl modules.
+ ($mydir = $0) =~ s,/[^/]*$,,;
+ if ($mydir eq $0) { $mydir = `pwd` ; chomp($mydir); }
+ if (!($mydir =~ m,/.*,,)) { $mmydir = `pwd`; chomp($mmydir); $mydir = "$mmydir/$mydir" ; }
+ unshift (@INC, $mydir);
+# unshift (@INC, "$mydir/..");
+}
-grep "in " $outfile > $outfile.packed
-grep "No hits" $outfile > $outfile.nohits
-grep -v ":" $outfile | sed -e "s/multiple hits.*\n//" > $outfile.multiple
-grep ":" $outfile | egrep -v "hits|in |multiple" > $outfile.single
+use Tpm;
+my @lw35nfss;
+my @freenfss;
+my %CTANarchive = (
+ lw35nfss => {zipfile => $lw35nfss_archive},
+ freenfss => {zipfile => $freenfss_archive},
+ cspsfonts => {zipfile => $cspsfonts_archive},
+ "ly1-min" => {zipfile => $ly1min_archive}
+); # each unnamed hash will get a key "members" whose value is a reference to
+ # a list of files in the archive
+
+
+# read zip archives into memory
+my $uz = new Archive::Zip or die;
+
+foreach my $archive (@psnfssArchives, @otherArchivesZip) {
+ $uz->read($CTANarchive{$archive}{zipfile}) == AZ_OK or die "Can't open $CTANarchive{$archive}{zipfile} for $archive";
+ $CTANarchive{$archive}{members} = [$uz->memberNames()];
+}
+
+# read tar archives into memory
+my $tar = new Archive::Tar or die;
+
+foreach my $archive (@otherArchivesTar) {
+ $tar->read($CTANarchive{$archive}{zipfile},1) or die "Can't open $CTANarchive{$archive}{zipfile} for $archive";
+ $CTANarchive{$archive}{members} = [$tar->list_files()];
+}
+
+my $wget = "wget -O";
+my $CTANlist = $CTANmirror . "FILES.byname";
+
+# read CTAN list into memory
+if ( ! -f $filelist) { system("$wget $filelist $CTANlist");};
+my @CTANbyname = read_file($filelist);
+foreach (@CTANbyname) {
+ s/^[^[:alpha:]]*//;
+ chomp;
+}
+my %CTANbyname = map { basename($_), $_ } @CTANbyname;
+
+
+# functions
+sub getLicensePerArchive {
+ my $file = basename($_[0]);
+ SWITCH: {
+ if ($file =~ /^lw35nfss.zip$/ ) { return "license: LPPL"; last SWITCH };
+ if ($file =~ /^freenfss.zip$/ ) { return "license: LPPL"; last SWITCH };
+ if ($file =~ /^cspsfonts.tar.gz$/ ) { return "license: CSTEX (unclear)"; last SWITCH };
+ if ($file =~ /^ly1-min.zip$/ ) { return "license: unknown (Carlisle)"; last SWITCH };
+
+ return "unknown";
+ };
+};
+sub getLicenseFromList {
+ my $file = $_[0];
+ SWITCH: {
+ if ($file =~ m(psnfss-source) ) { return " \t license: LPPL"; last SWITCH };
+ if ($file =~ m(urw/base35) ) { return " \t license: GPL"; last SWITCH };
+
+ return " \t license: unknown";
+ };
+};
+
+sub grepPsnfssArchive {
+ my $file = $_[0];
+ my ($hit, $ReturnLine);
+
+ foreach my $archive (@psnfssArchives) {
+ if (($hit) = grep {/$file/} @{$CTANarchive{$archive}{members}} ) {
+ my $zipfile = basename($CTANarchive{$archive}{zipfile});
+ $ReturnLine =
+ "$hit\t in $zipfile\t"
+ . getLicensePerArchive($CTANarchive{$archive}{zipfile});
+ return($ReturnLine);
+ }
+ }
+}
+
+sub grepOtherArchive {
+ my $file = $_[0];
+ my ($hit, $ReturnLine);
+
+ foreach my $archive (@otherArchivesTar, @otherArchivesZip) {
+ if (($hit) = grep {/$file/} @{$CTANarchive{$archive}{members}} ) {
+ my $zipfile = basename($CTANarchive{$archive}{zipfile});
+ $ReturnLine =
+ "$hit\t in $zipfile\t"
+ . getLicensePerArchive($CTANarchive{$archive}{zipfile});
+ return($ReturnLine);
+ }
+ }
+}
+
+# open (OUTLIST,'>', $outfile_base . ".list") or die "Cannot open $outfile_base.list";
+my %AllFilesList; # a hash containing references to the lists
+my %RequiredFilesList;
+my %RestFileList;
+
+
+# main loop
+foreach my $font (@fontlist) {
+ my $LocalTPM = $tpmDir . $font . ".tpm";
+
+ my $dom_parser = new XML::DOM::Parser;
+ my $tpm = $dom_parser->parsefile($LocalTPM);
+ my %RunFiles = Tpm::getListField($tpm, "RunFiles");
+
+ # we don't want the tpm file which isn't installed
+ $RunFiles{"text"} =~ s/\n.*\.tpm$//m;
+ my @RunFiles = split(/\n/m,$RunFiles{"text"});
+ my @Files = grep {!/^\s*$/} @RunFiles ;
+
+ foreach my $file (@Files) {
+ my $basefile = basename($file);
+ my $locline;
+ FINDLOC: {
+ my $loc;
+ # first look in the psnfss zip archives
+ if ($loc = grepPsnfssArchive($basefile)) {
+ $locline = $loc;
+ last FINDLOC
+ }
+ # now look in the CTAN filelist
+ if ($CTANbyname{$basefile}) {
+ $locline = $CTANbyname{$basefile} . getLicenseFromList($CTANbyname{$basefile});
+ last FINDLOC
+ }
+ # now look in some other archives
+ if ($loc = grepOtherArchive($basefile)) {
+ $locline = $loc;
+ last FINDLOC
+ }
+ }
+
+ # prepend the filename
+ $locline = $locline
+ ? $basefile . "\t" . $locline . "\n"
+ : $basefile . "\t\t unknown\t license: unknown\n" ;
+# print OUTLIST $locline ;
+ push @{$AllFilesList{$font}}, $locline;
+ } # end foreach (@Files)
+
+ # now sort files...
+ my @RequiredFilesList;
+ foreach (@{$AllFilesList{$font}}) {
+ push @{$RequiredFilesList{$font}},$_ if ( m($psnfssRequiredPattern) );
+ }
+ @{$RestFileList{$font}} = ();
+ my %HowOftenHash = ();
+
+ foreach my $line ( @{$AllFilesList{$font}}, @{$RequiredFilesList{$font}} ) {
+ $HowOftenHash{$line}++
+ };
+ foreach my $line ( keys %HowOftenHash ) {
+ push @{$RestFileList{$font}}, $line unless ( $HowOftenHash{$line} > 1 );
+ };
+
+ print @{$RestFileList{$font}};
+};
+
+
+exit 0;
+
+__END__
+
+
+
+
+
+# print @RequiredFilesList;
+# print @AllFilesList;
More information about the Pkg-tetex-commits
mailing list