* [PATCH 0/1] Make useradd-staticids.bbclass Python 3 compatible @ 2016-06-09 23:07 Peter Kjellerstedt 2016-06-09 23:07 ` [PATCH 1/1] useradd-staticids.bbclass: Make sure opened files are closed Peter Kjellerstedt 0 siblings, 1 reply; 3+ messages in thread From: Peter Kjellerstedt @ 2016-06-09 23:07 UTC (permalink / raw) To: openembedded-core Avoid warnings with Python 3 due to files that are not closed in useradd-staticids.bbclass. //Peter The following changes since commit 40e789d1fee7f0df2d23230fff38325119ad2935: bitbake: lib/bb/main.py: Fix use of BBPOSTCONF and BBPRECONF (2016-06-09 18:00:58 +0100) are available in the git repository at: git://git.yoctoproject.org/poky-contrib pkj/useradd-staticids-py3 http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/useradd-staticids-py3 Peter Kjellerstedt (1): useradd-staticids.bbclass: Make sure opened files are closed meta/classes/useradd-staticids.bbclass | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) -- 2.8.3 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] useradd-staticids.bbclass: Make sure opened files are closed 2016-06-09 23:07 [PATCH 0/1] Make useradd-staticids.bbclass Python 3 compatible Peter Kjellerstedt @ 2016-06-09 23:07 ` Peter Kjellerstedt 2016-06-16 13:07 ` George McCollister 0 siblings, 1 reply; 3+ messages in thread From: Peter Kjellerstedt @ 2016-06-09 23:07 UTC (permalink / raw) To: openembedded-core This avoids warnings about unclosed files with Python 3. Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> --- meta/classes/useradd-staticids.bbclass | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass index a9b506d..440c0e3 100644 --- a/meta/classes/useradd-staticids.bbclass +++ b/meta/classes/useradd-staticids.bbclass @@ -4,6 +4,7 @@ def update_useradd_static_config(d): import argparse import itertools import re + import errno class myArgumentParser( argparse.ArgumentParser ): def _print_message(self, message, file=None): @@ -30,19 +31,22 @@ def update_useradd_static_config(d): are set).""" id_table = dict() for conf in file_list.split(): - if os.path.exists(conf): - f = open(conf, "r") - for line in f: - if line.startswith('#'): - continue - # Make sure there always are at least exp_fields elements in - # the field list. This allows for leaving out trailing - # colons in the files. - fields = list_extend(line.rstrip().split(":"), exp_fields) - if fields[0] not in id_table: - id_table[fields[0]] = fields - else: - id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]])) + try: + with open(conf, "r") as f: + for line in f: + if line.startswith('#'): + continue + # Make sure there always are at least exp_fields + # elements in the field list. This allows for leaving + # out trailing colons in the files. + fields = list_extend(line.rstrip().split(":"), exp_fields) + if fields[0] not in id_table: + id_table[fields[0]] = fields + else: + id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]])) + except IOError as e: + if e.errno == errno.ENOENT: + pass return id_table -- 2.8.3 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] useradd-staticids.bbclass: Make sure opened files are closed 2016-06-09 23:07 ` [PATCH 1/1] useradd-staticids.bbclass: Make sure opened files are closed Peter Kjellerstedt @ 2016-06-16 13:07 ` George McCollister 0 siblings, 0 replies; 3+ messages in thread From: George McCollister @ 2016-06-16 13:07 UTC (permalink / raw) To: Peter Kjellerstedt; +Cc: openembedded-core On Thu, Jun 9, 2016 at 6:07 PM, Peter Kjellerstedt <peter.kjellerstedt@axis.com> wrote: > This avoids warnings about unclosed files with Python 3. > > Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> > --- > meta/classes/useradd-staticids.bbclass | 30 +++++++++++++++++------------- > 1 file changed, 17 insertions(+), 13 deletions(-) > > diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass > index a9b506d..440c0e3 100644 > --- a/meta/classes/useradd-staticids.bbclass > +++ b/meta/classes/useradd-staticids.bbclass > @@ -4,6 +4,7 @@ def update_useradd_static_config(d): > import argparse > import itertools > import re > + import errno > > class myArgumentParser( argparse.ArgumentParser ): > def _print_message(self, message, file=None): > @@ -30,19 +31,22 @@ def update_useradd_static_config(d): > are set).""" > id_table = dict() > for conf in file_list.split(): > - if os.path.exists(conf): > - f = open(conf, "r") > - for line in f: > - if line.startswith('#'): > - continue > - # Make sure there always are at least exp_fields elements in > - # the field list. This allows for leaving out trailing > - # colons in the files. > - fields = list_extend(line.rstrip().split(":"), exp_fields) > - if fields[0] not in id_table: > - id_table[fields[0]] = fields > - else: > - id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]])) > + try: > + with open(conf, "r") as f: > + for line in f: > + if line.startswith('#'): > + continue > + # Make sure there always are at least exp_fields > + # elements in the field list. This allows for leaving > + # out trailing colons in the files. > + fields = list_extend(line.rstrip().split(":"), exp_fields) > + if fields[0] not in id_table: > + id_table[fields[0]] = fields > + else: > + id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]])) This is still broken for me. As far as I can tell itertools.imap doesn't exist in Python 3. > + except IOError as e: > + if e.errno == errno.ENOENT: > + pass > > return id_table > > -- > 2.8.3 > > -- > _______________________________________________ > Openembedded-core mailing list > Openembedded-core@lists.openembedded.org > http://lists.openembedded.org/mailman/listinfo/openembedded-core ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-16 13:07 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-09 23:07 [PATCH 0/1] Make useradd-staticids.bbclass Python 3 compatible Peter Kjellerstedt 2016-06-09 23:07 ` [PATCH 1/1] useradd-staticids.bbclass: Make sure opened files are closed Peter Kjellerstedt 2016-06-16 13:07 ` George McCollister
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox