]> code.ossystems Code Review - openembedded-core.git/commitdiff
cve-update-db-native: use context manager for cve_f
authorChris Laplante <chris.laplante@agilent.com>
Wed, 9 Sep 2020 20:51:08 +0000 (16:51 -0400)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 9 Sep 2020 22:40:58 +0000 (23:40 +0100)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-core/meta/cve-update-db-native.bb

index d22b66f6c76b7e91827ea3f0360c5788adcb7027..328f6ab3645e1b84e74345018d9bad8ce428aa2a 100644 (file)
@@ -50,8 +50,6 @@ python do_populate_cve_db() {
     except OSError:
         pass
 
-    cve_f = open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a')
-
     bb.utils.mkdirhier(db_dir)
 
     # Connect to database
@@ -60,7 +58,7 @@ python do_populate_cve_db() {
 
     initialize_db(c)
 
-    with bb.progress.ProgressHandler(d) as ph:
+    with bb.progress.ProgressHandler(d) as ph, open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a') as cve_f:
         total_years = date.today().year + 1 - YEAR_START
         for i, year in enumerate(range(YEAR_START, date.today().year + 1)):
             ph.update((float(i + 1) / total_years) * 100)
@@ -108,7 +106,6 @@ python do_populate_cve_db() {
             if year == date.today().year:
                 cve_f.write('CVE database update : %s\n\n' % date.today())
 
-        cve_f.close()
         conn.commit()
         conn.close()
 }