diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2020-03-30 10:33:51 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-03-31 13:58:01 +0100 |
commit | 6a947a90adfedbdb4b9bfd12077d6592439a2a46 (patch) | |
tree | e0131b78f89eef2d9e3d10d27fef3772ac93d1bd /meta/lib | |
parent | 62d944d31e33d2a4697d3eaf39633b0523bae45c (diff) | |
download | poky-6a947a90adfedbdb4b9bfd12077d6592439a2a46.tar.gz |
prservice.py: Use "with" to control file handle lifetime
(From OE-Core rev: e7f025c87d595d2e37f83b75f11bedf2bce7bcc0)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/prservice.py | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/meta/lib/oe/prservice.py b/meta/lib/oe/prservice.py index b1132ccb11..fcdbe66c19 100644 --- a/meta/lib/oe/prservice.py +++ b/meta/lib/oe/prservice.py | |||
@@ -79,41 +79,40 @@ def prserv_export_tofile(d, metainfo, datainfo, lockdown, nomax=False): | |||
79 | df = d.getVar('PRSERV_DUMPFILE') | 79 | df = d.getVar('PRSERV_DUMPFILE') |
80 | #write data | 80 | #write data |
81 | lf = bb.utils.lockfile("%s.lock" % df) | 81 | lf = bb.utils.lockfile("%s.lock" % df) |
82 | f = open(df, "a") | 82 | with open(df, "a") as f: |
83 | if metainfo: | 83 | if metainfo: |
84 | #dump column info | 84 | #dump column info |
85 | f.write("#PR_core_ver = \"%s\"\n\n" % metainfo['core_ver']); | 85 | f.write("#PR_core_ver = \"%s\"\n\n" % metainfo['core_ver']); |
86 | f.write("#Table: %s\n" % metainfo['tbl_name']) | 86 | f.write("#Table: %s\n" % metainfo['tbl_name']) |
87 | f.write("#Columns:\n") | 87 | f.write("#Columns:\n") |
88 | f.write("#name \t type \t notn \t dflt \t pk\n") | 88 | f.write("#name \t type \t notn \t dflt \t pk\n") |
89 | f.write("#----------\t --------\t --------\t --------\t ----\n") | 89 | f.write("#----------\t --------\t --------\t --------\t ----\n") |
90 | for i in range(len(metainfo['col_info'])): | 90 | for i in range(len(metainfo['col_info'])): |
91 | f.write("#%10s\t %8s\t %8s\t %8s\t %4s\n" % | 91 | f.write("#%10s\t %8s\t %8s\t %8s\t %4s\n" % |
92 | (metainfo['col_info'][i]['name'], | 92 | (metainfo['col_info'][i]['name'], |
93 | metainfo['col_info'][i]['type'], | 93 | metainfo['col_info'][i]['type'], |
94 | metainfo['col_info'][i]['notnull'], | 94 | metainfo['col_info'][i]['notnull'], |
95 | metainfo['col_info'][i]['dflt_value'], | 95 | metainfo['col_info'][i]['dflt_value'], |
96 | metainfo['col_info'][i]['pk'])) | 96 | metainfo['col_info'][i]['pk'])) |
97 | f.write("\n") | 97 | f.write("\n") |
98 | 98 | ||
99 | if lockdown: | 99 | if lockdown: |
100 | f.write("PRSERV_LOCKDOWN = \"1\"\n\n") | 100 | f.write("PRSERV_LOCKDOWN = \"1\"\n\n") |
101 | 101 | ||
102 | if datainfo: | 102 | if datainfo: |
103 | idx = {} | 103 | idx = {} |
104 | for i in range(len(datainfo)): | 104 | for i in range(len(datainfo)): |
105 | pkgarch = datainfo[i]['pkgarch'] | 105 | pkgarch = datainfo[i]['pkgarch'] |
106 | value = datainfo[i]['value'] | 106 | value = datainfo[i]['value'] |
107 | if pkgarch not in idx: | 107 | if pkgarch not in idx: |
108 | idx[pkgarch] = i | 108 | idx[pkgarch] = i |
109 | elif value > datainfo[idx[pkgarch]]['value']: | 109 | elif value > datainfo[idx[pkgarch]]['value']: |
110 | idx[pkgarch] = i | 110 | idx[pkgarch] = i |
111 | f.write("PRAUTO$%s$%s$%s = \"%s\"\n" % | 111 | f.write("PRAUTO$%s$%s$%s = \"%s\"\n" % |
112 | (str(datainfo[i]['version']), pkgarch, str(datainfo[i]['checksum']), str(value))) | 112 | (str(datainfo[i]['version']), pkgarch, str(datainfo[i]['checksum']), str(value))) |
113 | if not nomax: | 113 | if not nomax: |
114 | for i in idx: | 114 | for i in idx: |
115 | f.write("PRAUTO_%s_%s = \"%s\"\n" % (str(datainfo[idx[i]]['version']),str(datainfo[idx[i]]['pkgarch']),str(datainfo[idx[i]]['value']))) | 115 | f.write("PRAUTO_%s_%s = \"%s\"\n" % (str(datainfo[idx[i]]['version']),str(datainfo[idx[i]]['pkgarch']),str(datainfo[idx[i]]['value']))) |
116 | f.close() | ||
117 | bb.utils.unlockfile(lf) | 116 | bb.utils.unlockfile(lf) |
118 | 117 | ||
119 | def prserv_check_avail(d): | 118 | def prserv_check_avail(d): |