[OE-core] [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons
Christopher Larson
clarson at kergoth.com
Fri Oct 23 15:52:36 UTC 2015
On Fri, Oct 23, 2015 at 8:20 AM, Burton, Ross <ross.burton at intel.com> wrote:
> On 23 October 2015 at 11:38, Peter Kjellerstedt <
> peter.kjellerstedt at axis.com> wrote:
>
>> - field = line.rstrip().split(":")
>> + # Make sure there always are at least seven
>> elements in
>> + # the field list. This allows for leaving out
>> trailing
>> + # colons in the passwd file.
>> + line = line.rstrip() + "::::::"
>> + field = line.split(":")
>>
>
> It's a stylist thing but I prefer padding the field list instead of
> manipulating the input string. Something like
>
> field = line.strip().split(":")
> field += [''] * (7 - len(field))
>
Agreed, but I think this is cleaner:
def iter_extend(iterable, length, obj=None):
"""Ensure that iterable is the specified length by extending with obj"""
return itertools.islice(itertools.chain(iterable,
itertools.repeat(obj)), length)
fields = iter_extend(line.rstrip().split(":"), 7)
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20151023/e8b65e24/attachment-0002.html>
More information about the Openembedded-core
mailing list