--- loncom/build/lpml_parse.pl 2001/11/29 19:00:56 1.24 +++ loncom/build/lpml_parse.pl 2001/12/15 20:20:11 1.32 @@ -1,14 +1,42 @@ #!/usr/bin/perl -# Scott Harrison +# The LearningOnline Network with CAPA +# lpml_parse.pl - Linux Packaging Markup Language parser +# +# $Id: lpml_parse.pl,v 1.32 2001/12/15 20:20:11 harris41 Exp $ +# +# Written by Scott Harrison, harris41@msu.edu +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA 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 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA 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 LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# # YEAR=2001 # May 2001 # 06/19/2001,06/20,06/24 - Scott Harrison # 9/5/2001,9/6,9/7,9/8 - Scott Harrison # 9/17,9/18 - Scott Harrison # 11/4,11/5,11/6,11/7,11/16,11/17 - Scott Harrison +# 12/2,12/3,12/4,12/5,12/6,12/13 - Scott Harrison # -# $Id: lpml_parse.pl,v 1.24 2001/11/29 19:00:56 harris41 Exp $ ### ############################################################################### @@ -49,7 +77,7 @@ Only the 1st argument is mandatory for t Example: cat ../../doc/loncapafiles.lpml |\\ -perl lpml_parse.pl html default /home/sherbert/loncapa /tmp/install +perl lpml_parse.pl html development default /home/sherbert/loncapa /tmp/install END # ------------------------------------------------- Grab command line arguments @@ -77,6 +105,8 @@ if (@ARGV) { my $targetroot; my $sourceroot; +my $targetrootarg; +my $sourcerootarg; if (@ARGV) { $sourceroot = shift @ARGV; } @@ -85,6 +115,8 @@ if (@ARGV) { } $sourceroot=~s/\/$//; $targetroot=~s/\/$//; +$sourcerootarg=$sourceroot; +$targetrootarg=$targetroot; my $logcmd='| tee -a WARNINGS'; @@ -193,11 +225,13 @@ $cleanstring=~s/\>\s*\n\s*\\new(\$cleans $parser->xml_mode('1'); # Define handling methods for mode-dependent text rendering + $parser->{textify}={ + specialnotices => \&format_specialnotices, + specialnotice => \&format_specialnotice, targetroot => \&format_targetroot, sourceroot => \&format_sourceroot, categories => \&format_categories, category => \&format_category, + abbreviation => \&format_abbreviation, targetdir => \&format_targetdir, chown => \&format_chown, chmod => \&format_chmod, @@ -317,7 +367,60 @@ exit; # ------------------------ Final output at end of markup parsing and formatting sub end { if ($mode eq 'html') { - return "\n"; + # START TEMP WAY +# my $totallinecount; +# my $totalbytecount; +# map {$totallinecount+=$linecount{$_}; +# $totalbytecount+=$bytecount{$_}} +# @categorynamelist; + # END TEMP WAY + return "
 
". + "Summary of Source Repository". + "". + "
 
". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "
Files, Directories, and Symbolic Links
Files (not referenced by globs)$file_count
Files (referenced by globs)$fileglobnames_count
Total Files".($fileglobnames_count+$file_count)."
File globs".$fileglob_count."
Directories".$directory_count."
Symbolic links".$link_count."
". + "". + "". + "". + "". + "". + join("\n",(map {"". + "". + ""} + @categorynamelist)). + "
File Category Count
IconNameNumber of OccurrencesNumber of Incorrect Counts
$_$categorycount{$_}
". + "\n"; + +# START TEMP WAY +# join("\n",(map {"". +# "$_$categorycount{$_}$linecount{$_}$bytecount{$_}"} +# @categorynamelist)). +# "
 
". +# "Total Lines of Code: $totallinecount". +# "
 
