[OE-core] [PATCH] relocate_sdk.py: Allow script to work with Python 2.4 and 3.
Laurentiu Palcu
laurentiu.palcu at intel.com
Thu Oct 17 06:54:11 UTC 2013
On Wed, Oct 16, 2013 at 11:44:59AM -0400, Konrad Scherer wrote:
> From: Konrad Scherer <Konrad.Scherer at windriver.com>
>
> Python 2.4 does not support the 'b' string literal or the
> keyword 'as' in exception handling. Python 3 does not accept
> the old method of exception handling and defaults to unicode.
> The b() function converts strings to bytes on Python 3 and
> using sys.exc_info() avoids the exception handling syntax.
>
> Signed-off-by: Konrad Scherer <Konrad.Scherer at windriver.com>
> ---
> scripts/relocate_sdk.py | 43 ++++++++++++++++++++++++++-----------------
> 1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
> index fe6e4e0..a15302d 100755
> --- a/scripts/relocate_sdk.py
> +++ b/scripts/relocate_sdk.py
> @@ -31,7 +31,15 @@ import os
> import re
> import errno
>
> -old_prefix = re.compile(b"##DEFAULT_INSTALL_DIR##")
> +if sys.version < '3':
> + def b(x):
> + return x
> +else:
> + import codecs
I can drop this import.
Thanks,
Laurentiu
> + def b(x):
> + return x.encode(sys.getfilesystemencoding())
> +
> +old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##"))
>
More information about the Openembedded-core
mailing list