Annotation of loncom/build/parse.pl, revision 1.8

1.1       harris41    1: #!/usr/bin/perl
                      2: 
                      3: # Scott Harrison
                      4: # November 2000
                      5: 
1.2       harris41    6: # Read in loncapa tags and metagroup tags
1.1       harris41    7: 
1.4       harris41    8: # ---------------------------------------------- Read in command line arguments
1.1       harris41    9: my ($file,$mode)=@ARGV;
1.2       harris41   10: 
1.4       harris41   11: # ---------------------------------------------------- Read in master data file
1.1       harris41   12: open IN,"<$file";
                     13: my @lines=<IN>;
                     14: close IN;
1.5       harris41   15: my $info1=join('',@lines);
                     16: my $info2=$info1; # value to allow for meta data group retrieval
1.1       harris41   17: 
1.4       harris41   18: # ------------------------------------------------------- Make default settings
                     19: my $distribution="redhat6.2";
                     20: my $date=`date +'%B %e, %Y'`; chop $date;
                     21: my $buildhost=`hostname`; chop $buildhost;
1.5       harris41   22: # file category mappings
                     23: my %fcm=(
                     24: 	 'conf' => 'configurable',
                     25: 	 'graphic file' => 'graphicfile',
                     26: 	 'handler' => 'handler',
                     27: 	 'interface file' => 'interfacefile',
                     28: 	 'symbolic link' => 'link',
                     29: 	 'root script' => 'rootscript',
                     30: 	 'script' => 'script',
                     31: 	 'setuid script' => 'setuid',
                     32: 	 'static conf' => 'static',
                     33: 	 'system file' => 'systemfile',
                     34: 	 );
1.4       harris41   35: 
                     36: # ---------------------------------------------------- Parse the marked up data
                     37: my %info; # big data storage object
1.5       harris41   38: while ($info1=~/\<loncapa\s+(.*?)\>/isg) {
1.1       harris41   39:     my $keystring=$1;
1.4       harris41   40:     # In the parsing of LON-CAPA tags, remove boundary white-space,
                     41:     # and handle quotation commands.
1.2       harris41   42:     my %hash=map {my ($key,$value)=split(/\=(?!")|\=(?=\s*"[^"]*"[^"]*$)/);
                     43:                                    $value=~s/^"//;
                     44:  				   $value=~s/"$//;
                     45:                                    (uc($key),$value);}
                     46:              split(/\s+(?=\w+\s*\=)/,$keystring);
1.4       harris41   47:     # Handle the different types of commands
1.1       harris41   48:     if (uc($hash{'TYPE'}) eq "OWNERSHIP") {
                     49:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
                     50:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
                     51:     }
                     52:     elsif (uc($hash{'TYPE'}) eq "DEVOWNERSHIP") {
                     53:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
                     54:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
                     55:     }
                     56:     elsif (uc($hash{'TYPE'}) eq "RPM") {
                     57:         $hash{'VALUE'}=~s/\\n/\n/g;
                     58:         $info{$hash{'TYPE'}}{$hash{'NAME'}}=$hash{'VALUE'};
                     59:     }
                     60:     elsif (uc($hash{'TYPE'}) eq "DIRECTORY") {
1.4       harris41   61:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=
                     62:                                                        $hash{'CATEGORY'};
                     63:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'DESCRIPTION'}=
                     64:                                $hash{'DESCRIPTION'} if $hash{'DESCRIPTION'};
1.1       harris41   65:     }
                     66:     elsif (uc($hash{'TYPE'}) eq "LOCATION") {
1.5       harris41   67:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=                               $hash{'CATEGORY'};
                     68:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'SOURCE'}=                                               $hash{'SOURCE'};
1.1       harris41   69:         # get surrounding metagroup information
                     70:         my $ckeystring=$keystring; $ckeystring=~s/(SOURCE\=\"[^"]*)\*/$1\\\*/g;
1.5       harris41   71:         $ckeystring=~s/(TARGET\=\"[^"]*)\*/$1\\\*/g;
1.1       harris41   72:         $info2=~/.*\<(?:metagroup|metasupergroup)\>(.*?)\<loncapa\s+$ckeystring\>(.*?)\<\/(?:metagroup|metasupergroup)\>/is;
                     73: 	my $data=$1.$2;
                     74:         my @meta=('description','build','dependencies','files','note');
                     75:         foreach my $m (@meta) {
                     76: 	    if ($data=~/\<($m)\>(.*?)\<\/$m\>/sgi) {
                     77: 		my ($key,$value)=($1,$2);
1.4       harris41   78: 		$info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{$key}=
                     79: 		                                                    $value;
1.1       harris41   80: 	    }
                     81:         }
                     82:     }
                     83:     else {
                     84:         warn("WARNING: this tag text will be ignored since it cannot be understood\n---> $keystring\n");
                     85:     }
                     86: }
                     87: 
