Bug#298913: locales: option to locale-gen to avoid regenerating existing locales?
Package: locales
Version: 2.3.2.ds1-20
Severity: wishlist
Tags: patch
It'd be nice if locale-gen had an option to avoid regenerating locales
that have already been generated. At the moment, successive calls to
locale-gen take O(n^2) time in the number of calls, which is annoying.
This is causing us performance issues on the Ubuntu live CD; we
pre-generate a bunch of locales, but if the user selects one that isn't
pre-generated then we have to run locale-gen, and since locales has not
been upgraded there's no reason to generate all the existing locales all
over again. (We could use localedef directly, but locale-gen already has
some logic that we want, and we'd want to add the locales to
/etc/locale.gen anyway for proper integration.) Similarly, it takes a
very long time to install several of our language packs, since they each
add some locales to /etc/locale.gen and call locale-gen.
Attached is a patch that implements a --keep-existing flag, with
documentation. It relies on perl-base to figure out whether the locale
exists, but perl-base is Essential so that should be OK. Run 'make' in
debian/local/manpages/ after applying it.
(Eventually, it might be nice to deal with removals from /etc/locale.gen
in a similar way, using 'localedef --delete-from-archive'.)
Thanks,
--
Colin Watson [cjwatson@debian.org]
diff -u glibc-2.3.2.ds1/debian/local/manpages/locale-gen.8.sgml glibc-2.3.2.ds1/debian/local/manpages/locale-gen.8.sgml
--- glibc-2.3.2.ds1/debian/local/manpages/locale-gen.8.sgml
+++ glibc-2.3.2.ds1/debian/local/manpages/locale-gen.8.sgml
@@ -13,7 +13,7 @@
<!ENTITY dhfirstname "<firstname>Eduard</firstname>">
<!ENTITY dhsurname "<surname>Bloch</surname>">
<!-- Please adjust the date whenever revising the manpage. -->
- <!ENTITY dhdate "<date>July 27, 2001</date>">
+ <!ENTITY dhdate "<date>March 10, 2005</date>">
<!-- SECTION should be 1-8, maybe w/ subsection other parameters are
allowed: see man(7), man(1). -->
<!ENTITY dhsection "<manvolnum>8</manvolnum>">
@@ -54,6 +54,7 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>&dhpackage;</command>
+ <arg><option>--keep-existing</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -80,6 +81,24 @@
</refsect1>
<refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><option>--keep-existing</option></term>
+ <listitem>
+ <para>By default, <command>&dhpackage;</command> removes all
+ existing locales and generates new ones afresh. The
+ <option>--keep-existing</option> option prevents this, so that
+ only locales which do not already exist are generated. This is
+ useful if calling locale-gen a number of times in
+ succession.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+ <refsect1>
<title>FILES</title>
<para><filename>/etc/locale.gen</filename></para>
diff -u glibc-2.3.2.ds1/debian/local/usr_sbin/locale-gen glibc-2.3.2.ds1/debian/local/usr_sbin/locale-gen
--- glibc-2.3.2.ds1/debian/local/usr_sbin/locale-gen
+++ glibc-2.3.2.ds1/debian/local/usr_sbin/locale-gen
@@ -11,9 +11,16 @@
[ -f $LOCALEGEN -a -s $LOCALEGEN ] || exit 0;
-# Remove all old locale dir and locale-archive before generating new
-# locale data.
-rm -rf /usr/lib/locale/* || true
+KEEP=
+if [ "$1" = '--keep-existing' ]; then
+ KEEP=1
+fi
+
+if [ -z "$KEEP" ]; then
+ # Remove all old locale dir and locale-archive before generating new
+ # locale data.
+ rm -rf /usr/lib/locale/* || true
+fi
umask 022
@@ -30,6 +37,10 @@
while read locale charset; do \
case $locale in \#*) continue;; "") continue;; esac; \
is_entry_ok || continue
+ if [ "$KEEP" ] && PERL_BADLANG=0 perl -MPOSIX -e \
+ 'exit 1 unless setlocale(LC_ALL, $ARGV[0])' "$locale"; then
+ continue
+ fi
echo -n " `echo $locale | sed 's/\([^.\@]*\).*/\1/'`"; \
echo -n ".$charset"; \
echo -n `echo $locale | sed 's/\([^\@]*\)\(\@.*\)*/\2/'`; \
Reply to: