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:47:19 +0100
commit93698ac54a0e4a94210b21df32e27a5252bf1056 (patch)
tree8c894b642ed6640a92606e364cabd0615d7d3e31
parenta9120996e032fbc6472dadbe39a3616b8826d9e5 (diff)
downloadpoky-93698ac54a0e4a94210b21df32e27a5252bf1056.tar.gz
useradd-staticids.bbclass: Make sure opened files are closed
This avoids warnings about unclosed files with Python 3. (From OE-Core rev: 77adf8341694b76cf58b7a31dda18b85b3eb87a2) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-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):
4 import argparse 4 import argparse
5 import itertools 5 import itertools
6 import re 6 import re
7 import errno
7 8
8 class myArgumentParser( argparse.ArgumentParser ): 9 class myArgumentParser( argparse.ArgumentParser ):
9 def _print_message(self, message, file=None): 10 def _print_message(self, message, file=None):
@@ -30,19 +31,22 @@ def update_useradd_static_config(d):
30 are set).""" 31 are set)."""
31 id_table = dict() 32 id_table = dict()
32 for conf in file_list.split(): 33 for conf in file_list.split():
33 if os.path.exists(conf): 34 try:
34 f = open(conf, "r") 35 with open(conf, "r") as f:
35 for line in f: 36 for line in f:
36 if line.startswith('#'): 37 if line.startswith('#'):
37 continue 38 continue
38 # Make sure there always are at least exp_fields elements in 39 # Make sure there always are at least exp_fields
39 # the field list. This allows for leaving out trailing 40 # elements in the field list. This allows for leaving
40 # colons in the files. 41 # out trailing colons in the files.
41 fields = list_extend(line.rstrip().split(":"), exp_fields) 42 fields = list_extend(line.rstrip().split(":"), exp_fields)
42 if fields[0] not in id_table: 43 if fields[0] not in id_table:
43 id_table[fields[0]] = fields 44 id_table[fields[0]] = fields
44 else: 45 else:
45 id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]])) 46 id_table[fields[0]] = list(itertools.imap(lambda x, y: x or y, fields, id_table[fields[0]]))
47 except IOError as e:
48 if e.errno == errno.ENOENT:
49 pass
46 50
47 return id_table 51 return id_table
48 52