1.4       harris41   88: if ($mode eq "ALL" || $mode eq "HTML") {
                     89:     my $a;
                     90:     $a=&begin_description_page;
                     91:     print $a;
                     92:     $a=&make_rpm_description_block;
                     93:     print $a;
                     94:     @directories=&determine_directory_structure;
                     95:     $a=&make_directory_structure_description_block(\@directories);
                     96:     print $a;
1.6       harris41   97:     $a=&make_file_type_ownership_and_permissions_description_block;
                     98:     print $a;
1.4       harris41   99:     $a=&make_directory_and_file_structure_description_block(\@directories);
                    100:     print $a;
                    101:     $a=&end_description_page;
                    102:     print $a;
                    103: }
                    104: 
                    105: # ------------------------------------------------- Begin description page
                    106: sub begin_description_page {
                    107:     my $description=<<END;
                    108: <HTML>
                    109: <HEAD>
                    110: <TITLE>LON-CAPA Software Description Page ($distribution, $date)</TITLE>
                    111: </HEAD>
                    112: <BODY>
                    113: <FONT SIZE=+2>LON-CAPA Software Description Page ($distribution, $date)</FONT>
                    114: <BR>Michigan State University
                    115: <BR>Learning Online with CAPA
                    116: <BR>Contact korte\@lon-capa.org
                    117: <UL>
                    118: <LI>About this file
                    119: <LI>Software Package Description
                    120: <LI>Directory Structure
1.7       harris41  121: <LI>File Type Ownership and Permissions
1.4       harris41  122: <LI>File and Directory Structure
                    123: </UL>
                    124: <FONT SIZE=+2>About this file</FONT>
                    125: <P>
                    126: This file is generated dynamically by <TT>parse.pl</TT> as
                    127: part of a development compilation process.  See 
                    128: http://install.lon-capa.org/compile/index.html for more
                    129: information.
                    130: </P>
                    131: END
                    132:     return $description;
                    133: }
                    134: 
                    135: # ------------------------------------------------- End description page
                    136: sub end_description_page {
                    137:     my $description=<<END;
                    138: <HR>
1.5       harris41  139: <FONT SIZE=-1>LON-CAPA Software Development Team</FONT>
1.4       harris41  140: </BODY>
                    141: </HTML>
                    142: END
                    143:     return $description;
                    144: }
                    145: 
                    146: # ------------------------------------------------- Make RPM description block
                    147: sub make_rpm_description_block {
                    148:     my $description=<<END;
                    149: <FONT SIZE=+2>Rolled in a RedHat 6.2 RPM, $date</FONT>
                    150: <P>
                    151: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
                    152: <TR><TD>
                    153: <PRE>
                    154: Name        : $info{'RPM'}{'Name'}
                    155: Version     : $info{'RPM'}{'Version'}
                    156: Vendor      : $info{'RPM'}{'Vendor'} 
                    157: Release     : $info{'RPM'}{'Release'}                             
                    158: Build Host  : $buildhost
                    159: Group       : $info{'RPM'}{'Group'}
                    160: License     : $info{'RPM'}{'Copyright'}
                    161: Summary     : $info{'RPM'}{'Summary'}
                    162: Description : 
                    163: <PRE>
                    164: $info{'RPM'}{'description'}
                    165: </PRE>
                    166: </TD></TR>
                    167: </TABLE>
                    168: </P>
                    169: END
                    170:     return $description;
                    171: }
                    172: 
                    173: # ----------------------------------------------- Determine directory structure
                    174: sub determine_directory_structure {
                    175:     my @directories=keys %{$info{'DIRECTORY'}{$distribution}};
                    176:     return (sort @directories);
                    177: }
