python: bulk replace file to open for py3
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 11 Apr 2018 04:03:34 +0000 (16:03 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 13 Apr 2018 05:27:12 +0000 (07:27 +0200)
The builtin function `file` was removed in py3. Use `open` instead.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/gpo.py
python/samba/provision/sambadns.py
python/samba/subunit/run.py

index 5f4ad0ebca0d008d3cd73d0bde24172a3dd17510..cd946d9fa72cf64834c42e32c3ad95991f035361 100644 (file)
@@ -252,7 +252,7 @@ def copy_directory_remote_to_local(conn, remotedir, localdir):
                 os.mkdir(l_name)
             else:
                 data = conn.loadfile(r_name)
-                file(l_name, 'w').write(data)
+                open(l_name, 'w').write(data)
 
 
 def copy_directory_local_to_remote(conn, localdir, remotedir):
@@ -274,7 +274,7 @@ def copy_directory_local_to_remote(conn, localdir, remotedir):
                 r_dirs.append(r_name)
                 conn.mkdir(r_name)
             else:
-                data = file(l_name, 'r').read()
+                data = open(l_name, 'r').read()
                 conn.savefile(r_name, data)
 
 
@@ -943,7 +943,7 @@ class cmd_create(Command):
             os.mkdir(os.path.join(gpodir, "Machine"))
             os.mkdir(os.path.join(gpodir, "User"))
             gpt_contents = "[General]\r\nVersion=0\r\n"
-            file(os.path.join(gpodir, "GPT.INI"), "w").write(gpt_contents)
+            open(os.path.join(gpodir, "GPT.INI"), "w").write(gpt_contents)
         except Exception as e:
             raise CommandError("Error Creating GPO files", e)
 
index 7a85546c53eca272103a557eaa28642f8c0afbc7..3d59c7010661efa1b345502008a93e25d384be55 100644 (file)
@@ -806,7 +806,7 @@ def create_samdb_copy(samdb, logger, paths, names, domainsid, domainguid):
     domainpart_file = os.path.join(dns_dir, partfile[domaindn])
     try:
         os.mkdir(dns_samldb_dir)
-        file(domainpart_file, 'w').close()
+        open(domainpart_file, 'w').close()
 
         # Fill the basedn and @OPTION records in domain partition
         dom_url = "%s://%s" % (backend_store, domainpart_file)
index bb598b424521716076c4b94a96a8ad3414f210f9..8f32d46ef49f76393797b5badf7a7428ab883b17 100755 (executable)
@@ -79,7 +79,7 @@ class TestProtocolClient(unittest.TestResult):
     suite = make_suite()
     # Create a stream (any object with a 'write' method). This should accept
     # bytes not strings: subunit is a byte orientated protocol.
-    stream = file('tests.log', 'wb')
+    stream = open('tests.log', 'wb')
     # Create a subunit result object which will output to the stream
     result = subunit.TestProtocolClient(stream)
     # Optionally, to get timing data for performance analysis, wrap the