imgcreate/errors.py | 23 +++++++++++++++++++++++
tools/livecd-creator | 2 +-
tools/livecd-iso-to-disk.sh | 14 ++++++++------
3 files changed, 32 insertions(+), 7 deletions(-)
New commits:
commit e182dda3d58a25a08d5057faf5d140f08806ed7e
Author: Felix Schwarz <felix.schwarz(a)oss.schwarz.eu>
Date: Sat Feb 7 12:01:30 2009 +0100
Patch for unicode error messages
when I tried to build a custom live cd I noticed some problems in the error
reporting when there were unicode error messages (e.g. some dependency was
missing).
Example:
...
> anaconda-11.4.1.63-1.i386 von updates hat Abhängigkeitsauflöse-Probleme
> --> Fehlende Abhängigkeit: booty wird benötigt von Paket anaconda-11.4.1.63-1.i386 (updates)
> Traceback (most recent call last):
> File "./tools/livecd-creator", line 140, in <module>
> sys.exit(main())
> File "./tools/livecd-creator", line 132, in main
> logging.error("Error creating Live CD : %s" % e)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 42: ordinal not in range(128)
My patch ensures that unicode error messages can be printed correctly every
time. To get 100% unicode support, one should go through all log calls and
ensure that all strings are unicode so that localized error messages are
always shown correctly.
With my patch, there should be no unicode exceptions anymore, even when the
error message may be printed as 'Fehlende Abh\xe4ngigkeit' instead of
'Fehlende Abhängigkeit' (notice the '\xe4' in the first string).
diff --git a/imgcreate/errors.py b/imgcreate/errors.py
index ba08563..a29b841 100644
--- a/imgcreate/errors.py
+++ b/imgcreate/errors.py
@@ -21,6 +21,29 @@ class CreatorError(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
+ # Some error messages may contain unicode strings (especially if your system
+ # locale is different from 'C', e.g. 'de_DE'). Python's exception class does
+ # not handle this appropriately (at least until 2.5) because str(Exception)
+ # returns just self.message without ensuring that all characters can be
+ # represented using ASCII. So we try to return a str and fall back to repr
+ # if this does not work.
+ #
+ # Please use unicode for your error logging strings so that we can really
+ # print nice error messages, e.g.:
+ # log.error(u"Internal error: " % e)
+ # instead of
+ # log.error("Internal error: " % e)
+ # With our custom __str__ and __unicode__ methods both will work but the
+ # first log call print a more readable error message.
+ def __str__(self):
+ try:
+ return str(self.message)
+ except UnicodeEncodeError:
+ return repr(self.message)
+
+ def __unicode__(self):
+ return unicode(self.message)
+
class KickstartError(CreatorError):
pass
class MountError(CreatorError):
diff --git a/tools/livecd-creator b/tools/livecd-creator
index 1aab882..39f7478 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -129,7 +129,7 @@ def main():
creator.unmount()
creator.package()
except imgcreate.CreatorError, e:
- logging.error("Error creating Live CD : %s" % e)
+ logging.error(u"Error creating Live CD : %s" % e)
return 1
finally:
creator.cleanup()
commit 75201f2180bb2e35cc439f9219aaf333d9577daa
Author: Jeremy Katz <katzj(a)redhat.com>
Date: Tue Feb 3 14:58:04 2009 -0500
Move syslinux path to be under LiveOS to prep for multiple livedirs
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index c310936..7d5ba1d 100755
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -246,7 +246,7 @@ checkSyslinuxVersion() {
if ! syslinux 2>&1 | grep -qe -d; then
SYSLINUXPATH=""
else
- SYSLINUXPATH="syslinux"
+ SYSLINUXPATH="LiveOS/syslinux"
fi
}
commit 9188aba5d6d9a71933c910dc076e5a108bf2f57d
Author: Stewart Adam <maillist(a)diffingo.com>
Date: Mon Jan 26 23:44:04 2009 -0500
Fix $BOOTCONFIG being overwritten
There's also a small bug that I forgot to account for in the last patch -
$BOOTCONFIG is overwritten if --mactel is set, so the syslinux.cfg file is
left in an inconsistent state with root=CDLABEL=<...> and
rootfstype=iso9660. The attached patch fixes this problem by using
$BOOTCONFIG and $BOOTCONFIG_EFI.
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index 85dba7e..c310936 100755
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -509,6 +509,8 @@ fi
cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH
BOOTCONFIG=$USBMNT/$SYSLINUXPATH/isolinux.cfg
+# Set this to nothing so sed doesn't care
+BOOTCONFIG_EFI=
if [ -n "$mactel" ];then
if [ -d $CDMNT/EFI/boot ]; then
cp $CDMNT/EFI/boot/* $USBMNT/EFI/boot
@@ -541,14 +543,14 @@ EOF
fi
# this is a little ugly, but it gets the "interesting" named config file
- BOOTCONFIG=$USBMNT/EFI/boot/boot?*.conf
+ BOOTCONFIG_EFI=$USBMNT/EFI/boot/boot?*.conf
rm -f $USBMNT/EFI/boot/grub.conf
fi
echo "Updating boot config file"
# adjust label and fstype
-sed -i -e "s/CDLABEL=[^ ]*/$USBLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$USBFS/" $BOOTCONFIG
-if [ -n "$kernelargs" ]; then sed -i -e "s/liveimg/liveimg ${kernelargs}/" $BOOTCONFIG ; fi
+sed -i -e "s/CDLABEL=[^ ]*/$USBLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$USBFS/" $BOOTCONFIG $BOOTCONFIG_EFI
+if [ -n "$kernelargs" ]; then sed -i -e "s/liveimg/liveimg ${kernelargs}/" $BOOTCONFIG $BOOTCONFIG_EFI ; fi
if [ "$overlaysizemb" -gt 0 ]; then
echo "Initializing persistent overlay file"
@@ -559,8 +561,8 @@ if [ "$overlaysizemb" -gt 0 ]; then
else
dd if=/dev/null of=$USBMNT/LiveOS/$OVERFILE count=1 bs=1M seek=$overlaysizemb
fi
- sed -i -e "s/liveimg/liveimg overlay=${USBLABEL}/" $BOOTCONFIG
- sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG
+ sed -i -e "s/liveimg/liveimg overlay=${USBLABEL}/" $BOOTCONFIG $BOOTCONFIG_EFI
+ sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG $BOOTCONFIG_EFI
fi
if [ "$swapsizemb" -gt 0 ]; then