[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH 4/4] Handle 16 digit hex strings for ID_SERIAL_SHORT (#611554)



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/08/2010 08:22 AM, David Cantrell wrote:
> Modification to udev_device_get_wwid() patch from Masahiro Matsuya
> <mmatsuya redhat com> to handle 16 digit hex strings for
> ID_SERIAL_SHORT.
> ---
>  storage/udev.py |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/storage/udev.py b/storage/udev.py
> index 738cea0..f780c09 100644
> --- a/storage/udev.py
> +++ b/storage/udev.py
> @@ -267,10 +267,11 @@ def udev_device_get_wwid(udev_info):
>      """ The WWID of a device is typically just its serial number, but with
>          colons in the name to make it more readable. """
>      serial = udev_device_get_serial(udev_info)
> +    serial_len = len(serial)
>  
> -    if serial and len(serial) == 32:
> +    if serial and (serial_len == 32 or serial_len == 16):
>          retval = ""
> -        for i in range(0, 16):
> +        for i in range(0, (serial_len / 2)):
>              retval += serial[i*2:i*2+2] + ":"
>  
>          return retval[0:-1]

It would be more readable to do:

for i in range(0, serial_len, 2):
    retval += serial[i:i+2] + ":"

I'd also be tempted to generalize it to any even length instead of 16 or
32 just so that it doesn't need any more changes in the future.

- -- 
Brian C. Lane <bcl redhat com>
Red Hat / Port Orchard, WA
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEVAwUBTDYGyRF+jBaO/jp/AQJAgwf+Nxp5t47FNCk25VzRVsSLlSfyE/jUbqzm
v3a6nr3UEVuZUs+3i4H9f6mUE6KCn5NUNqDPvRsSC/1JSyCUSj8FSJEXumOAGowc
qwJ+CzhUaG6I1yvOqmtevM6vDH09sIH9byoTMwFurPpbX/O9XQfboXSe6sVVaAP0
2BBrsZmD9eqNq6OHu/D7p6S+hBg6jKlLQuKAWfgoALYTEsvUXXX0xzWOaz2dc72Y
dIUrotq2zvpmhgDofsSz59YPk9Sis+9yOalRs9CENhwXRlP7keNjbt5xzpOkn3C5
n3+o/SpRVyCVkccvgTmNaVXVvb+8KhDf6xoKdkT4Kca6DQhFwWhk9A==
=f/qi
-----END PGP SIGNATURE-----


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]