1.1       harris41  178: 
1.4       harris41  179: 
                    180: # ---------------------------------- Make directory structure description block
                    181: sub make_directory_structure_description_block {
                    182:     my ($dirs)=@_;
                    183:     my $description=<<END;
                    184: <FONT SIZE=+2>Directory Structure Description, $date</FONT>
                    185: <P>
                    186: <TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
                    187: END
                    188:     my $maxcount=0;
1.8     ! harris41  189:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
        !           190:     my %diraccount; # hash to track which directories are accounted for
        !           191:     foreach my $file (@allfiles) {
        !           192: 	$file=~/^(.*)\/([^\/]+)$/;
        !           193: 	$diraccount{$1}=1;
        !           194:     }
1.4       harris41  195:     foreach my $d (@$dirs) {
                    196:         my (@matches)=($d=~/\//g);
                    197: 	my $count=scalar(@matches);
                    198: 	$maxcount=$count if $count>$maxcount;
1.8     ! harris41  199: 	delete $diraccount{$d};
1.4       harris41  200:     }
                    201:     $description.=<<END;
                    202: <TR>
                    203: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Category</TH>
                    204: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
                    205: <TH ALIGN=LEFT BGCOLOR=#FFFFFF><FONT COLOR=#FF0000>Development<BR>Permissions</FONT></TH>
                    206: END
                    207:     $description.="<TH ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+1).">Directory Path</TH>\n";
1.8     ! harris41  208:     if (keys %diraccount) {
        !           209: 	$description.= "<TR><TD ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+4)."><I><PRE>Directories that are unaccounted for: \n";
        !           210: 	foreach my $d (keys %diraccount) {
        !           211: 	    $description.="$d\n";
        !           212: 	}
        !           213: 	$description.="</PRE></I></TH></TR>\n";
        !           214:     }
1.4       harris41  215:     foreach my $d (@$dirs) {
                    216: 	my $dtable=$d;
                    217: 	$dtable=~s/\//\<\/TD\>\<TD\>/g;
                    218: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
                    219: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    220: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    221: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    222: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    223: 	$description.=<<END;
                    224: <TR>
                    225: <TD BGCOLOR=#FFFFFF>$category</TD>
                    226: <TD BGCOLOR=#FFFFFF><TT>$chmod $chown</TT></TD>
                    227: <TD BGCOLOR=#FFFFFF><FONT COLOR=#FF0000><TT>$devchmod $devchown</TT></FONT></TD>
                    228: <TD>
                    229: $dtable
                    230: </TD>
                    231: </TR>
                    232: END
                    233:     }
                    234:     $description.=<<END;
                    235: </TABLE>
                    236: </P>
                    237: END
                    238:     return $description;
                    239: }
                    240: 
1.6       harris41  241: # ------------------- Make file type ownership and permissions description block
                    242: sub make_file_type_ownership_and_permissions_description_block {
                    243:     my $description=<<END;
                    244: <FONT SIZE=+2>File Type Ownership and Permissions Descriptions, $date</FONT>
                    245: <P>
                    246: This table shows what permissions and ownership settings correspond
                    247: to each kind of file type.
                    248: </P>
                    249: <P>
                    250: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
                    251: <TR>
                    252: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Icon</TH>
                    253: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Type</TH>
                    254: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
                    255: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Development Permissions</TH>
                    256: </TR>
                    257: END
                    258:     foreach my $type (keys %{$info{'OWNERSHIP'}}) {
                    259: 	if (defined($fcm{$type})) {
                    260: 	    my $chmod=$info{'OWNERSHIP'}{$type}{'CHMOD'};
                    261: 	    my $chown=$info{'OWNERSHIP'}{$type}{'CHOWN'};
                    262: 	    my $devchmod=$info{'DEVOWNERSHIP'}{$type}{'CHMOD'};
                    263: 	    my $devchown=$info{'DEVOWNERSHIP'}{$type}{'CHOWN'};
                    264: 	    $description.=<<END;
                    265: <TR>
                    266: <TD><IMG SRC="$fcm{$type}.gif" ALT="$type"></TD>
                    267: <TD>$type</TD>
                    268: <TD><TT>$chmod $chown</TT></TD>
                    269: <TD><TT>$devchmod $devchown</TT></TD>
                    270: </TR>
                    271: END
                    272:         }
                    273:     }
                    274:     $description.=<<END;
                    275: </TABLE>
                    276: </P>
                    277: END
                    278: }
                    279: 
1.4       harris41  280: # ------------------------- Make directory and file structure description block
                    281: sub make_directory_and_file_structure_description_block {
                    282:     my ($dirs)=@_;
                    283:     my $description=<<END;
                    284: <FONT SIZE=+2>Directory and File Structure Description, $date</FONT>
1.6       harris41  285: <P>
                    286: The icons on the left column correspond to the file type
                    287: specified in the second column.  The last column "Notes" shows compilation,
1.7       harris41  288: dependency, and configuration information.  The CVS location
                    289: shows the location of the binary source file (if applicable) needed to
                    290: be copied to the target.  If the binary source file is not at
                    291: the specified location, then the text is shown in 
                    292: <FONT COLOR=#FF0000>red</FONT>.
1.6       harris41  293: </P>
1.4       harris41  294: <P>
1.5       harris41  295: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
1.4       harris41  296: END
                    297:     my $counter=0;
                    298:     my @colorindex=("#80FF80","#80FFFF","#FFFF80");
1.5       harris41  299:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
1.4       harris41  300:     foreach my $d (@$dirs) {
                    301: 	# set color
                    302: 	my $color=$colorindex[$counter%3];
                    303: 	# set other values
                    304: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    305: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    306: 	# find subdirectories that are contained in this directory
                    307: 	my @subdirs;
                    308: 	foreach my $d2 (@$dirs) {
1.5       harris41  309: 	    if ($d2=~/^$d\/([^\/]+)$/) {
1.4       harris41  310: 		push @subdirs,$1;
                    311: 	    }
                    312: 	}
                    313: 	# find files that are contained in this directory
                    314: 	my @files;
1.5       harris41  315: 	my @filesfull;
1.4       harris41  316: 	foreach my $f (@allfiles) {
1.5       harris41  317: 	    if ($f=~/^$d\/([^\/]+)$/) {
1.4       harris41  318: 		push @files,$1;
1.5       harris41  319: 		push @filesfull,$f;
1.4       harris41  320: 	    }
                    321: 	}
                    322: 	# render starting HTML formatting elements
                    323: 	if (@subdirs || @files) {
                    324: 	    my $subdirstring="<BR>* Relevant subdirectories: " . join(", ",@subdirs) if @subdirs;
                    325: 	    $description.=<<END;
1.5       harris41  326: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="directory.gif" ALT="directory">DIRECTORY -- $d $dirdescription
                    327: $subdirstring</FONT></TD></TR>
1.4       harris41  328: END
                    329:         }
                    330: 	else {
                    331: 	    $description.=<<END;
1.5       harris41  332: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="emptydirectory.gif" ALT="empty directory">EMPTY DIRECTORY - $d $dirdescription</FONT></TD></TR>
1.4       harris41  333: END
                    334:         }
                    335: 	if (@files) {
                    336: 	    $description.=<<END;
                    337: <TR>
1.5       harris41  338: <TH BGCOLOR=$color ALIGN=LEFT COLSPAN=2>Type</TH>
                    339: <TH BGCOLOR=$color ALIGN=LEFT>File Name</TH>
                    340: <TH BGCOLOR=$color ALIGN=LEFT>Function</TH>
                    341: <TH BGCOLOR=$color ALIGN=LEFT>CVS Location</TH>
                    342: <TH BGCOLOR=$color ALIGN=LEFT>Notes</TH>
1.4       harris41  343: </TR>
                    344: END
1.5       harris41  345:             foreach my $i (0..$#files) {
                    346: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    347: 		my $fdescription=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DESCRIPTION'};
                    348: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
1.7       harris41  349: 		unless (-e "../../$source") {
                    350: 		    $source=~/([^\/]+)$/;
                    351: 		    my $s=$1;
                    352: 		    $source="<FONT COLOR=#FF0000>$source</FONT>";
                    353: #		    my $fr=`cd ../../; find . -name $s`;
                    354: #		    $source.="<BR>$fr\n";
                    355: 		}
1.5       harris41  356: 		my $notes=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'NOTES'};
                    357: 		$description.=<<END;
                    358: <TR>
                    359: <TD BGCOLOR=#A0A0A0><IMG SRC="$fcm{$category}.gif" ALT="$category"></TD>
                    360: <TD BGCOLOR=$color>$category</TD>
                    361: <TD BGCOLOR=$color>$files[$i]</TD>
                    362: <TD BGCOLOR=$color>$fdescription&nbsp;</TD>
                    363: <TD BGCOLOR=$color>$source</TD>
                    364: <TD BGCOLOR=$color>$notes&nbsp;</TD>
1.4       harris41  365: </TR>
                    366: END
1.5       harris41  367: 	    }
                    368: 	}
1.4       harris41  369: 	$counter++;
                    370:     }
                    371:     $description.=<<END;
                    372: </TABLE>
                    373: </P>
                    374: END
                    375:     return $description;
                    376: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>