cookutils diff lighttpd/index.cgi @ rev 940

cook: improve patchit() and all_names(); modules/deps: change the cases upside down, show update stats (it not hangs); lighttpd/index.cgi: use split.db to make search datalist, and to search packages (no need to `ls` ~ 5000 dirs, just one file); lighttpd/cooker.css: style the matches in search page.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jun 22 20:18:08 2017 +0300 (2017-06-22)
parents 5ae6788158f0
children adda5217f721
line diff
     1.1 --- a/lighttpd/index.cgi	Tue Jun 20 03:52:01 2017 +0300
     1.2 +++ b/lighttpd/index.cgi	Thu Jun 22 20:18:08 2017 +0300
     1.3 @@ -31,6 +31,7 @@
     1.4  cooktime="$CACHE/cooktime"
     1.5  wokrev="$CACHE/wokrev"
     1.6  webstat="$CACHE/webstat"
     1.7 +splitdb="$CACHE/split.db"
     1.8  
     1.9  # Path to markdown to html convertor
    1.10  cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
    1.11 @@ -555,15 +556,11 @@
    1.12  
    1.13  
    1.14  datalist() {
    1.15 -	(
    1.16 -		cd $wok
    1.17 -
    1.18 -		ls | awk '
    1.19 +	cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
    1.20  		BEGIN{printf("<datalist id=\"packages\">")}
    1.21 -		     {printf("<option>%s</option>",$1)}
    1.22 +		     {printf("<option>%s",$1)}
    1.23  		END  {printf("</datalist>")}
    1.24  		'
    1.25 -	)
    1.26  }
    1.27  
    1.28  
    1.29 @@ -740,6 +737,7 @@
    1.30  
    1.31  # Update statistics used in web interface.
    1.32  # There is no need to recalculate the statistics every time the page is displayed.
    1.33 +# Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
    1.34  
    1.35  update_webstat() {
    1.36  	echo '<div id="waitme">'
    1.37 @@ -975,33 +973,53 @@
    1.38  case "$cmd" in
    1.39  	'')
    1.40  		page_header
    1.41 -		log=$LOGS/$pkg.log
    1.42  
    1.43  		# Package info.
    1.44 -		if [ -f "$wok/$pkg/receipt" ]; then
    1.45 -			pkg_info
    1.46 -		else
    1.47 -			if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
    1.48 -				echo "<h2>Not Found</h2>"
    1.49 -				show_note e "The requested package <b>$pkg</b> was not found on this server."
    1.50 -			else
    1.51 -				# Search page
    1.52 +		if [ ! -f "$wok/$pkg/receipt" ]; then
    1.53 +			# Let's look at the cases when the package was not found
    1.54 +
    1.55 +			# Maybe query is the exact name of split package? -> proceed to main package
    1.56 +			mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
    1.57 +				if (index(" " $2 " ", pkg)) {print $1; exit}
    1.58 +			}' $splitdb)
    1.59 +
    1.60 +			# No, so let's find any matches among packages names (both main and split)
    1.61 +			if [ -z "$mainpkg" ]; then
    1.62 +				pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
    1.63 +				# Nothing matched
    1.64 +				if [ -z "$pkgs" ]; then
    1.65 +					echo "<h2>Not Found</h2>"
    1.66 +					show_note e "The requested package <b>$pkg</b> was not found on this server."
    1.67 +					page_footer; exit 0
    1.68 +				fi
    1.69 +				# Search results page
    1.70  				echo "<section><h2>Package names matching “$pkg”</h2>"
    1.71  				echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
    1.72 -				for i in $(cd $wok; ls *$pkg*/receipt); do
    1.73 -					pkg=$(dirname $i)
    1.74 +				query="$pkg"
    1.75 +				for pkg in $pkgs; do
    1.76 +					# Find main package
    1.77 +					mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
    1.78 +						if (index(" " $2 " ", pkg)) {print $1; exit}
    1.79 +					}' $splitdb)
    1.80 +					unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
    1.81 +
    1.82  					unset SHORT_DESC CATEGORY
    1.83 -					. $wok/$pkg/receipt
    1.84 -					echo -n "<tr><td><a href="$base/$pkg">$pkg</a></td>"
    1.85 -					echo -n "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
    1.86 +					[ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
    1.87 +						. $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
    1.88 +
    1.89 +					echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
    1.90 +					[ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
    1.91 +					echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
    1.92  				done
    1.93  				echo '</tbody></table></section>'
    1.94 -				unset pkg
    1.95 +				page_footer; exit 0
    1.96  			fi
    1.97 -			page_footer
    1.98 -			exit 0
    1.99 +			pkg="$mainpkg"
   1.100  		fi
   1.101  
   1.102 +		log=$LOGS/$pkg.log
   1.103 +		pkg_info
   1.104 +
   1.105  		# Check for a log file and display summary if it exists.
   1.106  		summary "$log"
   1.107  
   1.108 @@ -1128,9 +1146,9 @@
   1.109  
   1.110  
   1.111  		echo "<section><h3>Quick jump:</h3><ul>"
   1.112 -		echo "$split" | sed 'p' | xargs printf "<li><a href='#id-%s'>%s</a></li>\n"
   1.113 -		echo "<li id='li-repeats' style='display:none'><a href='#id-repeats'>repeatedly packaged files</a></li>"
   1.114 -		echo "<li id='li-orphans' style='display:none'><a href='#id-orphans'>unpackaged files</a></li>"
   1.115 +		echo "$split" | sed 'p' | xargs printf "<li><a href='#%s'>%s</a></li>\n"
   1.116 +		echo "<li id='li-repeats' style='display:none'><a href='#repeats'>repeatedly packaged files</a></li>"
   1.117 +		echo "<li id='li-orphans' style='display:none'><a href='#orphans'>unpackaged files</a></li>"
   1.118  		echo "</ul></section>"
   1.119  
   1.120  		for p in $split; do
   1.121 @@ -1144,7 +1162,7 @@
   1.122  
   1.123  			size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
   1.124  
   1.125 -			echo "<section><h3 id='id-$p'>Contents of package “$namever” (${size:-empty}):</h3>"
   1.126 +			echo "<section><h3 id='$p'>Contents of package “$namever” (${size:-empty}):</h3>"
   1.127  			echo '<pre class="files">'
   1.128  			if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
   1.129  				echo -n '<span class="underline">permissions·lnk·user    ·'
   1.130 @@ -1166,7 +1184,7 @@
   1.131  		repeats="$(sort $packaged | uniq -d)"
   1.132  		if [ -n "$repeats" ]; then
   1.133  			echo '<script>document.getElementById("li-repeats").style.display = "list-item"</script>'
   1.134 -			echo -n '<section><h3 id="id-repeats">Repeatedly packaged files:</h3><pre class="files">'
   1.135 +			echo -n '<section><h3 id="repeats">Repeatedly packaged files:</h3><pre class="files">'
   1.136  			echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
   1.137  			echo "</pre></section>"
   1.138  		fi
   1.139 @@ -1177,7 +1195,7 @@
   1.140  		orphans="$(sort $all_files $packaged | uniq -u)"
   1.141  		if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
   1.142  			echo '<script>document.getElementById("li-orphans").style.display = "list-item"</script>'
   1.143 -			echo '<section><h3 id="id-orphans">Unpackaged files:</h3>'
   1.144 +			echo '<section><h3 id="orphans">Unpackaged files:</h3>'
   1.145  			table=$(mktemp)
   1.146  			echo "$orphans" | awk -vi="$base/$indir/browse/install" '
   1.147  			function tag(text, color) {