". +# "Total Bytes: $totalbytecount". +# END TEMP WAY } if ($mode eq 'install') { return ''; @@ -339,12 +442,13 @@ sub format_lpml { $lpml=< -LPML Description Page (dist=$dist, $date) +LPML Description Page +(dist=$dist, categorytype=$categorytype, $date) END $lpml .= "
LPML Description Page (dist=$dist, ". - "$date)". + "categorytype=$categorytype, $date)". ""; $lpml .=< @@ -353,7 +457,8 @@ END Descriptions
  • Software Package Description
  • Directory Structure
  • -
  • File and Directory Structure
  • +
  • Files
  • +
  • Summary of Source Repository
  • END $lpml .=<About this file

    This file is generated dynamically by lpml_parse.pl as -part of a development compilation process. Author: Scott -Harrison (harris41\@msu.edu). +part of a development compilation process.

    +

    LPML written by Scott Harrison (harris41\@msu.edu).

    END } @@ -374,7 +479,7 @@ END * Software Package Description * Directory Structure * File Type Ownership and Permissions -* File and Directory Structure +* Files END $lpml .=<". "\nFile Type Ownership and Permissions". " Descriptions". - "\n\n". - "
    \n$text\n". + "\n

    This table shows what permissions and ownership settings ". + "correspond to each category.

    ". + "\n
    \n". + "". + "". + "". + "". + "". + "\n$text\n". "
    IconCategory NamePermissions ". + "($categorytype)
    \n"; } elsif ($mode eq 'text') { return $categories="\n". "\nFile Type Ownership and Permissions". " Descriptions". + "\n$text". "\n"; } else { @@ -472,12 +586,24 @@ sub format_category { my (@tokeninfo)=@_; $category_att_name=$tokeninfo[2]->{'name'}; $category_att_type=$tokeninfo[2]->{'type'}; - $chmod='';$chown=''; + $abbreviation=''; $chmod='';$chown=''; $parser->get_text('/category'); $parser->get_tag('/category'); + $fab{$category_att_name}=$abbreviation; if ($mode eq 'html') { - return $category="\n
    CATEGORY $category_att_name ". - "$category_att_type $chmod $chown"; + if ($category_att_type eq $categorytype) { + push @categorynamelist,$category_att_name; + $categoryhash{$category_att_name}="$chmod $chown"; + return $category="". + "\n". + "${category_att_name}\n". + "$chmod $chown\n". + "". + "\n"; +# return $category="\n
    CATEGORY $category_att_name ". +# "$category_att_type $chmod $chown"; + } } else { if ($category_att_type eq $categorytype) { @@ -488,6 +614,17 @@ sub format_category { return ''; } } +# --------------------------------------------------- Format categories section +sub format_abbreviation { + my @tokeninfo=@_; + $abbreviation=''; + my $text=&trim($parser->get_text('/abbreviation')); + if ($text) { + $parser->get_tag('/abbreviation'); + $abbreviation=$text; + } + return ''; +} # -------------------------------------------------------- Format chown section sub format_chown { my @tokeninfo=@_; @@ -682,12 +819,14 @@ sub format_rpmAutoReqProv { sub format_rpmdescription { my $text=$parser->get_text('/rpmdescription'); $parser->get_tag('/rpmdescription'); - $text=~s/\n//g; - $text=~s/\\n/\n/g; if ($mode eq 'html') { + $text=~s/\n//g; + $text=~s/\\n/\n/g; return $rpmdescription="\nDescription : $text"; } elsif ($mode eq 'text') { + $text=~s/\n//g; + $text=~s/\\n/\n/g; return $rpmdescription="\nDescription : $text"; } else { @@ -711,11 +850,18 @@ sub format_directories { my $text=$parser->get_text('/directories'); $parser->get_tag('/directories'); if ($mode eq 'html') { + $text=~s/\[\{\{\{\{\{DPATHLENGTH\}\}\}\}\}\]/$dpathlength/g; return $directories="\n
     
    ". "". "Directory Structure". - "\n$text\n
    ". - "\n"; + "\n
     
    ". + "\n". + "". + "\n". + "\n". + "\n". + "\n$text\n
    CategoryStatusExpected Permissions & OwnershipTarget Directory ". + "Path

    "."\n"; } elsif ($mode eq 'text') { return $directories="\nDirectory Structure\n$text\n". @@ -734,8 +880,26 @@ sub format_directory { $targetdir='';$categoryname='';$description=''; $parser->get_text('/directory'); $parser->get_tag('/directory'); + $directory_count++; + $categorycount{$categoryname}++; if ($mode eq 'html') { - return $directory="\n
    DIRECTORY $targetdir $categoryname ". + my @a; + @a=($targetdir=~/\//g); + my $d=scalar(@a)+1; + $dpathlength=$d if $d>$dpathlength; + my $thtml=$targetdir; + $thtml=~s/\//\<\/td\>\/g; + my ($chmod,$chown)=split(/\s/,$categoryhash{$categoryname}); + return $directory="\n". + "$categoryname". + " ". + "$chmod
    $chown". + "$thtml". + "". + "$description"; + } + if ($mode eq 'text') { + return $directory="\nDIRECTORY $targetdir $categoryname ". "$description"; } elsif ($mode eq 'install') { @@ -786,8 +950,15 @@ sub format_files { if ($mode eq 'html') { return $directories="\n
     
    ". "
    ". - "File and Directory Structure". - "\n$text\n
    ". + "Files
     
    ". + "

    All source and target locations are relative to the ". + "sourceroot and targetroot values at the beginning of this ". + "document.

    ". + "\n". + "". + "". + "". + "$text
    StatusCategoryName/LocationDescriptionNotes
    \n". "\n"; } elsif ($mode eq 'text') { @@ -881,13 +1052,36 @@ sub format_file { $note=''; $build=''; $status=''; $dependencies=''; my $text=&trim($parser->get_text('/file')); my $buildtest; + $file_count++; + $categorycount{$categoryname}++; + # START TEMP WAY +# if (-T "$sourcerootarg/$source") { +# $linecount{$categoryname}+=`wc -l $sourcerootarg/$source`; +# } +# my $bytesize=(-s "$sourcerootarg/$source"); +# $bytecount{$categoryname}+=$bytesize; + # END TEMP WAY if ($source) { $parser->get_tag('/file'); if ($mode eq 'html') { - return ($file="\n
    BEGIN FILE\n". - "$source $target $categoryname $description $note " . - "$build $status $dependencies" . - "\nEND FILE"); + return ($file="\n". + "". + " ". + "". + "$categoryname
    ". + $categoryhash{$categoryname}."". + "SOURCE: $source
    TARGET: $target". + "$description". + "$note". + ""); +# return ($file="\n
    BEGIN FILE\n". +# "$source $target $categoryname $description $note " . +# "$build $status $dependencies" . +# "\nEND FILE"); } elsif ($mode eq 'install' && $categoryname ne 'conf') { if ($build) { @@ -935,21 +1129,11 @@ $buildtest \@if !(test -e "${sourceroot} case "\$\$ECODE" in \\ 1) echo "${targetroot}/${target} is unchanged";; \\ 2) echo "**** WARNING **** target file ${targetroot}/${target} is newer than CVS source; saving current (old) target file to ${targetroot}/${target}.lpmlsave and then overwriting"$logcmd && install -o www -g www -m 0600 ${targetroot}/${target} ${targetroot}/${target}.lpmlsave && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\ - 0) echo "install $categoryhash{$categorname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\ + 0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\ esac; \\ perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\ fi END -# return "\t".'@test -e '.$sourceroot.'/'.$source. -# ' && perl filecompare.pl -b '.$sourceroot.'/'.$source.' '. -# $targetroot.'/'.$target. -# ' && install '. -# $categoryhash{$categoryname}.' '. -# $sourceroot.'/'.$source.' '. -# $targetroot.'/'.$target. -# ' || echo "**** WARNING '. -# '**** CVS source file does not exist: '.$sourceroot.'/'. -# $source.'"'."\n"; } elsif ($mode eq 'configinstall' && $categoryname eq 'conf') { push @configall,$targetroot.'/'.$target; @@ -1000,16 +1184,46 @@ END # --------------------------------------------------------- Format link section sub format_link { my @tokeninfo=@_; - $link=''; $linkto=''; $target=''; $categoryname=''; $description=''; - $note=''; $build=''; $status=''; $dependencies=''; + $link=''; $linkto=''; $source=''; $target=''; $categoryname=''; + $description=''; $note=''; $build=''; $status=''; $dependencies=''; my $text=&trim($parser->get_text('/link')); + my @links; if ($linkto) { $parser->get_tag('/link'); if ($mode eq 'html') { - return $link="\n
    BEGIN LINK\n". - "$linkto $target $categoryname $description $note " . - "$build $status $dependencies" . - "\nEND LINK"; + my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target); + $link_count+=scalar(@targets); + foreach my $tgt (@targets) { + $categorycount{$categoryname}++; + push @links,("\n". + "". + " ". + "". + "$categoryname". + "LINKTO: $linkto
    TARGET: $tgt". + "$description". + "$note". + ""); +# push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt. +# "\n"; + } + return join('',@links); +# return ($link="\n". +# "". +# " ". +# "$categoryname". +# "LINKTO: $linkto
    TARGET: $target". +# "$description". +# "$note". +# ""); +# return $link="\nBEGIN LINK\n". +# "$linkto $target $categoryname $description $note " . +# "$build $status $dependencies" . +# "\nEND LINK"; } elsif ($mode eq 'install') { my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target); @@ -1033,18 +1247,56 @@ sub format_fileglob { $note=''; $build=''; $status=''; $dependencies=''; $filenames=''; my $text=&trim($parser->get_text('/fileglob')); + my $filenames2=$filenames;$filenames2=~s/\s//g; + $fileglob_count++; + my @semi=($filenames2=~/(\;)/g); + $fileglobnames_count+=scalar(@semi)+1; + $categorycount{$categoryname}+=scalar(@semi)+1; + # START TEMP WAY +# for my $f (split(/\;/,$filenames2)) { +# if (-T "$sourcerootarg/$sourcedir/$f") { +# $linecount{$categoryname}+=`wc -l $sourcerootarg/$sourcedir/$f`; +# open OUT,">>/tmp/junk123"; +# print OUT "$linecount{$categoryname} $categoryname $sourcerootarg/$sourcedir/$f\n"; +# close OUT; +# } +# my $bytesize=(-s "$sourcerootarg/$sourcedir/$f"); +# $bytecount{$categoryname}+=$bytesize; +# } + # END TEMP WAY if ($sourcedir) { $parser->get_tag('/fileglob'); if ($mode eq 'html') { - return $fileglob="\n
    BEGIN FILEGLOB\n". - "$glob sourcedir $targetdir $categoryname $description $note ". - "$build $status $dependencies $filenames" . - "\nEND FILEGLOB"; + return $fileglob="\n". + " ". + ""."". + "$categoryname
    ". + "".$categoryhash{$categoryname}."". + "SOURCEDIR: $sourcedir
    ". + "TARGETDIR: $targetdir
    ". + "GLOB: $glob
    ". + "FILENAMES: $filenames". + "". + "$description". + "$note". + ""; +# return $fileglob="\nBEGIN FILEGLOB\n". +# "$glob sourcedir $targetdir $categoryname $description $note ". +# "$build $status $dependencies $filenames" . +# "\nEND FILEGLOB"; } elsif ($mode eq 'install') { + my $eglob=$glob; + if ($glob eq '*') { + $eglob='[^C][^V][^S]'.$glob; + } return "\t".'install '. $categoryhash{$categoryname}.' '. - $sourceroot.'/'.$sourcedir.'[^C][^V][^S]'.$glob.' '. + $sourceroot.'/'.$sourcedir.$eglob.' '. $targetroot.'/'.$targetdir.'.'."\n"; } else { @@ -1090,9 +1342,25 @@ sub format_source { sub format_note { my @tokeninfo=@_; $note=''; - my $text=&trim($parser->get_text('/note')); +# my $text=&trim($parser->get_text('/note')); + my $aref; + my $text; + while ($aref=$parser->get_token()) { + if ($aref->[0] eq 'E' && $aref->[1] eq 'note') { + last; + } + elsif ($aref->[0] eq 'S') { + $text.=$aref->[4]; + } + elsif ($aref->[0] eq 'E') { + $text.=$aref->[2]; + } + else { + $text.=$aref->[1]; + } + } if ($text) { - $parser->get_tag('/note'); +# $parser->get_tag('/note'); $note=$text; } return ''; @@ -1164,6 +1432,16 @@ sub format_filenames { } return ''; } +# ------------------------------------------------ Format specialnotice section +sub format_specialnotices { + $parser->get_tag('/specialnotices'); + return ''; +} +# ------------------------------------------------ Format specialnotice section +sub format_specialnotice { + $parser->get_tag('/specialnotice'); + return ''; +} # ------------------------------------------------------- Format linkto section sub format_linkto { my @tokeninfo=@_;