cookutils 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 ab44ce9b38bb
files cook doc/cookopts.txt
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...'
     2.1 --- a/doc/cookopts.txt	Tue Nov 15 03:40:41 2016 +0200
     2.2 +++ b/doc/cookopts.txt	Thu Nov 17 01:28:30 2016 +0200
     2.3 @@ -10,46 +10,95 @@
     2.4  Currently, the following options are recognized:
     2.5  
     2.6  !pixmaps
     2.7 -    Don't copy icons from a /usr/share/pixmaps folder as well as from stuff
     2.8 -    folder (the same action that made obsolete option `GENERIC_PIXMAPS="no"`).
     2.9 +    Default action is to copy icons from a /usr/share/pixmaps folder as well as
    2.10 +    from stuff folder (the same action that made obsolete option
    2.11 +    `GENERIC_PIXMAPS="no"`).
    2.12 +    The presence of this option overrides the default action: files will not be
    2.13 +    automatically copied.
    2.14  
    2.15  !menus
    2.16 -    Don't copy desktop files from a /usr/share/applications folder (the same
    2.17 -    action that made obsolete option `GENERIC_MENUS="no"`).
    2.18 +    Default action is to copy desktop files from a /usr/share/applications
    2.19 +    folder (the same action that made obsolete option `GENERIC_MENUS="no"`).
    2.20 +    The presence of this option overrides the default action: files will not be
    2.21 +    automatically copied.
    2.22  
    2.23  !fixdesktops
    2.24 -    Don't fix common errors and warnings in the .desktop files.
    2.25 +    Default action is to fix common errors and warnings in the .desktop files.
    2.26 +    The presence of this option overrides the default action: .desktop files
    2.27 +    will not be changed.
    2.28 +
    2.29 +!i18nz
    2.30 +    1. Default action is to delete locales that are not currently supported by
    2.31 +    the SliTaz while processing desktop files.
    2.32 +    The presence of this option overrides the default action: .desktop files
    2.33 +    will contain the original set of locales.
    2.34 +    Please note, this option does not have any action if the `!fixdesktops`
    2.35 +    option provided: desktop files in any way not change.
    2.36 +    2. Default action is to keep only supported translations provided by the
    2.37 +    *.mo files.
    2.38 +    The presence of this option overrides the default action: all existing *.mo
    2.39 +    files will remain.
    2.40 +    Please note, you can add all translations to the package, for example, using
    2.41 +    command: `cook_copy_files *.mo`, and then by default only supported locales
    2.42 +    will be left.
    2.43 +
    2.44 +!extradesktops
    2.45 +    Default action is to remove extra information from the desktop files: such
    2.46 +    entries as 'GenericName', 'X-GNOME-FullName' (all X-* are exposed),
    2.47 +    'Terminal=false', Keywords, other sections. This extra information just not
    2.48 +    supported in the current (LXDE) environment.
    2.49 +    The presence of this option overrides the default action: extra information
    2.50 +    will not be removed from the .desktop files.
    2.51  
    2.52  !strip
    2.53 -    Don't strip executable files, shared and static libraries, as well as remove
    2.54 -    Python (*.pyc and *.pyo) and Perl (perllocal.pod and .packlist) files.
    2.55 +    Default action is to strip executable files, shared and static libraries,
    2.56 +    as well as remove Python (*.pyc and *.pyo) and Perl (perllocal.pod and
    2.57 +    .packlist) files.
    2.58 +    The presence of this option overrides the default action: executable files
    2.59 +    and libraries will not be stripped, and Python and Perl files all will be
    2.60 +    left.
    2.61  
    2.62  !manz
    2.63 -    Don't compress all man pages.
    2.64 +    Default action is to compress all man pages.
    2.65 +    The presence of this option overrides the default action: all man pages will
    2.66 +    be left "as is". Please note that these files may be installed in compressed
    2.67 +    form.
    2.68  
    2.69  !pngz
    2.70 -    Don't compress all png images. Image compression allows you to save some
    2.71 -    space, but it takes a lot of time.
    2.72 +    Default action is to compress all PNG images. Image compression allows you
    2.73 +    to save some space, but it takes a lot of time.
    2.74 +    The presence of this option overrides the default action: all PNG images
    2.75 +    will be left "as is".
    2.76  
    2.77  !pngquant
    2.78 -    Don't use `pngquant` to compress png images. Note, `pngquant` produces
    2.79 -    indexed images (max 256 colors) which can be inappropriate in some cases:
    2.80 -    a few programs (such as SLiM) will not recognize this compressed PNG file
    2.81 -    format.
    2.82 +    Default action is to use `pngquant` while compressing PNG images. Please
    2.83 +    note, `pngquant` produces indexed images (max 256 colors) which can be
    2.84 +    inappropriate in some cases: a few programs (such as SLiM) will not
    2.85 +    recognize this PNG file format.
    2.86 +    The presence of this option overrides the default action: `pngquant` will
    2.87 +    not be used.
    2.88  
    2.89  !optipng
    2.90 -    Don't use `optipng` to compress png images. Note, `optipng` is lossless png
    2.91 -    compressor. Using `pngquant` and `optipng` in conjunction allows to save
    2.92 -    more space.
    2.93 +    Default action is to use `optipng` to compress PNG images. Please note,
    2.94 +    `optipng` is lossless PNG compressor. Using `pngquant` and `optipng` in
    2.95 +    conjunction allows to save more space.
    2.96 +    The presence of this option overrides the default action: `optipng` will not
    2.97 +    be used.
    2.98  
    2.99  op0 to op8
   2.100 -    Use specified `optipng` optimization level. The higher the level, the slower
   2.101 -    compression. Note, this option does not have an exclamation mark, because it
   2.102 -    means "don't" and here is "do" otherwise.
   2.103 +    Default action is to use opimization level 2 while processing PNG images by
   2.104 +    `optipng`. Using this option you can set desired `optipng` optimization
   2.105 +    level. The higher the level, the slower compression and the smaller file
   2.106 +    size. Please note that this option has no exclamation mark, because it means
   2.107 +    "don't do", and here, on the contrary, "to do".
   2.108  
   2.109  !svgz
   2.110 -    Don't compress all svg images.
   2.111 +    Default action is to compress all SVG images.
   2.112 +    The presence of this option overrides the default action: all SVG images
   2.113 +    will be left "as is".
   2.114  
   2.115  !uiz
   2.116 -    Don't compress Glade UI files. Compression means the removal of
   2.117 -    insignificant spaces and comments.
   2.118 +    Default action is to compress Glade UI files. Compression means the removal
   2.119 +    of insignificant spaces and comments.
   2.120 +    The presence of this option overrides the default action: all *.ui and
   2.121 +    *.glade files will be left "as is".