Check-in [e7e77fdcbc]
Overview
Comment:Updated to build additional HTML files
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e7e77fdcbc07662877bc63be883dc9645cfe2ce3
User & Date: rkeene on 2010-02-09 21:03:20
Other Links: manifest | tags
Context
2010-02-09
21:19
Updated to only produce TPM header if the package info is complete check-in: a29f966f9d user: rkeene tags: trunk
21:03
Updated to build additional HTML files check-in: e7e77fdcbc user: rkeene tags: trunk
15:58
Fixed building sqlite3 on non-GNU platforms check-in: bd843fe232 user: rkeene tags: trunk
Changes

Modified server/teapot_index from [3523082fbc] to [4eb6497cd6].

     4      4   	puts stderr "Usage: teapot_index <srcdir> <destdir>"
     5      5   	exit 1
     6      6   }
     7      7   
     8      8   set srcdir [file normalize [lindex $argv 0]]
     9      9   set dstdir [file normalize [lindex $argv 1]]
    10     10   
           11  +# Define requirements for entities
           12  +## Must be sync'd with [teapot_index]
           13  +set entity_definition(package) [list name ver arch]
           14  +
           15  +# Define maping of field name to text
           16  +set entity_fieldnames([list package name]) "Name"
           17  +set entity_fieldnames([list package ver]) "Version"
           18  +set entity_fieldnames([list package arch]) "Platform"
           19  +set entity_fieldnames([list entity]) "What"
           20  +
    11     21   # Index all packages
    12     22   proc teapot_index {srcdir} {
    13     23   	array set pkginfo [list]
    14     24   
    15     25   	foreach pkgdir [glob -directory $srcdir -type d */out/*] {
    16     26   		unset -nocomplain currpkginfo
    17     27   		set currpkginfo(pkgdir) $pkgdir
................................................................................
    85     95   		set pkginfo([list $currpkginfo(name) $currpkginfo(vers) $currpkginfo(platform)]) [array get currpkginfo]
    86     96   	}
    87     97   
    88     98   	return [array get pkginfo]
    89     99   }
    90    100   
    91    101   proc generate_tpm {entlist} {
          102  +	set pkgs [list]
          103  +	foreach part $entlist {
          104  +		set pkginfo [list]
          105  +		foreach enttype $part {
          106  +			set pkg [lindex $enttype 0]
          107  +			lappend pkginfo $pkg
          108  +		}
          109  +		lappend pkgs $pkginfo
          110  +	}
          111  +
    92    112   	set ret {<!-- [[TPM[[}
    93         -	append ret $entlist
          113  +	append ret $pkgs
    94    114   	append ret {]]MPT]] -->}
    95    115   
    96    116   	return $ret
    97    117   }
          118  +
          119  +proc complete_entpath {type entinfo_arrlist} {
          120  +	array set entinfo $entinfo_arrlist
          121  +
          122  +	set req_fields $::entity_definition($type)
          123  +
          124  +	set retval [list $type]
          125  +
          126  +	foreach req_field $req_fields {
          127  +		if {![info exists entinfo($req_field)]} {
          128  +			return ""
          129  +		}
          130  +
          131  +		lappend retval $req_field $entinfo($req_field)
          132  +	}
          133  +
          134  +	return $retval
          135  +}
    98    136   
    99    137   proc generate_table {fields numitems} {
   100    138   	set ret ""
   101    139   
   102    140   	foreach field $fields {
   103    141   		append ret "      <tr>\n"
   104    142   
   105         -		foreach part [lrange $field 0 [expr $numitems - 1]] {
   106         -			append ret "        <td>$part</td>\n"
          143  +		unset -nocomplain entinfo
          144  +		foreach enttype [lrange $field 0 [expr $numitems - 1]] {
          145  +			set item [lindex $enttype 0]
          146  +			set type [lindex $enttype 1]
          147  +
          148  +			set entinfo($type) $item
          149  +		}
          150  +
          151  +		if {[info exists entinfo(entity)]} {
          152  +			set entity_type $entinfo(entity)
          153  +
          154  +			set req_fields $::entity_definition($entity_type)
          155  +		}
          156  +
          157  +		set entpath_parts [list]
          158  +
          159  +		foreach enttype [lrange $field 0 [expr $numitems - 1]] {
          160  +			set item [lindex $enttype 0]
          161  +			set type [lindex $enttype 1]
          162  +
          163  +			if {$type != "entity"} {
          164  +				lappend entpath_parts $type $item
          165  +			}
          166  +
          167  +			set complete_entpath_parts ""
          168  +			if {[info exists entity_type]} {
          169  +				set complete_entpath_parts [complete_entpath $entity_type $entpath_parts]
          170  +			}
          171  +
          172  +			if {$complete_entpath_parts == ""} {
          173  +				set entpath [join [join [list entity $entpath_parts]] /]
          174  +			} else {
          175  +				set entpath [join $complete_entpath_parts /]
          176  +			}
          177  +
          178  +			append ret "        <td><a href=\"/$entpath\">$item</a></td>\n"
   107    179   		}
   108    180   
   109    181   		append ret "      </tr>\n"
   110    182   	}
   111    183   
   112    184   	return [string range $ret 0 end-1]
   113    185   }
   114    186   
   115    187   # Create "index.html"
   116    188   proc create_output_index {dstdir pkginfo_arrlist} {
   117    189   	array set pkginfo $pkginfo_arrlist
   118    190   
   119    191   	set indexfile [file join $dstdir index.html]
          192  +	set altindexfile [file join $dstdir entity index.html]
   120    193   
   121    194   	set pkglist [list]
   122    195   	foreach ent [array names pkginfo] {
   123    196   		set pkg [lindex $ent 0]
   124         -		if {[lsearch -exact $pkglist $pkg] != -1} {
          197  +		set addent [list [list $pkg name]]
          198  +		if {[lsearch -exact $pkglist $addent] != -1} {
   125    199   			continue
   126    200   		}
   127    201   
   128         -		lappend pkglist $pkg
          202  +		lappend pkglist $addent
   129    203   	}
          204  +
          205  +	set pkglist [lsort -dictionary $pkglist]
   130    206   
   131    207   	set fd [open $indexfile w]
   132    208   	puts $fd "<html>"
   133    209   	puts $fd "  <head>"
   134    210   	puts $fd "    <title>List of all entities</title>"
   135    211   	puts $fd "  </head>"
   136    212   	puts $fd "  <body>"
................................................................................
   138    214   	puts $fd "    <h1>List of all entities</h1>"
   139    215   	puts $fd "    <table>"
   140    216   	puts $fd [generate_table $pkglist 1]
   141    217   	puts $fd "    </table>"
   142    218   	puts $fd "  </body>"
   143    219   	puts $fd "</html>"
   144    220   	close $fd
          221  +
          222  +	file delete -- $altindexfile
          223  +	file mkdir [file dirname $altindexfile]
          224  +	file link -hard $altindexfile $indexfile
   145    225   }
   146    226   
   147    227   # Create "package/list"
   148    228   proc create_output_pkglist {dstdir pkginfo_arrlist} {
   149    229   	array set pkginfo $pkginfo_arrlist
   150    230   
   151    231   	set pkgdir [file join $dstdir package]
................................................................................
   157    237   
   158    238   	set pkglist [list]
   159    239   	foreach ent [array names pkginfo] {
   160    240   		set pkg [lindex $ent 0]
   161    241   		set ver [lindex $ent 1]
   162    242   		set arch [lindex $ent 2]
   163    243   
   164         -		lappend pkglist [list package $pkg $ver $arch 0]
          244  +		lappend pkglist [list [list package entity] [list $pkg name] [list $ver ver] [list $arch arch] [list 0 unknown]]
   165    245   	}
          246  +
          247  +	set pkglist [lsort -dictionary $pkglist]
   166    248   
   167    249   	set fd [open $indexfile w]
   168    250   	puts $fd "<html>"
   169    251   	puts $fd "  <head>"
   170    252   	puts $fd "    <title>List of all packages</title>"
   171    253   	puts $fd "  </head>"
   172    254   	puts $fd "  <body>"
................................................................................
   181    263   	puts $fd "      </tr>"
   182    264   	puts $fd [generate_table $pkglist 4]
   183    265   	puts $fd "    </table>"
   184    266   	puts $fd "  </body>"
   185    267   	puts $fd "</html>"
   186    268   	close $fd
   187    269   
   188         -	file delete $altindexfile
          270  +	file delete -- $altindexfile
   189    271   	file link -hard $altindexfile $indexfile
   190    272   }
   191    273   
   192    274   # Create "package/name/<pkg>/ver/<ver>/arch/<arch>/file"
   193    275   proc create_output_files {dstdir pkginfo_arrlist {force 0}} {
   194    276   	array set pkginfo $pkginfo_arrlist
   195    277   
................................................................................
   214    296   			if {[file exists $extfile] && !$force} {
   215    297   				continue
   216    298   			}
   217    299   
   218    300   			if {[catch {
   219    301   				cd $pkgdir
   220    302   
   221         -				file delete $extfile
          303  +				file delete -- $extfile
   222    304   				exec zip -r $extfile . -x build.log
   223    305   			} err]} {
   224    306   				puts "Error while zipping: $err"
   225    307   			}
   226    308   		} else {
   227    309   			set origfile [lindex [glob $pkgdir *] 0]
   228    310   
   229    311   			file copy -force -- $origfile $extfile
   230    312   		}
   231    313   
   232         -		file delete $regfile
          314  +		file delete -- $regfile
   233    315   		file link -hard $regfile $extfile
   234    316   	}
   235    317   }
          318  +
          319  +proc create_entity_file {entity dstdir pkginfo_arrlist} {
          320  +	array set pkginfo $pkginfo_arrlist
          321  +	array set entinfo $entity
          322  +
          323  +	if {![info exists entinfo(entity)]} {
          324  +		return
          325  +	}
          326  +
          327  +	set entity_type $entinfo(entity)
          328  +	set req_fields $::entity_definition($entity_type)
          329  +
          330  +	set complete 1
          331  +	set pkgpat [list]
          332  +	set dispfields [list]
          333  +	foreach req_field $req_fields {
          334  +		if {![info exists entinfo($req_field)]} {
          335  +			set complete 0
          336  +
          337  +			lappend pkgpat "*"
          338  +				if {![info exists pkgnextlevel]} {
          339  +				set pkgnextlevel $req_field
          340  +				lappend dispfields $req_field
          341  +			}
          342  +		} else {
          343  +			lappend pkgpat $entinfo($req_field)
          344  +			lappend dispfields $req_field
          345  +		}
          346  +	}
          347  +
          348  +	if {$complete} {
          349  +		set entpath_parts [list $entity_type]
          350  +
          351  +		foreach req_field $req_fields {
          352  +			lappend entpath_parts $req_field $entinfo($req_field)
          353  +		}
          354  +	} else {
          355  +		set entpath_parts [list entity]
          356  +
          357  +		foreach req_field $req_fields {
          358  +			if {[info exists entinfo($req_field)]} {
          359  +				lappend entpath_parts $req_field $entinfo($req_field)
          360  +			}
          361  +		}
          362  +	}
          363  +
          364  +	set entpath [join $entpath_parts /]
          365  +
          366  +	if {[string match "/*" $entpath]} {
          367  +		return
          368  +	}
          369  +
          370  +	set indexfile [file join $dstdir $entpath index.html]
          371  +	set tmpindexfile [file join $dstdir $entpath index.html.tmp]
          372  +
          373  +	catch {
          374  +		file mkdir [file dirname $indexfile]
          375  +	}
          376  +
          377  +	set fd [open $tmpindexfile w]
          378  +
          379  +	puts $fd "<html>"
          380  +	puts $fd "  <head>"
          381  +	puts $fd "    <title>"
          382  +	puts $fd "    </title>"
          383  +	puts $fd "  </head>"
          384  +	puts $fd "  <body>"
          385  +
          386  +	set pkglist [list]
          387  +	if {!$complete} {
          388  +		foreach pkgent [array names pkginfo $pkgpat] {
          389  +			unset -nocomplain currpkginfo
          390  +			for {set idx 0} {$idx < [llength $req_fields]} {incr idx} {
          391  +				set field [lindex $req_fields $idx]
          392  +				set value [lindex $pkgent $idx]
          393  +				set currpkginfo($field) $value
          394  +			}
          395  +
          396  +			set currpkgdata [list [list $entity_type entity]]
          397  +			foreach dispfield $dispfields {
          398  +				lappend currpkgdata [list $currpkginfo($dispfield) $dispfield]
          399  +			}
          400  +
          401  +			if {[lsearch -exact $pkglist $currpkgdata] != -1} {
          402  +				continue
          403  +			}
          404  +
          405  +			lappend pkglist $currpkgdata
          406  +		}
          407  +
          408  +		puts $fd [generate_tpm $pkglist]
          409  +
          410  +		puts $fd "    <h1>$pkgnextlevel</h1>"
          411  +		puts $fd "    <table>"
          412  +		puts $fd "    <tr>"
          413  +		foreach dispfield [join [list entity $dispfields]] {
          414  +			if {[info exists ::entity_fieldnames([list $entity_type $dispfield])]} {
          415  +				set dispfieldheader $::entity_fieldnames([list $entity_type $dispfield])
          416  +			} else {
          417  +				set dispfieldheader $::entity_fieldnames([list $dispfield])
          418  +			}
          419  +			puts $fd "      <th>$dispfieldheader</th>"
          420  +		}
          421  +		puts $fd "    </tr>"
          422  +
          423  +		puts $fd [generate_table $pkglist 10]
          424  +
          425  +		puts $fd "    </table>"
          426  +	} else {
          427  +		set dispname_list [list]
          428  +		set pathname_list [list $entity_type]
          429  +		foreach field $req_fields {
          430  +			lappend dispname_list $entinfo($field)
          431  +			lappend pathname_list $field $entinfo($field)
          432  +		}
          433  +		set key $dispname_list
          434  +		array set currpkginfo $pkginfo($key)
          435  +
          436  +		set pathname_dir "[join $pathname_list /]"
          437  +		set pathname_dirlocal [file join $dstdir $pathname_dir]
          438  +		set pathname_tail $currpkginfo(extfile)
          439  +		if {$pathname_tail == ""} {
          440  +			set pathname_tail "file"
          441  +		}
          442  +		set pathname_uri "/$pathname_dir/$pathname_tail"
          443  +
          444  +		puts $fd "    <h1>Details of $entity_type [join $dispname_list]</h1>"
          445  +		puts $fd "    <p><a href=\"$pathname_uri\">Package archive</a></p>"
          446  +		puts $fd "    <p>Details</p>"
          447  +		puts $fd "    <table border=\"1\">"
          448  +		puts $fd "      <tr>"
          449  +		puts $fd "        <th>Key</th>"
          450  +		puts $fd "        <th>Value</th>"
          451  +		puts $fd "      </tr>"
          452  +
          453  +		foreach descfield [list rsk::build::date category description license platform require summary] {
          454  +			if {![info exists currpkginfo($descfield)]} {
          455  +				continue
          456  +			}
          457  +			set descval $currpkginfo($descfield)
          458  +			switch -- $descfield {
          459  +				"require" {
          460  +					catch {
          461  +						set descval [join $descval {, }]
          462  +					}
          463  +				}
          464  +			}
          465  +
          466  +			puts $fd "      <tr>"
          467  +			puts $fd "        <td>$descfield</td>"
          468  +
          469  +			puts $fd "        <td>$descval</td>"
          470  +			puts $fd "      </tr>"
          471  +		}
          472  +		puts $fd "    </table>"
          473  +	}
          474  +
          475  +	puts $fd "  </body>"
          476  +	puts $fd "</html>"
          477  +
          478  +	close $fd
          479  +
          480  +	file rename -force -- $tmpindexfile $indexfile
          481  +}
          482  +
          483  +proc create_all_entity_files {dstdir pkginfo_arrlist} {
          484  +	set entfields $::entity_definition(package)
          485  +
          486  +	array set pkginfo $pkginfo_arrlist
          487  +
          488  +	set seen_entities [list]
          489  +	foreach pkgdata [lsort -dictionary [array names pkginfo]] {
          490  +		unset -nocomplain entity
          491  +		lappend entity entity package
          492  +
          493  +		for {set endidx 0} {$endidx < [llength $entfields]} {incr endidx} {
          494  +			lappend entity [lindex $entfields $endidx]
          495  +			lappend entity [lindex $pkgdata $endidx]
          496  +
          497  +			if {[lsearch -exact $seen_entities $entity] != -1} {
          498  +				continue
          499  +			}
          500  +			lappend seen_entities $entity
          501  +
          502  +			create_entity_file $entity $dstdir $pkginfo_arrlist
          503  +		}
          504  +	}
          505  +}
   236    506   
   237    507   set pkginfo [teapot_index $srcdir]
   238    508   create_output_index $dstdir $pkginfo
   239    509   create_output_pkglist $dstdir $pkginfo
   240    510   create_output_files $dstdir $pkginfo
          511  +create_all_entity_files $dstdir $pkginfo