File:  [LON-CAPA] / loncom / build / Attic / parse.pl
Revision 1.12: download - view: text, annotated - select for diffs
Mon Dec 11 19:02:48 2000 UTC (23 years, 7 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
the BinaryRoot target works great now in this parse script

    1: #!/usr/bin/perl
    2: 
    3: # Scott Harrison
    4: # November 2000
    5: 
    6: # Read in loncapa tags and metagroup tags
    7: 
    8: # ---------------------------------------------- Read in command line arguments
    9: my ($file,$mode)=@ARGV;
   10: 
   11: # ---------------------------------------------------- Read in master data file
   12: open IN,"<$file";
   13: my @lines=<IN>;
   14: close IN;
   15: my $info1=join('',@lines);
   16: my $info2=$info1; # value to allow for meta data group retrieval
   17: 
   18: # ------------------------------------------------------- Make default settings
   19: my $distribution="redhat6.2";
   20: my $date=`date +'%B %e, %Y'`; chop $date;
   21: my $buildhost=`hostname`; chop $buildhost;
   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: 	 );
   35: 
   36: # ---------------------------------------------------- Parse the marked up data
   37: my %info; # big data storage object
   38: while ($info1=~/\<loncapa\s+(.*?)\>/isg) {
   39:     my $keystring=$1;
   40:     # In the parsing of LON-CAPA tags, remove boundary white-space,
   41:     # and handle quotation commands.
   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);
   47:     # Handle the different types of commands
   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") {
   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'};
   65:     }
   66:     elsif (uc($hash{'TYPE'}) eq "LOCATION") {
   67:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=                               $hash{'CATEGORY'};
   68:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'LINKTO'}=                               $hash{'LINKTO'};
   69:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'SOURCE'}=                                               $hash{'SOURCE'};
   70:         # get surrounding metagroup information
   71:         my $ckeystring=$keystring; $ckeystring=~s/(SOURCE\=\"[^"]*)\*/$1\\\*/g;
   72:         $ckeystring=~s/(TARGET\=\"[^"]*)\*/$1\\\*/g;
   73:         $info2=~/.*\<(?:metagroup|metasupergroup)\>(.*?)\<loncapa\s+$ckeystring\>(.*?)\<\/(?:metagroup|metasupergroup)\>/is;
   74: 	my $data=$1.$2;
   75:         my @meta=('description','build','dependencies','files','note');
   76:         foreach my $m (@meta) {
   77: 	    if ($data=~/\<($m)\>(.*?)\<\/$m\>/sgi) {
   78: 		my ($key,$value)=($1,$2);
   79: 		$info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{uc($key)}=
   80: 		                                                    $value;
   81: 	    }
   82:         }
   83:     }
   84:     else {
   85:         warn("WARNING: this tag text will be ignored since it cannot be understood\n---> $keystring\n");
   86:     }
   87: }
   88: 
   89: my $a;
   90: my @directories;
   91: if ($mode eq "HTML") {
   92:     $a=&begin_description_page;
   93:     print $a;
   94:     $a=&make_rpm_description_block;
   95:     print $a;
   96:     @directories=&determine_directory_structure;
   97:     $a=&make_directory_structure_description_block(\@directories);
   98:     print $a;
   99:     $a=&make_file_type_ownership_and_permissions_description_block;
  100:     print $a;
  101:     $a=&make_directory_and_file_structure_description_block(\@directories);
  102:     print $a;
  103:     $a=&end_description_page;
  104:     print $a;
  105: }
  106: elsif ($mode eq "SPEC") {
  107:     my $out=$info{'RPM'}{'Name'} . '-' . $info{'RPM'}{'Version'} . '.spec';
  108:     open OUT,">$out";
  109:     $a=&make_rpm_spec_block;
  110:     print OUT $a;
  111:     $a=&make_rpm_build_block;
  112:     print OUT $a;
  113:     @directories=&determine_directory_structure;
  114:     $a=&make_directory_structure_spec_block(\@directories);
  115:     print OUT $a;
  116:     $a=&make_directory_and_file_structure_spec_block(\@directories);
  117:     print OUT $a;
  118:     $a=&end_spec_page;
  119:     print OUT $a;
  120:     close OUT;
  121: }
  122: elsif ($mode eq "LCMakefile") {
  123:     @directories=&determine_directory_structure;
  124:     $a=&make_directory_install_segment(\@directories);
  125:     print $a;
  126:     $a=&make_files_install_segment(\@directories);
  127:     print $a;
  128:     $a=&make_links_install_segment(\@directories);
  129:     print $a;
  130: }
  131: elsif ($mode eq "BinaryRoot") {
  132:     mkdir "BinaryRoot",0755;
  133:     open OUT,">Makefile.BinaryRoot";
  134:     @directories=&determine_directory_structure;
  135:     $a=&make_directory_binaryroot_segment(\@directories);
  136:     print OUT $a;
  137:     $a=&make_files_binaryroot_segment(\@directories);
  138:     print OUT $a;
  139:     $a=&make_links_binaryroot_segment(\@directories);
  140:     print OUT $a;
  141:     close OUT;
  142:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' directories`;
  143:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' files`;
  144:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' links`;
  145:     open OUT,">base_file_list.txt";
  146:     $a=&make_file_list(\@directories);
  147:     print OUT $a;
  148:     close OUT;
  149:     
  150: }
  151: elsif ($mode eq "status") {
  152: }
  153: elsif ($mode eq "update") {
  154: }
  155: elsif ($mode eq "freshinstall") {
  156: }
  157: 
  158: # ------------------------------------------------------ a list of file targets
  159: sub make_file_list {
  160:     my ($dirs)=@_;
  161:     my $description;
  162:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  163:     foreach my $d (@$dirs) {
  164: 	# set other values
  165: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  166: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  167: 	# find files that are contained in this directory
  168: 	my @files;
  169: 	my @filesfull;
  170: 	foreach my $f (@allfiles) {
  171: 	    if ($f=~/^$d\/([^\/]+)$/) {
  172: 		push @files,$1;
  173: 		push @filesfull,$f;
  174: 	    }
  175: 	}
  176: 	# render starting HTML formatting elements
  177: 	if (@files) {
  178:         }
  179: 	my $pwd=`pwd`; chop $pwd;
  180: 	if (@files) {
  181:             foreach my $i (0..$#files) {
  182: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  183: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  184: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  185: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  186: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  187: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  188: 		my $rot="/".$filesfull[$i];
  189: 		if ($rot=~/\*/) {
  190: 		    $rot=~s/[^\/]+$// if $rot=~/\*/;
  191: 		    my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
  192: 		    chop $listing;
  193: 		    my @list=split(/\s+/,$listing);
  194: 		    my $rot2;
  195: 		    foreach my $l (@list) {
  196: 			$l=~s/^\s*//; $l=~s/\s*$//;
  197: 			$rot2.="BinaryRoot$rot$l\n" if length($l);
  198: 		    }
  199: 		    chop $rot2;
  200: 		    $rot=$rot2;
  201: 		}
  202: 		else {
  203: 		    $rot="BinaryRoot$rot";
  204: 		}
  205: 		$description.=<<END;
  206: $rot
  207: END
  208: 	    }
  209: 	}
  210:     }
  211:     $description.=<<END;
  212: 
  213: END
  214:     return $description;
  215: }
  216: 
  217: # --------------------------------- Commands to make BinaryRoot directories
  218: sub make_directory_binaryroot_segment {
  219:     my ($dirs)=@_;
  220:     my $description=<<END;
  221: directories:
  222: END
  223:     foreach my $d (@$dirs) {
  224: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  225: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  226: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  227: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  228: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  229: 	my $own=$devchown; $own=~s/\:/\,/;
  230: 	$description.=<<END;
  231: \tinstall -m $devchmod -d \$(TARGET)/$d
  232: END
  233:     }
  234:     $description.=<<END;
  235: 
  236: END
  237:     return $description;
  238: }
  239: 
  240: # --------------------------------------- Commands to make BinaryRoot files
  241: sub make_files_binaryroot_segment {
  242:     my ($dirs)=@_;
  243:     my $description=<<END;
  244: files:
  245: END
  246:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  247:     foreach my $d (@$dirs) {
  248: 	# set other values
  249: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  250: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  251: 	# find files that are contained in this directory
  252: 	my @files;
  253: 	my @filesfull;
  254: 	foreach my $f (@allfiles) {
  255: 	    if ($f=~/^$d\/([^\/]+)$/) {
  256: 		push @files,$1;
  257: 		push @filesfull,$f;
  258: 	    }
  259: 	}
  260: 	# render starting HTML formatting elements
  261: 	if (@files) {
  262: 	    $description.=<<END;
  263: \t# $d $dirdescription
  264: END
  265:         }
  266: 	if (@files) {
  267:             foreach my $i (0..$#files) {
  268: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  269: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  270: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  271: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  272: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  273: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  274: 		my $rot=$filesfull[$i];
  275: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  276: 		$description.=<<END if $category ne 'symbolic link';
  277: \tinstall -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  278: END
  279: 	    }
  280: 	}
  281:     }
  282:     $description.=<<END;
  283: 
  284: END
  285:     return $description;
  286: }
  287: 
  288: # ------------------------------ Commands to make BinaryRoot symbolic links
  289: sub make_links_binaryroot_segment {
  290:     my ($dirs)=@_;
  291:     my $description=<<END;
  292: links:
  293: END
  294:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  295:     foreach my $d (@$dirs) {
  296: 	# find files that are contained in this directory
  297: 	my @files;
  298: 	my @filesfull;
  299: 	foreach my $f (@allfiles) {
  300: 	    if ($f=~/^$d\/([^\/]+)$/) {
  301: 		push @files,$1;
  302: 		push @filesfull,$f;
  303: 	    }
  304: 	}
  305: 	# render starting HTML formatting elements
  306: 	if (@files) {
  307:             foreach my $i (0..$#files) {
  308: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  309: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  310: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  311: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  312: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  313: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  314: 		$description.=<<END if $category eq 'symbolic link';
  315: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
  316: END
  317: 	    }
  318: 	}
  319:     }
  320:     $description.=<<END;
  321: 
  322: END
  323:     return $description;
  324: }
  325: 
  326: # --------------------------------- Installation commands to install directories
  327: sub make_directory_install_segment {
  328:     my ($dirs)=@_;
  329:     my $description=<<END;
  330: directories:
  331: END
  332:     foreach my $d (@$dirs) {
  333: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  334: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  335: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  336: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  337: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  338: 	my $own=$devchown; $own=~s/\:/\,/;
  339: 	$description.=<<END;
  340: \tinstall -m $devchmod -d \$(SOURCE)/$d \$(ROOT)/$d
  341: END
  342:     }
  343:     $description.=<<END;
  344: 
  345: END
  346:     return $description;
  347: }
  348: 
  349: # --------------------------------------- Installation commands to install files
  350: sub make_files_install_segment {
  351:     my ($dirs)=@_;
  352:     my $description=<<END;
  353: files:
  354: END
  355:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  356:     foreach my $d (@$dirs) {
  357: 	# set other values
  358: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  359: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  360: 	# find files that are contained in this directory
  361: 	my @files;
  362: 	my @filesfull;
  363: 	foreach my $f (@allfiles) {
  364: 	    if ($f=~/^$d\/([^\/]+)$/) {
  365: 		push @files,$1;
  366: 		push @filesfull,$f;
  367: 	    }
  368: 	}
  369: 	# render starting HTML formatting elements
  370: 	if (@files) {
  371: 	    $description.=<<END;
  372: \t# $d $dirdescription
  373: END
  374:         }
  375: 	if (@files) {
  376:             foreach my $i (0..$#files) {
  377: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  378: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  379: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  380: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  381: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  382: 		my $rot=$filesfull[$i];
  383: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  384: 		$description.=<<END if $category ne 'symbolic link';
  385: \tinstall -m $devchmod \$(SOURCE)/$filesfull[$i] \$(ROOT)/$rot
  386: END
  387: 	    }
  388: 	}
  389:     }
  390:     $description.=<<END;
  391: 
  392: END
  393:     return $description;
  394: }
  395: 
  396: # ------------------------------ Installation commands to install symbolic links
  397: sub make_links_install_segment {
  398:     my ($dirs)=@_;
  399:     my $description=<<END;
  400: links:
  401: END
  402:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  403:     foreach my $d (@$dirs) {
  404: 	# find files that are contained in this directory
  405: 	my @files;
  406: 	my @filesfull;
  407: 	foreach my $f (@allfiles) {
  408: 	    if ($f=~/^$d\/([^\/]+)$/) {
  409: 		push @files,$1;
  410: 		push @filesfull,$f;
  411: 	    }
  412: 	}
  413: 	# render starting HTML formatting elements
  414: 	if (@files) {
  415:             foreach my $i (0..$#files) {
  416: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  417: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  418: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  419: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  420: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  421: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  422: 		$description.=<<END if $category eq 'symbolic link';
  423: \tln -s /$linkto \$(ROOT)/$filesfull[$i]
  424: END
  425: 	    }
  426: 	}
  427:     }
  428:     $description.=<<END;
  429: 
  430: END
  431:     return $description;
  432: }
  433: 
  434: # --------------------------------------------------------- Make RPM .spec block
  435: sub make_rpm_spec_block {
  436:     my $pwd=`pwd`; chop $pwd;
  437:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  438:     my $source=$info{'RPM'}{'Name'} . "-" . $info{'RPM'}{'Version'} . '.tar.gz';
  439:     my $description=<<END;
  440: Summary: $info{'RPM'}{'Summary'}
  441: Name: $info{'RPM'}{'Name'}
  442: Version: $info{'RPM'}{'Version'}
  443: Release: $info{'RPM'}{'Release'}
  444: Vendor: $info{'RPM'}{'Vendor'} 
  445: BuildRoot: $buildroot
  446: Copyright: $info{'RPM'}{'Copyright'}
  447: Group: $info{'RPM'}{'Group'}
  448: Source: $source
  449: AutoReqProv: $info{'RPM'}{'AutoReqProv'}
  450: \%description
  451: $info{'RPM'}{'description'}
  452: 
  453: END
  454:     return $description;
  455: }
  456: 
  457: # --------------------------------------------------- Make RPM build .spec block
  458: sub make_rpm_build_block {
  459:     my $pwd=`pwd`; chop $pwd;
  460:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  461:     my $sourceroot="$pwd/LON-CAPA-SourceRoot";
  462:     my $description=<<END;
  463: 
  464: \%prep
  465: \%setup
  466: 
  467: \%build
  468: rm -Rf "$buildroot"
  469: 
  470: \%install
  471: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" directories
  472: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" files
  473: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" links
  474: 
  475: \%pre
  476: $info{'RPM'}{'pre'}
  477: 
  478: \%post
  479: \%postun
  480: 
  481: \%files
  482: # \%doc README COPYING ChangeLog LICENSE
  483: END
  484:     return $description;
  485: }
  486: 
  487: # ------------------------------------- Make directory structure RPM .spec block
  488: sub make_directory_structure_spec_block {
  489:     my ($dirs)=@_;
  490:     foreach my $d (@$dirs) {
  491: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  492: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  493: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  494: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  495: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  496: 	my $own=$devchown; $own=~s/\:/\,/;
  497: 	$description.=<<END;
  498: \%dir \%attr($devchmod,$own) /$d
  499: END
  500:     }
  501:     return $description;
  502: }
  503: 
  504: # ---------------------------- Make directory and file structure RPM .spec block
  505: sub make_directory_and_file_structure_spec_block {
  506:     my ($dirs)=@_;
  507:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  508:     foreach my $d (@$dirs) {
  509: 	# set other values
  510: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  511: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  512: 	# find files that are contained in this directory
  513: 	my @files;
  514: 	my @filesfull;
  515: 	foreach my $f (@allfiles) {
  516: 	    if ($f=~/^$d\/([^\/]+)$/) {
  517: 		push @files,$1;
  518: 		push @filesfull,$f;
  519: 	    }
  520: 	}
  521: 	# render starting HTML formatting elements
  522: 	if (@files) {
  523: 	    $description.=<<END;
  524: # $d $dirdescription
  525: END
  526:         }
  527: 	if (@files) {
  528:             foreach my $i (0..$#files) {
  529: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  530: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  531: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  532: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  533: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  534: 		my $own=$devchown; $own=~s/\:/\,/;
  535: 		my $config="";
  536: 		$config="\%config " if $category eq 'conf';
  537: 		$devchmod='-' if $category eq 'symbolic link';
  538: 		$description.=<<END;
  539: $config\%attr($devchmod,$own) /$filesfull[$i]
  540: END
  541: 	    }
  542: 	}
  543:     }
  544:     return $description;
  545: }
  546: 
  547: # ----------------------------------------------------------- End RPM .spec page
  548: sub end_spec_page {
  549: }
  550: 
  551: # ------------------------------------------------------- Begin description page
  552: sub begin_description_page {
  553:     my $description=<<END;
  554: <HTML>
  555: <HEAD>
  556: <TITLE>LON-CAPA Software Description Page ($distribution, $date)</TITLE>
  557: </HEAD>
  558: <BODY>
  559: <FONT SIZE=+2>LON-CAPA Software Description Page ($distribution, $date)</FONT>
  560: <BR>Michigan State University
  561: <BR>Learning Online with CAPA
  562: <BR>Contact korte\@lon-capa.org
  563: <UL>
  564: <LI>About this file
  565: <LI>Software Package Description
  566: <LI>Directory Structure
  567: <LI>File Type Ownership and Permissions
  568: <LI>File and Directory Structure
  569: </UL>
  570: <FONT SIZE=+2>About this file</FONT>
  571: <P>
  572: This file is generated dynamically by <TT>parse.pl</TT> as
  573: part of a development compilation process.  See 
  574: http://install.lon-capa.org/compile/index.html for more
  575: information.
  576: </P>
  577: END
  578:     return $description;
  579: }
  580: 
  581: # ------------------------------------------------- End description page
  582: sub end_description_page {
  583:     my $description=<<END;
  584: <HR>
  585: <FONT SIZE=-1>LON-CAPA Software Development Team</FONT>
  586: </BODY>
  587: </HTML>
  588: END
  589:     return $description;
  590: }
  591: 
  592: # ------------------------------------------------- Make RPM description block
  593: sub make_rpm_description_block {
  594:     my $description=<<END;
  595: <FONT SIZE=+2>Rolled in a RedHat 6.2 RPM, $date</FONT>
  596: <P>
  597: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
  598: <TR><TD>
  599: <PRE>
  600: Name        : $info{'RPM'}{'Name'}
  601: Version     : $info{'RPM'}{'Version'}
  602: Vendor      : $info{'RPM'}{'Vendor'} 
  603: Release     : $info{'RPM'}{'Release'}                             
  604: Build Host  : $buildhost
  605: Group       : $info{'RPM'}{'Group'}
  606: License     : $info{'RPM'}{'Copyright'}
  607: Summary     : $info{'RPM'}{'Summary'}
  608: Description : 
  609: $info{'RPM'}{'description'}
  610: </PRE>
  611: </TD></TR>
  612: </TABLE>
  613: </P>
  614: END
  615:     return $description;
  616: }
  617: 
  618: # ----------------------------------------------- Determine directory structure
  619: sub determine_directory_structure {
  620:     my @directories=keys %{$info{'DIRECTORY'}{$distribution}};
  621:     return (sort @directories);
  622: }
  623: 
  624: 
  625: # ---------------------------------- Make directory structure description block
  626: sub make_directory_structure_description_block {
  627:     my ($dirs)=@_;
  628:     my $description=<<END;
  629: <FONT SIZE=+2>Directory Structure Description, $date</FONT>
  630: <P>
  631: The directory structure description below shows only those
  632: directories which either contain LON-CAPA specific files
  633: or normally do not exist on a RedHat Linux system (and
  634: must be generated to allow proper placement of files
  635: during LON-CAPA run-time operation).
  636: </P>
  637: <P>
  638: <TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
  639: END
  640:     my $maxcount=0;
  641:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  642:     my %diraccount; # hash to track which directories are accounted for
  643:     foreach my $file (@allfiles) {
  644: 	$file=~/^(.*)\/([^\/]+)$/;
  645: 	$diraccount{$1}=1;
  646:     }
  647:     foreach my $d (@$dirs) {
  648:         my (@matches)=($d=~/\//g);
  649: 	my $count=scalar(@matches);
  650: 	$maxcount=$count if $count>$maxcount;
  651: 	delete $diraccount{$d};
  652:     }
  653:     $description.=<<END;
  654: <TR>
  655: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Category</TH>
  656: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
  657: <TH ALIGN=LEFT BGCOLOR=#FFFFFF><FONT COLOR=#FF0000>Development<BR>Permissions</FONT></TH>
  658: END
  659:     $description.="<TH ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+1).">Directory Path</TH>\n";
  660:     if (keys %diraccount) {
  661: 	$description.= "<TR><TD ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+4)."><I><PRE>Directories that are unaccounted for: \n";
  662: 	foreach my $d (keys %diraccount) {
  663: 	    $description.="$d\n";
  664: 	}
  665: 	$description.="</PRE></I></TH></TR>\n";
  666:     }
  667:     foreach my $d (@$dirs) {
  668: 	my $dtable=$d;
  669: 	$dtable=~s/\//\<\/TD\>\<TD\>/g;
  670: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  671: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  672: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  673: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  674: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  675: 	$description.=<<END;
  676: <TR>
  677: <TD BGCOLOR=#FFFFFF>$category</TD>
  678: <TD BGCOLOR=#FFFFFF><TT>$chmod $chown</TT></TD>
  679: <TD BGCOLOR=#FFFFFF><FONT COLOR=#FF0000><TT>$devchmod $devchown</TT></FONT></TD>
  680: <TD>
  681: $dtable
  682: </TD>
  683: </TR>
  684: END
  685:     }
  686:     $description.=<<END;
  687: </TABLE>
  688: </P>
  689: END
  690:     return $description;
  691: }
  692: 
  693: # ------------------- Make file type ownership and permissions description block
  694: sub make_file_type_ownership_and_permissions_description_block {
  695:     my $description=<<END;
  696: <FONT SIZE=+2>File Type Ownership and Permissions Descriptions, $date</FONT>
  697: <P>
  698: This table shows what permissions and ownership settings correspond
  699: to each kind of file type.
  700: </P>
  701: <P>
  702: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
  703: <TR>
  704: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Icon</TH>
  705: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Type</TH>
  706: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
  707: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Development Permissions</TH>
  708: </TR>
  709: END
  710:     foreach my $type (keys %{$info{'OWNERSHIP'}}) {
  711: 	if (defined($fcm{$type})) {
  712: 	    my $chmod=$info{'OWNERSHIP'}{$type}{'CHMOD'};
  713: 	    my $chown=$info{'OWNERSHIP'}{$type}{'CHOWN'};
  714: 	    my $devchmod=$info{'DEVOWNERSHIP'}{$type}{'CHMOD'};
  715: 	    my $devchown=$info{'DEVOWNERSHIP'}{$type}{'CHOWN'};
  716: 	    $description.=<<END;
  717: <TR>
  718: <TD><IMG SRC="$fcm{$type}.gif" ALT="$type"></TD>
  719: <TD>$type</TD>
  720: <TD><TT>$chmod $chown</TT></TD>
  721: <TD><TT>$devchmod $devchown</TT></TD>
  722: </TR>
  723: END
  724:         }
  725:     }
  726:     $description.=<<END;
  727: </TABLE>
  728: </P>
  729: END
  730: }
  731: 
  732: # ------------------------- Make directory and file structure description block
  733: sub make_directory_and_file_structure_description_block {
  734:     my ($dirs)=@_;
  735:     my $description=<<END;
  736: <FONT SIZE=+2>Directory and File Structure Description, $date</FONT>
  737: <P>
  738: The icons on the left column correspond to the file type
  739: specified in the second column.  The last column "Notes" shows compilation,
  740: dependency, and configuration information.  The CVS location
  741: shows the location of the binary source file (if applicable) needed to
  742: be copied to the target.  If the binary source file is not at
  743: the specified location, then the text is shown in 
  744: <FONT COLOR=#FF0000>red</FONT>.
  745: </P>
  746: <P>
  747: <TABLE BORDER=1 CELLPADDING=5 WIDTH=500>
  748: END
  749:     my $counter=0;
  750:     my @colorindex=("#80FF80","#80FFFF","#FFFF80");
  751:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  752:     foreach my $d (@$dirs) {
  753: 	# set color
  754: 	my $color=$colorindex[$counter%3];
  755: 	# set other values
  756: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  757: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  758: 	# find subdirectories that are contained in this directory
  759: 	my @subdirs;
  760: 	foreach my $d2 (@$dirs) {
  761: 	    if ($d2=~/^$d\/([^\/]+)$/) {
  762: 		push @subdirs,$1;
  763: 	    }
  764: 	}
  765: 	# find files that are contained in this directory
  766: 	my @files;
  767: 	my @filesfull;
  768: 	foreach my $f (@allfiles) {
  769: 	    if ($f=~/^$d\/([^\/]+)$/) {
  770: 		push @files,$1;
  771: 		push @filesfull,$f;
  772: 	    }
  773: 	}
  774: 	# render starting HTML formatting elements
  775: 	if (@subdirs || @files) {
  776: 	    my $subdirstring="<BR>* Relevant subdirectories: " . join(", ",@subdirs) if @subdirs;
  777: 	    $description.=<<END;
  778: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="directory.gif" ALT="directory">DIRECTORY -- $d $dirdescription
  779: $subdirstring</FONT></TD></TR>
  780: END
  781:         }
  782: 	else {
  783: 	    $description.=<<END;
  784: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="emptydirectory.gif" ALT="empty directory">EMPTY DIRECTORY - $d $dirdescription</FONT></TD></TR>
  785: END
  786:         }
  787: 	if (@files) {
  788: 	    $description.=<<END;
  789: <TR>
  790: <TH BGCOLOR=$color ALIGN=LEFT COLSPAN=2>Type</TH>
  791: <TH BGCOLOR=$color ALIGN=LEFT>File Name</TH>
  792: <TH BGCOLOR=$color ALIGN=LEFT>Function</TH>
  793: <TH BGCOLOR=$color ALIGN=LEFT>CVS Location</TH>
  794: <TH BGCOLOR=$color ALIGN=LEFT>Notes</TH>
  795: </TR>
  796: END
  797:             foreach my $i (0..$#files) {
  798: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  799: 		my $fdescription=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DESCRIPTION'};
  800: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  801: 		my $note=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'NOTE'};
  802: 		$note.="<BR>" if $note;
  803: 		my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
  804: 		my @E=split(/\s+/,$listing);
  805: 		$source=~/(.*)\/[^\/]+$/;
  806: 		my $sd=$1;
  807: 		my $eflag=0;
  808: 		foreach my $e (@E) {
  809: 		    unless (-e "../../$sd/$e") {
  810: 			$e="<FONT COLOR=#FF0000>$e</FONT>";
  811: 			$eflag=1;
  812: 		    }
  813: 		}
  814: 		$listing=join("\n",@E);
  815: 		$listing="<B>listing</B><BR><FONT SIZE=-2>$listing</FONT>" if $listing;
  816: 		$listing.="<BR>" if $listing;
  817: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
  818: 		$build="<B>build</B><BR>$build" if $build;
  819: 		$build.="<BR>" if $build;
  820: 		my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
  821: 		$dependencies="<B>dependencies</B><BR>$dependencies" if $dependencies;
  822: 		$dependencies.="<BR>" if $dependencies;
  823: 		unless (-e "../../$source") {
  824: 		    $source=~/([^\/]+)$/;
  825: 		    my $s=$1;
  826: 		    if ($source!~/\*/) {
  827: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
  828: 		    }
  829: 		    elsif ($eflag) {
  830: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
  831: 		    }
  832: 		}
  833: 		$description.=<<END;
  834: <TR>
  835: <TD BGCOLOR=#A0A0A0><IMG SRC="$fcm{$category}.gif" ALT="$category"></TD>
  836: <TD BGCOLOR=$color>$category</TD>
  837: <TD BGCOLOR=$color>$files[$i]</TD>
  838: <TD BGCOLOR=$color>$fdescription&nbsp;</TD>
  839: <TD BGCOLOR=$color>$source</TD>
  840: <TD BGCOLOR=$color>$note$listing$build$dependencies&nbsp;</TD>
  841: </TR>
  842: END
  843: 	    }
  844: 	}
  845: 	$counter++;
  846:     }
  847:     $description.=<<END;
  848: </TABLE>
  849: </P>
  850: END
  851:     return $description;
  852: }

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