still making both branches closer
[nepi.git] / src / nepi / util / sfaapi.py
index 9c3b5d3..f460b7e 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -212,7 +211,7 @@ class SFAAPI(object):
             else: slice_resources = []
             if slice_resources:
                 slice_resources_hrn = self.get_resources_hrn(slice_resources)
-                for s_hrn_key, s_hrn_value in slice_resources_hrn.iteritems():
+                for s_hrn_key, s_hrn_value in slice_resources_hrn.items():
                     s_parts = s_hrn_value.split('.')
                     s_hrn = '.'.join(s_parts[:2]) + '.' + '\\.'.join(s_parts[2:])
                     resources_hrn_new.append(s_hrn)
@@ -220,10 +219,9 @@ class SFAAPI(object):
 
             resources_urn = self._get_resources_urn(resources_hrn_new)
             rspec = self.rspec_proc.build_sfa_rspec(slicename, resources_urn, None, leases)
-            f = open("/tmp/rspec_input.rspec", "w")
-            f.truncate(0)
-            f.write(rspec)
-            f.close()
+            with open("/tmp/rspec_input.rspec", "w") as f:
+                f.truncate(0)
+                f.write(rspec)
             
             if not os.path.getsize("/tmp/rspec_input.rspec") > 0:
                 raise RuntimeError("Fail to create rspec file to allocate resource in slice %s" % slicename)
@@ -270,10 +268,9 @@ class SFAAPI(object):
                 # Re implementing urn from hrn because the library sfa-common doesn't work for wilabt
                 resources_urn = self._get_urn(resources_hrn_new)
                 rspec = self.rspec_proc.build_sfa_rspec(slicename, resources_urn, properties, leases)
-                f = open("/tmp/rspec_input.rspec", "w")
-                f.truncate(0)
-                f.write(rspec)
-                f.close()
+                with open("/tmp/rspec_input.rspec", "w") as f:
+                    f.truncate(0)
+                    f.write(rspec)
 
                 if not os.path.getsize("/tmp/rspec_input.rspec") > 0:
                     raise RuntimeError("Fail to create rspec file to allocate resources in slice %s" % slicename)