ossystems-srcrev-handler.bbclass: Use 'with' to open the file
authorOtavio Salvador <otavio@ossystems.com.br>
Thu, 12 Apr 2018 20:26:37 +0000 (17:26 -0300)
committerOtavio Salvador <otavio@ossystems.com.br>
Thu, 12 Apr 2018 20:27:18 +0000 (17:27 -0300)
We use the 'with' block to open the file description and later iterate
over all lines.

Change-Id: I0e4c31517a58f32ad42c0ab5dd62ef4b6e8fdb01
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
classes/ossystems-srcrev-handler.bbclass

index 5be22fa..345a35b 100644 (file)
@@ -36,20 +36,20 @@ def ossystems_srcrev_handler(d):
     else:
         bb.plain("O.S. Systems SRCREV handler: Using 'AUTOREV' to build recipes...")
 
-    srcrevs_fd = open(srcrevs, 'r')
-    for line in srcrevs_fd.readlines():
-        pkg, version, srcrev = line.split()
-
-        if _stable_release(d):
-            bb.debug(1, "O.S. Systems SRCREV handler: Setting %s for version %s (%s)..."
-                     % (pkg, version, srcrev))
-            rev = srcrev
-        else:
-            bb.debug(1, "O.S. Systems SRCREV handler: Setting %s for 'AUTOREV'..."
-                     % (pkg))
-            rev = "${AUTOREV}"
-
-        d.setVar("SRCREV_pn-%s" % pkg, rev)
+    with open(srcrevs, 'r') as srcrevs_fd:
+        for line in srcrevs_fd.readlines():
+            pkg, version, srcrev = line.split()
+
+            if _stable_release(d):
+                bb.debug(1, "O.S. Systems SRCREV handler: Setting %s for version %s (%s)..."
+                         % (pkg, version, srcrev))
+                rev = srcrev
+            else:
+                bb.debug(1, "O.S. Systems SRCREV handler: Setting %s for 'AUTOREV'..."
+                         % (pkg))
+                rev = "${AUTOREV}"
+
+            d.setVar("SRCREV_pn-%s" % pkg, rev)
 
 addhandler ossystems_srcrev_eventhandler
 python ossystems_srcrev_eventhandler() {