summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2016-06-10 17:46:10 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-12 23:46:50 +0100
commit77adf8341694b76cf58b7a31dda18b85b3eb87a2 (patch)
tree06b171b26dee3fb8c9531bf31379596a98baf1ad
parentcccd8b09523d8f0c1df97d08181737681db13f37 (diff)
downloadopenembedded-core-contrib-77adf8341694b76cf58b7a31dda18b85b3eb87a2.tar.gz
openembedded-core-contrib-77adf8341694b76cf58b7a31dda18b85b3eb87a2.tar.bz2
openembedded-core-contrib-77adf8341694b76cf58b7a31dda18b85b3eb87a2.zip
useradd-staticids.bbclass: Make sure opened files are closed
This avoids warnings about unclosed files with Python 3. Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Ross Burton <ross.burton@intel.com>
-rw-r--r--meta/classes/useradd-staticids.bbclass30
1 files changed, 17 insertions, 13 deletions
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index a9b506d05d..440c0e3846 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