Hi!

It's been quite some time that I have noticed that we could considerably
simplify debconf_select in partman-base by using the features provided
by Choices-C, as debconf_select was basically reimplementing it
manually.  And tonight was the night!

As far as I have tested, everything works after applying this patch.
But a second look is more than needed on such a core function…

Other comments:
 * All templates using debconf_select or ask_user must now
   define the following:
    Choices-C: ${CHOICES}
    Choices: ${DESCRIPTIONS}
 * The deprecated ability to set default values through localised
   strings have also been removed.
 * Templates used through debconf_select in partman-base,
   partman-crypto, partman-auto, partman-partitioning and partman-target
   have all been updated.

Stats:
 installer/doc/devel/partman/partman-doc.sgml       |    6 +-
 packages/partman/partman-auto/debian/changelog     |    7 ++
 packages/partman/partman-auto/debian/control       |    2 +-
 .../partman-auto/debian/partman-auto.templates     |   12 +++-
 packages/partman/partman-base/debian/changelog     |   14 ++++
 .../partman-base/debian/partman-base.templates     |   12 +++-
 packages/partman/partman-base/lib/base.sh          |   65 +++++++-------------
 packages/partman/partman-crypto/debian/changelog   |    7 ++
 packages/partman/partman-crypto/debian/control     |    2 +-
 .../partman-crypto/debian/partman-crypto.templates |   15 +++--
 .../partman/partman-partitioning/debian/changelog  |    7 ++
 .../debian/partman-partitioning.templates          |    3 +-
 packages/partman/partman-target/debian/changelog   |    7 ++
 .../partman-target/debian/partman-target.templates |    3 +-
 14 files changed, 100 insertions(+), 62 deletions(-)

Cheers,
-- 
Jérémy Bobbio                        .''`. 
[EMAIL PROTECTED]                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
commit c02d2d5837c257d76d3c042c42864abf11251848
Author: Jérémy Bobbio <[EMAIL PROTECTED]>
Date:   Sun Mar 30 00:14:35 2008 +0000

    Use Choices-C in partman debconf_select
    
    Instead of mangling the localised strings, debconf_select (and thus
    ask_user) now uses Choices-C.
    
    All templates using debconf_select or ask_user must now
    define the following:
      Choices-C: ${CHOICES}
      Choices: ${DESCRIPTIONS}
    
    The deprecated ability to set default values through localised strings
    have also been removed.
    
    Templates used through debconf_select in partman-base, partman-crypto,
    partman-auto, partman-partitioning and partman-target have all been
    updated.

diff --git a/installer/doc/devel/partman/partman-doc.sgml b/installer/doc/devel/partman/partman-doc.sgml
index 21017bd..e763629 100644
--- a/installer/doc/devel/partman/partman-doc.sgml
+++ b/installer/doc/devel/partman/partman-doc.sgml
@@ -337,7 +337,8 @@ UMSDOS file systems, only a few new udebs must be all that is needed.
  and choices fields:
 <example>
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 </example>
 
 <p> All other files in the menu directory are subdirectories.  Any
@@ -736,7 +737,8 @@ debconf_select <var>priority</var> <var>template</var> <var>choices</var> <var>d
   The template must have exactly the following type and choices fields:
 <example>
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 </example>
 
 <p> The udebs that generate menus using menu-directories use the
diff --git a/packages/partman/partman-auto/debian/changelog b/packages/partman/partman-auto/debian/changelog
index 4cd409e..d17e39a 100644
--- a/packages/partman/partman-auto/debian/changelog
+++ b/packages/partman/partman-auto/debian/changelog
@@ -1,3 +1,10 @@
+partman-auto (77) UNRELEASED; urgency=low
+
+  * Update to the new debconf_select interface.
+    Requires partman-base (>= 118).
+
+ -- Jérémy Bobbio <[EMAIL PROTECTED]>  Sat, 29 Mar 2008 23:35:43 +0100
+
 partman-auto (76) unstable; urgency=low
 
   [ Colin Watson ]
diff --git a/packages/partman/partman-auto/debian/control b/packages/partman/partman-auto/debian/control
index a14204d..23b7691 100644
--- a/packages/partman/partman-auto/debian/control
+++ b/packages/partman/partman-auto/debian/control
@@ -9,5 +9,5 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-auto
 Package: partman-auto
 XC-Package-Type: udeb
 Architecture: any
-Depends: ${misc:Depends}, di-utils, partman-base (>= 114), partman-basicfilesystems, partman-ext3
+Depends: ${misc:Depends}, di-utils, partman-base (>= 118), partman-basicfilesystems, partman-ext3
 Description: Automatically partition storage devices (partman)
diff --git a/packages/partman/partman-auto/debian/partman-auto.templates b/packages/partman/partman-auto/debian/partman-auto.templates
index f5c7ce6..354efee 100644
--- a/packages/partman/partman-auto/debian/partman-auto.templates
+++ b/packages/partman/partman-auto/debian/partman-auto.templates
@@ -24,7 +24,8 @@ _Description: Failed to partition the selected disk
 
 Template: partman-auto/init_automatically_partition
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl1:
 _Description: Partitioning method:
  The installer can guide you through partitioning a disk (using different
@@ -47,7 +48,8 @@ Description: for internal use; can be preseeded
 
 Template: partman-auto/automatically_partition
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl1:
 _Description: Partitioning method:
  If you choose guided partitioning for an entire disk, you will next be
@@ -55,7 +57,8 @@ _Description: Partitioning method:
 
 Template: partman-auto/choose_recipe
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl1:
 #flag:comment:2
 # "Selected for partitioning" can be either an entire disk
@@ -112,7 +115,8 @@ _Description: Guided - use entire disk
 
 Template: partman-auto/select_disk
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl1:
 _Description: Select disk to partition:
  Note that all data on the disk you select will be erased, but not before
diff --git a/packages/partman/partman-base/debian/changelog b/packages/partman/partman-base/debian/changelog
index 0735b1a..8ed2699 100644
--- a/packages/partman/partman-base/debian/changelog
+++ b/packages/partman/partman-base/debian/changelog
@@ -1,3 +1,17 @@
+partman-base (118) UNRELEASED; urgency=low
+
+  * Use Choices-C in debconf_select instead of mangling the localised
+    strings.  All templates using debconf_select or ask_user must now define
+    the following:
+      Choices-C: ${CHOICES}
+      Choices: ${DESCRIPTIONS}
+    The deprecated ability to set default values through localised strings
+    have also been removed.
+  * Update partman/choose_partition, partman/storage_device,
+    partman/free_space and partman/active_partition to the new format.
+
+ -- Jérémy Bobbio <[EMAIL PROTECTED]>  Sat, 29 Mar 2008 22:57:27 +0100
+
 partman-base (117) unstable; urgency=low
 
   [ Colin Watson ]
diff --git a/packages/partman/partman-base/debian/partman-base.templates b/packages/partman/partman-base/debian/partman-base.templates
index 0a1564f..edb7240 100644
--- a/packages/partman/partman-base/debian/partman-base.templates
+++ b/packages/partman/partman-base/debian/partman-base.templates
@@ -55,7 +55,8 @@ Description: ${TYPE}
 
 Template: partman/choose_partition
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl1:
 _Description: This is an overview of your currently configured partitions and mount points. Select a partition to modify its settings (file system, mount point, etc.), a free space to create partitions, or a device to initialize its partition table.
 
@@ -108,19 +109,22 @@ _Description: The partition tables of the following devices are changed:
 
 Template: partman/storage_device
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl2:
 _Description: What to do with this device:
 
 Template: partman/free_space
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl2:
 _Description: How to use this free space:
 
 Template: partman/active_partition
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl2:
 _Description: Partition settings:
  You are editing partition #${PARTITION} of ${DEVICE}. ${OTHERINFO} ${DESTROYED}
diff --git a/packages/partman/partman-base/lib/base.sh b/packages/partman/partman-base/lib/base.sh
index 9187bac..bd8a6ee 100644
--- a/packages/partman/partman-base/lib/base.sh
+++ b/packages/partman/partman-base/lib/base.sh
@@ -42,65 +42,44 @@ maybe_escape () {
 }
 
 debconf_select () {
-	local IFS priority template choices default_choice default x u newchoices code
+	local IFS priority template choices default keys descriptions code x
 	priority="$1"
 	template="$2"
 	choices="$3"
-	default_choice="$4"
-	default=''
-	# Debconf ignores spaces so we have to remove them from $choices
-	newchoices=''
+	default="$4"
+	keys=""
+	descriptions=""
 	IFS="$NL"
 	for x in $choices; do
-		local key option
+		local key plugin
 		restore_ifs
-		key=$(echo ${x%$TAB*})
-		option=$(echo "${x#*$TAB}" | sed "s/ *\$//g; s/^ /$debconf_select_lead/g")
-		newchoices="${newchoices:+${newchoices}${NL}}${key}${TAB}${option}"
-		if [ "$key" = "$default_choice" ]; then
-			default="$option"
+		key="${x%$TAB*}"
+		keys="${keys:+${keys}, }$key"
+		descriptions="${descriptions:+${descriptions}, }$(
+			echo "${x#*$TAB}" |
+			sed "s/ *\$//g; s/^ /$debconf_select_lead/g; s/,/\\\\,/g; s/^ /\\\\ /")"
+
+		# If the question was asked via ask_user, this allow preseeding
+		# by using the name of the plugin responsible for the answer.
+		if [ -n "$default" ]; then
+			plugin="${key%%__________*}"
+			if [ "$default" = "$plugin" ] ||
+			   [ "$default" = "${plugin#[0-9][0-9]}" ]; then
+				default="$key"
+			fi
 		fi
 	done
-	choices="$newchoices"
-	u=''
-	IFS="$NL"
-	# escape the commas and leading whitespace but keep them unescaped
-	# in $choices
-	for x in $choices; do
-		u="$u, `echo ${x#*$TAB} | sed 's/,/\\\\,/g; s/^ /\\\\ /'`"
-	done
-	u=${u#, }
-	restore_ifs
 	# You can preseed questions asked through this function by using
-	# full localised text (deprecated) or by using the key (the part
-	# before the tab). Additionally, if the question was asked via
-	# ask_user below, then you can also preseed it using the name of the
-	# plugin responsible for the answer you want.
+	# the key (the part before the tab).
 	if [ -n "$default" ]; then
 		db_set $template "$default"
 	fi
-	db_subst $template CHOICES "$u"
+	db_subst $template CHOICES "$keys"
+	db_subst $template DESCRIPTIONS "$descriptions"
 	code=0
 	db_input $priority $template || code=1
 	db_go || return 255
 	db_get $template
-	IFS="$NL"
-	for x in $choices; do
-		if [ "$RET" = "${x#*$TAB}" ]; then
-			RET="${x%$TAB*}"
-			break
-		else
-			# Help out ask_user.
-			local key="${x%%__________*}"
-			if [ "$key" != "$x" ] && \
-			   ([ "$RET" = "$key" ] || \
-			    [ "$RET" = "${key#[0-9][0-9]}" ]); then
-				RET="${x%$TAB*}"
-				break
-			fi
-		fi
-	done
-	restore_ifs
 	return $code
 }
 
diff --git a/packages/partman/partman-crypto/debian/changelog b/packages/partman/partman-crypto/debian/changelog
index 8c6f31e..69ac781 100644
--- a/packages/partman/partman-crypto/debian/changelog
+++ b/packages/partman/partman-crypto/debian/changelog
@@ -1,3 +1,10 @@
+partman-crypto (29) UNRELEASED; urgency=low
+
+  * Update to the new debconf_select interface.
+    Requires partman-base (>= 118).
+
+ -- Jérémy Bobbio <[EMAIL PROTECTED]>  Sat, 29 Mar 2008 23:37:32 +0100
+
 partman-crypto (28) unstable; urgency=low
 
   [ Max Vozeler ]
diff --git a/packages/partman/partman-crypto/debian/control b/packages/partman/partman-crypto/debian/control
index 3c3faa6..891e50b 100644
--- a/packages/partman/partman-crypto/debian/control
+++ b/packages/partman/partman-crypto/debian/control
@@ -9,7 +9,7 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-crypto
 Package: partman-crypto
 XC-Package-Type: udeb
 Architecture: any
-Depends: partman-base (>= 114), ${shlibs:Depends}, ${misc:Depends}
+Depends: partman-base (>= 118), ${shlibs:Depends}, ${misc:Depends}
 Description: Add to partman support for block device encryption
 
 Package: partman-crypto-dm
diff --git a/packages/partman/partman-crypto/debian/partman-crypto.templates b/packages/partman/partman-crypto/debian/partman-crypto.templates
index 022f121..bbd9412 100644
--- a/packages/partman/partman-crypto/debian/partman-crypto.templates
+++ b/packages/partman/partman-crypto/debian/partman-crypto.templates
@@ -47,7 +47,8 @@ _Description: Encryption method:
 
 Template: partman-crypto/crypto_type
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl3:
 _Description: Encryption method for this partition:
 
@@ -71,7 +72,8 @@ _Description: Key size:
 
 Template: partman-crypto/keysize
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl3:
 _Description: Key size for this partition:
 
@@ -85,7 +87,8 @@ _Description: IV algorithm:
 
 Template: partman-crypto/ivalgorithm
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # An initialization vector is the initial randomness used to seed
 # the encryption algorithm
 # :sl3:
@@ -103,7 +106,8 @@ _Description: Encryption key:
 
 Template: partman-crypto/keytype
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl3:
 _Description: Type of encryption key for this partition:
 
@@ -115,7 +119,8 @@ _Description: Encryption key hash:
 
 Template: partman-crypto/keyhash
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl3:
 _Description: Type of encryption key hash for this partition:
  The encryption key is derived from the passphrase by applying a
diff --git a/packages/partman/partman-partitioning/debian/changelog b/packages/partman/partman-partitioning/debian/changelog
index 93953a6..f0b4519 100644
--- a/packages/partman/partman-partitioning/debian/changelog
+++ b/packages/partman/partman-partitioning/debian/changelog
@@ -1,3 +1,10 @@
+partman-partitioning (59) UNRELEASED; urgency=low
+
+  * Update to the new debconf_select interface.
+    Requires partman-base (>= 118).
+
+ -- Jérémy Bobbio <[EMAIL PROTECTED]>  Sun, 30 Mar 2008 00:17:48 +0000
+
 partman-partitioning (58) unstable; urgency=low
 
   [ Frans Pop ]
diff --git a/packages/partman/partman-partitioning/debian/partman-partitioning.templates b/packages/partman/partman-partitioning/debian/partman-partitioning.templates
index 2c05fbf..6b6d43b 100644
--- a/packages/partman/partman-partitioning/debian/partman-partitioning.templates
+++ b/packages/partman/partman-partitioning/debian/partman-partitioning.templates
@@ -26,7 +26,8 @@ _Description: Write previous changes to disk and continue?
 
 Template: partman-partitioning/source_partition
 Type: select
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 # :sl2:
 _Description: Source partition:
  Please choose the partition which contains the data you want to copy.
diff --git a/packages/partman/partman-target/debian/changelog b/packages/partman/partman-target/debian/changelog
index e4ec78c..ab1fc4f 100644
--- a/packages/partman/partman-target/debian/changelog
+++ b/packages/partman/partman-target/debian/changelog
@@ -1,3 +1,10 @@
+partman-target (55) UNRELEASED; urgency=low
+
+  * Update to the new debconf_select interface.
+    Requires partman-base (>= 118).
+
+ -- Jérémy Bobbio <[EMAIL PROTECTED]>  Sat, 29 Mar 2008 23:38:00 +0100
+
 partman-target (54) unstable; urgency=low
 
   [ Colin Watson ]
diff --git a/packages/partman/partman-target/debian/partman-target.templates b/packages/partman/partman-target/debian/partman-target.templates
index b26dc22..8ccac64 100644
--- a/packages/partman/partman-target/debian/partman-target.templates
+++ b/packages/partman/partman-target/debian/partman-target.templates
@@ -81,7 +81,8 @@ _Description: Do you want to resume partitioning?
 Template: partman-target/choose_method
 Type: select
 # :sl2:
-Choices: ${CHOICES}
+Choices-C: ${CHOICES}
+Choices: ${DESCRIPTIONS}
 _Description: How to use this partition:
 
 Template: partman-target/text/method

Attachment: signature.asc
Description: Digital signature

Reply via email to