cookutils rev 1082

Fix $MAINTAINER fetch for the case "User <user@example.com>"; cache/proxy/extract Repology badges for maintainers
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jul 12 18:01:24 2018 +0300 (2018-07-12)
parents 8683bf3e7c02
children a97d05aa96a3
files cook lighttpd/cooker.css lighttpd/index.cgi
line diff
     1.1 --- a/cook	Tue Jul 10 20:11:48 2018 +0300
     1.2 +++ b/cook	Thu Jul 12 18:01:24 2018 +0300
     1.3 @@ -1679,6 +1679,7 @@
     1.4  		[ -f "$WOK/$pkg/receipt" ] || continue
     1.5  		unset PACKAGE MAINTAINER
     1.6  		. $WOK/$pkg/receipt
     1.7 +		MAINTAINER=$(echo $MAINTAINER | sed 's|.*<||; s|>.*||')
     1.8  		echo -e "$MAINTAINER\t$PACKAGE"
     1.9  	done | sort > $db
    1.10  }
     2.1 --- a/lighttpd/cooker.css	Tue Jul 10 20:11:48 2018 +0300
     2.2 +++ b/lighttpd/cooker.css	Thu Jul 12 18:01:24 2018 +0300
     2.3 @@ -354,6 +354,8 @@
     2.4  .icon.more::before { content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='16' width='16'><path d='m3 7c-2 .1-2 2-2 2s0 1.9 2 2c2-.1 2-2 2-2s0-1.9-2-2zm5 0c-2 .1-2 2-2 2s0 1.9 2 2c2-.1 2-2 2-2s0-1.9-2-2zm5 0c-2 .1-2 2-2 2s0 1.9 2 2c2-.1 2-2 2-2s0-1.9-2-2z'/></svg>"); }
     2.5  .icon.bell::before { content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='16' width='16'><path d='m9.6 2.7s-3.4-.2-4.5 3c-1.9 4.6-2.5 3.8-2.8 4.4-.2.6.4.8.4.8l9.3 3.3s.5.2.8-.3-.9-.5.7-5.2c1-3.5-1.6-5.1-1.6-5.1s.3-1.1-.8-1.5c-1-.4-1.5.6-1.5.6zm-2.9 11s-.4 1.4 1.3 2.2c2 .4 2.3-.9 2.3-.9z'/></svg>"); }
     2.6  .icon.maintainers::before { content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='16' width='16'><path d='m6 2c-4 0-4 6 0 6s4-6 0-6zm3.9 2.2c.4 1.3-.3 2.8-1.1 3.5 0 0 .7 1.3 2.2 1.3 3.4 0 3.4-5 0-5-.5 0-1.1.2-1.1.2zm-3.9 5.8c-6 0-6 4-6 4v1h12v-1s0-4-6-4zm4.4 0c1.6 1 2.6 2.5 2.6 4h3v-1c0-1.5-1.5-3-5.6-3z'/></svg>"); }
     2.7 +.icon.actual::before { content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='16' width='16'><path d='m8 1c-3.8 0-7 3.2-7 7s3.2 7 7 7 7-3.2 7-7c0-1.5-.6-2.9-.6-2.9l-7.1 8.1-3.8-3.8c-.9-.9.5-2.3 1.4-1.4l2.3 2.3 6-6.9s-2-2.4-5.2-2.4z' fill='%23090'/></svg>"); }
     2.8 +.icon.update::before { content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='16' width='16'><path d='m8 .7-2.2 2.3h-2.8v2.8l-2.3 2.2 2.3 2.2v2.8h2.8l2.2 2.3 2.2-2.3h2.8v-2.8l2.3-2.2-2.3-2.2v-2.8h-2.8zm-1 3.3h2v5h-2zm0 6h2v2h-2z' fill='%23f90'/></svg>"); }
     2.9  
    2.10  .bigicon-i {
    2.11  	background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><path d='m16 2c-14 .7-14 14-14 14s0 13.3 14 14c14-.7 14-14 14-14s0-13.3-14-14zm0 5.5c2.5 0 2.5 2.5 2.5 2.5s0 2.5-2.5 2.5-2.5-2.5-2.5-2.5 0-2.5 2.5-2.5zm-2 6.5h4v10h-4z' fill='%2329F'/></svg>") no-repeat 0.5rem 50%;
     3.1 --- a/lighttpd/index.cgi	Tue Jul 10 20:11:48 2018 +0300
     3.2 +++ b/lighttpd/index.cgi	Thu Jul 12 18:01:24 2018 +0300
     3.3 @@ -37,9 +37,10 @@
     3.4  cooknotes="$CACHE/cooknotes"
     3.5  cooktime="$CACHE/cooktime"
     3.6  wokrev="$CACHE/wokrev"
     3.7 -webstat="$CACHE/webstat"
     3.8 +webstat="$CACHE/webstat"		# note, file should be previously created with write permissions for www
     3.9  splitdb="$CACHE/split.db"
    3.10  maintdb="$CACHE/maint.db"
    3.11 +repologydb="$CACHE/repology.db"	# note, file should be previously created with write permissions for www
    3.12  
    3.13  # Path to markdown to html convertor
    3.14  cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
    3.15 @@ -253,6 +254,38 @@
    3.16  }
    3.17  
    3.18  
    3.19 +# Proxy to the Repology
    3.20 +# Problems:
    3.21 +# 1. Function "latest packaged version" widely used here, and it has no JSON API, but only SVG badge.
    3.22 +# 2. So, all version comparisons can be only visually and not automated.
    3.23 +# 3. When the thousands of badges present on the web page, many of them are broken (maybe server
    3.24 +#    drops requests), while our server displays status icons well.
    3.25 +# 4. Default badges are wide and not customizable.
    3.26 +# Solution:
    3.27 +# 1. Make local cache. Update it on demand, but no more than once a day (Repology cached info
    3.28 +#    on a hourly basis). Use cached values when they are not expired.
    3.29 +# 2. Extract and save version(s) from the SVG badges. Values can be compared in the scripts as well
    3.30 +#    as custom badges may be provided.
    3.31 +
    3.32 +repology_get() {
    3.33 +	local found versions day=$(date +%j)		# %j is the number of the day in the year
    3.34 +	found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
    3.35 +		if ($1 == pkg && $2 == day) { print $3; exit; }
    3.36 +	}' $repologydb)
    3.37 +	if [ -n "$found" ]; then
    3.38 +		echo "$found"
    3.39 +	else
    3.40 +		versions=$(wget -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
    3.41 +		| sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
    3.42 +		if [ -n "$versions" ]; then
    3.43 +			sed -i "/^$1	/d" $repologydb
    3.44 +			echo -e "$1\t$day\t$versions" >> $repologydb
    3.45 +			echo $versions
    3.46 +		fi
    3.47 +	fi
    3.48 +}
    3.49 +
    3.50 +
    3.51  # Query '?pct=<package>': update percentage
    3.52  
    3.53  if [ -n "$(GET pct)" ]; then
    3.54 @@ -1143,18 +1176,22 @@
    3.55  							unset VERSION; REPOLOGY=$pkg
    3.56  							. $wok/$pkg/receipt
    3.57  							if [ "$REPOLOGY" == '-' ]; then
    3.58 -								repo_info=" </td><td> "
    3.59 +								unset repo_info1 repo_info2
    3.60  							else
    3.61 -								repo_info="<a href='https://repology.org/metapackage/$REPOLOGY' target='_blank'
    3.62 -									rel='noopener noreferrer' title='latest packaged version(s)'>
    3.63 -									<img src='https://repology.org/badge/latest-versions/$REPOLOGY.svg' alt='latest packaged version(s)'>
    3.64 -									</a></td>"
    3.65 +								repo_ver=$(repology_get $REPOLOGY)
    3.66 +								if echo " $repo_ver " | fgrep -q " $VERSION "; then
    3.67 +									icon='actual'
    3.68 +								else
    3.69 +									icon='update'
    3.70 +								fi
    3.71 +								repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
    3.72 +								repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
    3.73  							fi
    3.74  							cat <<EOT
    3.75  		<tr>
    3.76  			<td><img src="$base/s/$pkg"> <a href="$pkg">$pkg</a></td>
    3.77  			<td>$VERSION</td>
    3.78 -			<td>$repo_info</td>
    3.79 +			<td>$repo_info1 $repo_info2</td>
    3.80  		</tr>
    3.81  EOT
    3.82  					done