cookutils rev 998

lighttpd/index.cgi: improve titling; modules/compressor: show file names for warnings/errors, restore original if error, store in cache if no errors.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Nov 04 04:02:57 2017 +0200 (2017-11-04)
parents 061c4c621204
children 4504ab343621
files lighttpd/index.cgi modules/compressor modules/deps
line diff
     1.1 --- a/lighttpd/index.cgi	Wed Nov 01 03:44:38 2017 +0200
     1.2 +++ b/lighttpd/index.cgi	Sat Nov 04 04:02:57 2017 +0200
     1.3 @@ -479,7 +479,7 @@
     1.4  			: ${_fs=#_#_#}
     1.5  			: ${_stuff=#_#_#}
     1.6  			# Use one-letter html tags to save some bytes :)
     1.7 -			# <b>is error (red)</b> <u>is warning (orange)</u> <i>is informal (green)</i>
     1.8 +			# <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
     1.9  			sed	-e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
    1.10  				-e 's#OK$#<i>OK</i>#' \
    1.11  				-e 's#\([Dd]one\)$#<i>\1</i>#' \
    1.12 @@ -661,12 +661,17 @@
    1.13  
    1.14  
    1.15  pkg_info() {
    1.16 -	local log active bpkg
    1.17 +	local log active bpkg short_desc=''
    1.18  	log="$LOGS/$pkg.log"
    1.19  
    1.20  	echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
    1.21 -	[ -f $PKGS/packages.info ] && awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { print ": " $4; exit; }}' $PKGS/packages.info
    1.22 -	echo '</h2>'
    1.23 +	# Get short description for existing packages
    1.24 +	[ -f $PKGS/packages.info ] &&
    1.25 +	short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
    1.26 +	# If package not exists (not created yet or broken), get short description
    1.27 +	# (but only for "main" package) from receipt
    1.28 +	[ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
    1.29 +	echo ": $short_desc</h2>"
    1.30  	echo '<div id="info">'
    1.31  	echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
    1.32  
     2.1 --- a/modules/compressor	Wed Nov 01 03:44:38 2017 +0200
     2.2 +++ b/modules/compressor	Sat Nov 04 04:02:57 2017 +0200
     2.3 @@ -55,7 +55,7 @@
     2.4  # Compressor mini summary
     2.5  
     2.6  comp_summary() {
     2.7 -	# "$time0" "$size0" "$size1"
     2.8 +	# "$time0" "$size0" "$size1" "$log_file"
     2.9  	status
    2.10  	[ "$2" -eq 0 ] && return
    2.11  	saving=$(awk -va="$2" -vb="$3" 'BEGIN{ printf("%.0f\n", (a - b) / 1024) }')
    2.12 @@ -66,6 +66,14 @@
    2.13  	fi
    2.14  	_ '  Time: %s. Size: %s B -> %s B. Save: %s KB.%s' \
    2.15  		"$(calc_time $1)" "$2" "$3" "$saving" "$cache_msg"
    2.16 +
    2.17 +	if [ -s "$4" ]; then
    2.18 +		_ 'Cleaner warnings and errors:'
    2.19 +		awk '{printf "  %s\n", $0;}' "$4"
    2.20 +		echo
    2.21 +	fi
    2.22 +	# Clean log
    2.23 +	[ ! -f "$4" ] || rm "$4"
    2.24  }
    2.25  
    2.26  
    2.27 @@ -146,15 +154,23 @@
    2.28  	done
    2.29  
    2.30  	# Recompress with advdef (it can't compress, only recompress)
    2.31 +	cleaner_log="$(mktemp)"
    2.32  	IFS=$'\n'
    2.33  	for i in $(find $manpath -type f); do
    2.34  		if ! cached_path=$(query_cache mangz "$i"); then
    2.35 -			advdef -z4q "$i"
    2.36 -			store_cache "$cached_path" "$i"
    2.37 +			cp -a "$i" "$i.orig$$"		# save the original if something goes wrong
    2.38 +			out="$(advdef -z4q "$i")"
    2.39 +			if [ -n "$out" ]; then
    2.40 +				echo "$i:"$'\n'"$out"$'\n' >> "$cleaner_log"
    2.41 +				mv -f "$i.orig$$" "$i"	# restore the original
    2.42 +			else
    2.43 +				store_cache "$cached_path" "$i"
    2.44 +				rm -f "$i.orig$$"		# clean
    2.45 +			fi
    2.46  		fi
    2.47  	done
    2.48  
    2.49 -	comp_summary "$time0" "$size0" "$(sizes man)"
    2.50 +	comp_summary "$time0" "$size0" "$(sizes man)" "$cleaner_log"
    2.51  }
    2.52  
    2.53  
    2.54 @@ -171,15 +187,23 @@
    2.55  	action 'Recompressing gzip files...'
    2.56  
    2.57  	# Recompress with advdef
    2.58 +	cleaner_log="$(mktemp)"
    2.59  	IFS=$'\n'
    2.60  	for i in $(find $install -type f -name '*.gz' ! -path '*/share/man/*'); do
    2.61  		if ! cached_path=$(query_cache gz "$i"); then
    2.62 -			advdef -z4q "$i"
    2.63 -			store_cache "$cached_path" "$i"
    2.64 +			cp -a "$i" "$i.orig$$"		# save the original if something goes wrong
    2.65 +			out="$(advdef -z4q "$i")"
    2.66 +			if [ -n "$out" ]; then
    2.67 +				echo "$i:"$'\n'"$out"$'\n' >> "$cleaner_log"
    2.68 +				mv -f "$i.orig$$" "$i"	# restore the original
    2.69 +			else
    2.70 +				store_cache "$cached_path" "$i"
    2.71 +				rm -f "$i.orig$$"		# clean
    2.72 +			fi
    2.73  		fi
    2.74  	done
    2.75  
    2.76 -	comp_summary "$time0" "$size0" "$(sizes gz)"
    2.77 +	comp_summary "$time0" "$size0" "$(sizes gz)" "$cleaner_log"
    2.78  }
    2.79  
    2.80  
    2.81 @@ -196,15 +220,23 @@
    2.82  	action 'Recompressing zip files...'
    2.83  
    2.84  	# Recompress with advzip
    2.85 +	cleaner_log="$(mktemp)"
    2.86  	IFS=$'\n'
    2.87  	for i in $(find $install -type f -name '*.zip'); do
    2.88  		if ! cached_path=$(query_cache zip "$i"); then
    2.89 -			advzip -z3qk "$i"	# -4 is more than 2 orders slower
    2.90 -			store_cache "$cached_path" "$i"
    2.91 +			cp -a "$i" "$i.orig$$"		# save the original if something goes wrong
    2.92 +			out="$(advzip -z3qk "$i")"	# '-4' is more than two orders slower; use '-3'
    2.93 +			if [ -n "$out" ]; then
    2.94 +				echo "$i:"$'\n'"$out"$'\n' >> "$cleaner_log"
    2.95 +				mv -f "$i.orig$$" "$i"	# restore the original
    2.96 +			else
    2.97 +				store_cache "$cached_path" "$i"
    2.98 +				rm -f "$i.orig$$"		# clean
    2.99 +			fi
   2.100  		fi
   2.101  	done
   2.102  
   2.103 -	comp_summary "$time0" "$size0" "$(sizes zip)"
   2.104 +	comp_summary "$time0" "$size0" "$(sizes zip)" "$cleaner_log"
   2.105  }
   2.106  
   2.107  
   2.108 @@ -234,17 +266,37 @@
   2.109  
   2.110  	[ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
   2.111  
   2.112 +	cleaner_log="$(mktemp)"
   2.113 +	pq_opt='--skip-if-larger' # Sublime Text is mad about `if` in $(), so put it separately
   2.114  	IFS=$'\n'
   2.115  	for i in $(find $install -type f -name '*.png'); do
   2.116 -		unset IFS
   2.117 +		unset IFS iserror
   2.118  		if ! cached_path=$(query_cache $cache_section "$i"); then
   2.119 -			$use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
   2.120 -			$use_op && optipng -quiet -strip all -o$oplevel "$i"
   2.121 -			store_cache "$cached_path" "$i"
   2.122 +			cp -a "$i" "$i.orig$$"		# save the original if something goes wrong
   2.123 +			if $use_pq; then
   2.124 +				out="$(pngquant -f $pq_opt --ext .png --speed 1 "$i" 2>&1)"
   2.125 +				if [ -n "$out" ]; then
   2.126 +					echo "$i (pngquant):"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.127 +					iserror='yes'
   2.128 +				fi
   2.129 +			fi
   2.130 +			if $use_op && [ -z "$iserror" ]; then
   2.131 +				out="$(optipng -quiet -strip all -o$oplevel "$i" 2>&1)"
   2.132 +				if [ -n "$out" ]; then
   2.133 +					echo "$i (optipng):"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.134 +					iserror='yes'
   2.135 +				fi
   2.136 +			fi
   2.137 +			if [ -n "$iserror" ]; then
   2.138 +				mv -f "$i.orig$$" "$i"	# restore the original
   2.139 +			else
   2.140 +				store_cache "$cached_path" "$i"
   2.141 +				rm -f "$i.orig$$"		# clean
   2.142 +			fi
   2.143  		fi
   2.144  	done
   2.145  
   2.146 -	comp_summary "$time0" "$size0" "$(sizes png)"
   2.147 +	comp_summary "$time0" "$size0" "$(sizes png)" "$cleaner_log"
   2.148  }
   2.149  
   2.150  
   2.151 @@ -267,17 +319,10 @@
   2.152  	for i in $(IFS=$'\n' find $install -type f -name '*.svg'); do
   2.153  		out="$(unset IFS; svgcleaner "$i" "$i" --copy-on-error --quiet \
   2.154  			--multipass --remove-unresolved-classes no $opts 2>&1)"
   2.155 -		[ -z "$out" ] || echo -e "$i:\n$out\n" >> "$cleaner_log"
   2.156 +		[ -z "$out" ] || echo "$i:"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.157  	done
   2.158  
   2.159 -	comp_summary "$time0" "$size0" "$(sizes svg)"
   2.160 -
   2.161 -	if [ -s "$cleaner_log" ]; then
   2.162 -		_ 'Cleaner warnings and errors:'
   2.163 -		awk '{printf "  %s\n", $0;}' "$cleaner_log"
   2.164 -		echo
   2.165 -	fi
   2.166 -	rm "$cleaner_log"
   2.167 +	comp_summary "$time0" "$size0" "$(sizes svg)" "$cleaner_log"
   2.168  }
   2.169  
   2.170  
   2.171 @@ -296,13 +341,18 @@
   2.172  	size0=$(sizes xml)
   2.173  	time0=$(get_time)
   2.174  	temp_ui="$(mktemp)"
   2.175 +	cleaner_log="$(mktemp)"
   2.176  	IFS=$'\n'
   2.177  	for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
   2.178 -		xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
   2.179 -		cat "$temp_ui" > "$ui"
   2.180 +		out="$(xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui")"
   2.181 +		if [ -n "$out" ]; then
   2.182 +			echo "$ui:"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.183 +		else
   2.184 +			cat "$temp_ui" > "$ui"
   2.185 +		fi
   2.186  	done
   2.187  
   2.188 -	comp_summary "$time0" "$size0" "$(sizes xml)"
   2.189 +	comp_summary "$time0" "$size0" "$(sizes xml)" "$cleaner_log"
   2.190  	rm "$temp_ui"
   2.191  }
   2.192  
   2.193 @@ -381,7 +431,7 @@
   2.194  		rm "$desktop.orig"
   2.195  	done
   2.196  
   2.197 -	comp_summary "$time0" "$size0" "$(sizes des)"
   2.198 +	comp_summary "$time0" "$size0" "$(sizes des)" '/dev/null'
   2.199  }
   2.200  
   2.201  
   2.202 @@ -404,11 +454,20 @@
   2.203  	time0=$(get_time)
   2.204  
   2.205  	# Process all existing *.mo files
   2.206 +	cleaner_log="$(mktemp)"
   2.207  	IFS=$'\n'
   2.208  	for mo in $(find "$install" -type f -name '*.mo'); do
   2.209  		tmpfile="$(mktemp)"
   2.210  
   2.211 -		msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
   2.212 +		# put ANY errors of {msgunfmt,msguniq,msgconv} to $out. FIXME?
   2.213 +		out="$({ msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'; } 2>&1)"
   2.214 +		if [ -n "$out" ]; then
   2.215 +			# using literal $'\n' here instead of using `echo -e "...\n..."` because
   2.216 +			# $out may contain escapes ('\r', '\v') that we should print as-is
   2.217 +			echo "$mo:"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.218 +			continue # proceed to next file
   2.219 +		fi
   2.220 +
   2.221  		# add newline
   2.222  		echo >> "$tmpfile"
   2.223  
   2.224 @@ -497,12 +556,17 @@
   2.225  		}
   2.226  		' "$tmpfile" > "$tmpfile.awk"
   2.227  
   2.228 -		msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
   2.229 +		out="$(msgfmt "$tmpfile.awk" -o "$tmpfile.mo" 2>&1)"
   2.230 +		if [ -n "$out" ]; then
   2.231 +			echo "$mo (msgfmt):"$'\n'"$out"$'\n' >> "$cleaner_log"
   2.232 +			continue # proceed to next file
   2.233 +		fi
   2.234  
   2.235  		if [ -s "$tmpfile.mo" ]; then
   2.236  			rm "$mo"; mv "$tmpfile.mo" "$mo"
   2.237  		else
   2.238 -			_ 'Error processing %s' "$mo"
   2.239 +			_ 'Error processing %s' "$mo" >> "$cleaner_log"
   2.240 +			echo >> "$cleaner_log"
   2.241  			[ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
   2.242  		fi
   2.243  
   2.244 @@ -510,7 +574,7 @@
   2.245  		rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
   2.246  	done
   2.247  
   2.248 -	comp_summary "$time0" "$size0" "$(sizes mo1)"
   2.249 +	comp_summary "$time0" "$size0" "$(sizes mo1)" "$cleaner_log"
   2.250  }
   2.251  
   2.252  
   2.253 @@ -629,7 +693,7 @@
   2.254  
   2.255  	# Remove the unsupported locales
   2.256  	for rem_locale in $elocales; do
   2.257 -		[ -d  "$fs/usr/share/locale/$rem_locale" ] &&
   2.258 +		[ ! -d  "$fs/usr/share/locale/$rem_locale" ] ||
   2.259  		rm -r "$fs/usr/share/locale/$rem_locale"
   2.260  	done
   2.261  
     3.1 --- a/modules/deps	Wed Nov 01 03:44:38 2017 +0200
     3.2 +++ b/modules/deps	Sat Nov 04 04:02:57 2017 +0200
     3.3 @@ -172,6 +172,7 @@
     3.4  				s("nss", "palemoon");  #
     3.5  				s("xfconf", "libxfconf"); s("xfconf-dev", "libxfconf-dev");
     3.6  				s("exo",    "libexo");    s("exo-dev",    "libexo-dev");
     3.7 +				s("gconf",  "GConf");     s("gconf-dev",  "GConf-dev");
     3.8  
     3.9  				# if called with "--incl": show all deps including glibc-base,
    3.10  				# gcc-lib-base, glibc-dev and gcc; otherwise hide them