cookutils diff cook @ rev 838
cook: strip unsupported translations. Rewrite the doc in cookopts.txt.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Nov 17 01:28:30 2016 +0200 (2016-11-17) |
parents | 275599c3423c |
children | bd3b572e2651 |
line diff
1.1 --- a/cook Tue Nov 15 03:40:41 2016 +0200 1.2 +++ b/cook Thu Nov 17 01:28:30 2016 +0200 1.3 @@ -483,6 +483,30 @@ 1.4 } 1.5 1.6 1.7 +# Get list of supported locales... 1.8 + 1.9 +get_supported_locales() { 1.10 + local lpc='/slitaz-i18n/stuff/locale-pack.conf' LOCALE_PACK 1.11 + if [ -e "$WOK$lpc" ]; then 1.12 + # ... from package in the local wok 1.13 + . "$WOK$lpc" 1.14 + else 1.15 + # ... from Hg 1.16 + temp_conf=$(mktemp) 1.17 + wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc" 1.18 + if [ -s $temp_conf ]; then 1.19 + . $temp_conf 1.20 + else 1.21 + # Give up and use hardcoded list 1.22 + LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \ 1.23 + pt_BR ro ru sl sv tr uk zh_CN zh_TW" 1.24 + fi 1.25 + rm $temp_conf 1.26 + fi 1.27 + echo $LOCALE_PACK 1.28 +} 1.29 + 1.30 + 1.31 # Fix common errors and warnings in the .desktop files 1.32 # Fixing can be disabled with COOKOPTS="!fixdesktops" 1.33 1.34 @@ -490,10 +514,18 @@ 1.35 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return 1.36 [ -z "$(find $install -type f -name '*.desktop')" ] && return 1.37 1.38 + local size0=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}') 1.39 + local time0=$(date +%s) 1.40 + 1.41 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then 1.42 tazpkg -gi desktop-file-utils-extra --quiet 1.43 fi 1.44 1.45 + # The variable $LOCALE is set in cook.conf and may be overridden in the receipt. 1.46 + # Default value is "" (empty). That means for us that we'll use the full 1.47 + # list of supported locales here. 1.48 + [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales) 1.49 + 1.50 for desktop in $(find $install -type f -name '*.desktop'); do 1.51 cp "$desktop" "$desktop.orig" 1.52 1.53 @@ -503,6 +535,14 @@ 1.54 # Fix common errors in .desktop file 1.55 fix-desktop-file "$desktop" 1.56 1.57 + # Strip unsupported locales from .desktop file 1.58 + [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] && 1.59 + sdft "$desktop" -i -k "$LOCALE" 1.60 + 1.61 + # Extra-strip 1.62 + [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] && 1.63 + sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o 1.64 + 1.65 if [ -n "$QA" ]; then 1.66 # Check the rest of errors, warnings and tips 1.67 _ 'QA: Checking %s...' "$(basename $desktop)" 1.68 @@ -513,6 +553,10 @@ 1.69 1.70 rm "$desktop.orig" 1.71 done 1.72 + 1.73 + local size1=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}') 1.74 + local time1=$(date +%s) 1.75 + comp_summary "$time0" "$time1" "$size0" "$size1" 1.76 } 1.77 1.78 1.79 @@ -575,6 +619,44 @@ 1.80 } 1.81 1.82 1.83 +# Strip unsupported locales (.mo files) 1.84 + 1.85 +strip_mo_i18n() { 1.86 + [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return 1.87 + 1.88 + [ -z "$(find $fs -type f -name '*.mo')" ] && return 1.89 + 1.90 + action 'Stripping translations files...' 1.91 + local size0=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}') 1.92 + local time0=$(date +%s) 1.93 + 1.94 + # The variable $LOCALE is set in cook.conf and may be overridden in the receipt. 1.95 + # Default value is "" (empty). That means for us that we'll use the full 1.96 + # list of supported locales here. 1.97 + [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales) 1.98 + 1.99 + # Existing locales 1.100 + elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') " 1.101 + 1.102 + # Thin out the list of existing locales. At the end there will be only locales that need 1.103 + # to delete (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...) 1.104 + for keep_locale in $LOCALE; do 1.105 + elocales=${elocales//$keep_locale} 1.106 + done 1.107 + 1.108 + # Remove the unsupported locales 1.109 + for rem_locale in $elocales; do 1.110 + [ -d "$fs/usr/share/locale/$rem_locale" ] && 1.111 + rm -r "$fs/usr/share/locale/$rem_locale" 1.112 + done 1.113 + 1.114 + local size1=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}') 1.115 + local time1=$(date +%s) 1.116 + status 1.117 + comp_summary "$time0" "$time1" "$size0" "$size1" 1.118 +} 1.119 + 1.120 + 1.121 # Update installed.cook.diff 1.122 1.123 update_installed_cook_diff() { 1.124 @@ -1042,6 +1124,7 @@ 1.125 1.126 # Strip and stuff files. 1.127 strip_package 1.128 + strip_mo_i18n 1.129 1.130 # Create files.list with redirecting find output. 1.131 action 'Creating the list of files...'