Use open() instead of file()
authorGuido Günther <agx@sigxcpu.org>
Wed, 28 Aug 2013 17:30:12 +0000 (19:30 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 28 Aug 2013 17:30:12 +0000 (19:30 +0200)
since the later doesn't exist in python3

19 files changed:
gbp/deb/changelog.py
gbp/deb/control.py
gbp/deb/dscfile.py
gbp/deb/format.py
gbp/deb/source.py
gbp/git/repository.py
gbp/patch_series.py
gbp/scripts/common/pq.py
gbp/scripts/dch.py
gbp/scripts/pq.py
setup.py
tests/07_test_fastimport.py
tests/09_test_write_tree.py
tests/11_test_dch_main.py
tests/15_test_DebianSource.py
tests/16_test_supercommand.py
tests/test_Config.py
tests/test_GitVfs.py
tests/testutils.py

index 2857431..356f74d 100644 (file)
@@ -115,7 +115,7 @@ class ChangeLog(object):
         self._cp = cp
 
     def _read(self):
-            with file(self.filename) as f:
+            with open(self.filename) as f:
                 self._contents = f.read()
 
     def __getitem__(self, item):
index b15d360..a4cef2f 100644 (file)
@@ -47,7 +47,7 @@ class Control(object):
             if not os.access(filename, os.F_OK):
                 raise NoControlError("Control file %s does not exist" % filename)
 
-            with file(filename) as f:
+            with open(filename) as f:
                 control = email.message_from_file(f)
 
         if not control.items():
index abaf690..e2492dc 100644 (file)
@@ -49,7 +49,7 @@ class DscFile(object):
         self.native = False
         self.dscfile = os.path.abspath(dscfile)
 
-        f = file(self.dscfile)
+        f = open(self.dscfile)
         fromdir = os.path.dirname(os.path.abspath(dscfile))
         for line in f:
             m = self.version_re.match(line)
index 9abba73..3a4c8ab 100644 (file)
@@ -92,7 +92,7 @@ class DebianSourceFormat(object):
         'quilt'
         >>> os.unlink(t.name)
         """
-        with file(filename) as f:
+        with open(filename) as f:
             return klass(f.read())
 
     @classmethod
@@ -107,7 +107,7 @@ class DebianSourceFormat(object):
             the above parameters
         """
         format_file = format_file or klass.format_file
-        with file(klass.format_file, 'w') as f:
+        with open(klass.format_file, 'w') as f:
             f.write("%s (%s)" % (version, type))
         return klass.parse_file(klass.format_file)
 
index 1e87312..c740361 100644 (file)
@@ -32,7 +32,7 @@ class FileVfs(object):
 
     def open(self, path, flags=None):
         flags = flags or 'r'
-        return file(os.path.join(self._dir, path), flags)
+        return open(os.path.join(self._dir, path), flags)
 
 class DebianSourceError(Exception):
     pass
index 3fe8d6f..a9204c5 100644 (file)
@@ -1653,7 +1653,7 @@ class GitRepository(object):
                 raise GitRepositoryError("Error running git init: %s" % stderr)
 
             if description:
-                with file(os.path.join(abspath, git_dir, "description"), 'w') as f:
+                with open(os.path.join(abspath, git_dir, "description"), 'w') as f:
                     description += '\n' if description[-1] != '\n' else ''
                     f.write(description)
             return klass(abspath)
index 6a65446..10fccfc 100644 (file)
@@ -167,7 +167,7 @@ class PatchSeries(list):
             return []
 
         try:
-            s = file(seriesfile)
+            s = open(seriesfile)
         except Exception as err:
             raise GbpError("Cannot open series file: %s" % err)
 
index ce06353..7e6e210 100644 (file)
@@ -148,14 +148,14 @@ def patch_write_header(srcname, dstname):
     """
     topic = None
 
-    with file(srcname) as src:
+    with open(srcname) as src:
         header = patch_read_header(src)
         header_len = len(''.join(header))
 
         topic = patch_header_parse_topic(header)
         patch_header_mangle_newline(header)
 
-    with file(dstname, 'w') as dst:
+    with open(dstname, 'w') as dst:
         dst.write(''.join(header[1:]))
 
     return (header_len, topic)
@@ -165,9 +165,9 @@ def patch_write_content(srcname, dstname, header_len):
     """
     Write out the patch body skipping the header
     """
-    with file(srcname) as src:
+    with open(srcname) as src:
         src.seek(header_len, 0)
-        with file(dstname, 'a') as dst:
+        with open(dstname, 'a') as dst:
             dst.write(src.read())
 
 
index eb4de5a..a848d6d 100644 (file)
@@ -126,8 +126,8 @@ def mangle_changelog(changelog, cp, snapshot=''):
     """
     try:
         tmpfile = '%s.%s' % (changelog, snapshot)
-        cw = file(tmpfile, 'w')
-        cr = file(changelog, 'r')
+        cw = open(tmpfile, 'w')
+        cr = open(changelog, 'r')
 
         print >>cw, ("%(Source)s (%(MangledVersion)s) "
                      "%(Distribution)s; urgency=%(urgency)s\n" % cp)
index 78f061a..6885078 100755 (executable)
@@ -59,7 +59,7 @@ def export_patches(repo, branch, options):
                                   signature=False,
                                   symmetric=False)
     if patches:
-        f = file(SERIES_FILE, 'w')
+        f = open(SERIES_FILE, 'w')
         gbp.log.info("Regenerating patch queue in '%s'." % PATCH_DIR)
         for patch in patches:
             filename = write_patch(patch, PATCH_DIR, options)
index 23bde20..fb6f624 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ def fetch_version():
     except OSError:
         pass # Failing is fine, we just can't print the version then
 
-    with file('gbp/version.py', 'w') as f:
+    with open('gbp/version.py', 'w') as f:
         f.write('"The current gbp version number"\n')
         f.write('gbp_version="%s"\n' % version)
 
index 42824f9..0a14d38 100644 (file)
@@ -38,7 +38,7 @@ def test_add_file():
     fastimport.deleteall()
     testfile = os.path.join(repo.path, '.git', 'description')
     fastimport.add_file('./testfile',
-                        file(testfile),
+                        open(testfile),
                         os.path.getsize(testfile))
 
 def test_add_symlink():
index 3534f77..7147da5 100644 (file)
@@ -19,7 +19,7 @@ class TestWriteTree(testutils.DebianGitTestRepo):
         paths = []
         for i in range(4):
             path = os.path.join(self.repo.path, 'testfile%d' % i)
-            with file(path, 'w') as f:
+            with open(path, 'w') as f:
                 print >>f, "testdata %d" % i
             paths.append(path)
         return paths
index 1849a3d..2ce9906 100644 (file)
@@ -79,7 +79,7 @@ class TestScriptDch(DebianGitTestRepo):
             options.extend(dch_options)
         ret = dch.main(options)
         self.assertEqual(ret, 0)
-        return file("debian/changelog").readlines()
+        return open("debian/changelog").readlines()
 
 
     def test_dch_main_new_upstream_version(self):
index 4896b31..feca625 100644 (file)
@@ -52,7 +52,7 @@ class TestDebianSource(testutils.DebianGitTestRepo):
         self.assertRaises(DebianSourceError,
                           source.is_native)
 
-        with file('debian/changelog', 'w') as f:
+        with open('debian/changelog', 'w') as f:
             f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low
 
   * git doesn't like '~' in tag names so replace this with a dot when tagging
index 884437b..f72bb56 100644 (file)
@@ -37,7 +37,7 @@ class TestSuperCommand(unittest.TestCase):
     def test_invalid_command(self):
         """Test if we fail correctly with an invalid command"""
         old_stderr = sys.stderr
-        with file('/dev/null', 'w') as sys.stderr:
+        with open('/dev/null', 'w') as sys.stderr:
             self.assertEqual(gbp.scripts.supercommand.supercommand(
                              ['argv0', 'asdf']), 2)
             self.assertEqual(gbp.scripts.supercommand.supercommand(
index 995d619..9a68f8c 100644 (file)
@@ -71,7 +71,7 @@ def test_parser_fallback():
     >>> tmpdir = str(context.new_tmpdir('foo'))
     >>> confname = os.path.join(tmpdir, 'gbp.conf')
     >>> parser.config_files = [confname]
-    >>> f = file(confname, 'w')
+    >>> f = open(confname, 'w')
     >>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n')
     >>> f.close()
     >>> parser._parse_config_files()
@@ -90,13 +90,13 @@ def test_filter():
     >>> tmpdir = str(context.new_tmpdir('bar'))
     >>> confname = os.path.join(tmpdir, 'gbp.conf')
     >>> parser.config_files = [confname]
-    >>> f = file(confname, 'w')
+    >>> f = open(confname, 'w')
     >>> f.write('[bar]\\nfilter = asdf\\n')
     >>> f.close()
     >>> parser._parse_config_files()
     >>> parser.config['filter']
     ['asdf']
-    >>> f = file(confname, 'w')
+    >>> f = open(confname, 'w')
     >>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
     >>> f.close()
     >>> parser._parse_config_files()
index dda156d..7004db1 100644 (file)
@@ -26,7 +26,7 @@ def test_read():
     >>> import os, gbp.git.vfs
     >>> repo_dir = context.new_tmpdir(__name__)
     >>> repo = gbp.git.GitRepository.create(str(repo_dir))
-    >>> f = file(os.path.join(repo.path, 'foo.txt'), 'w')
+    >>> f = open(os.path.join(repo.path, 'foo.txt'), 'w')
     >>> content = 'al pha\\na\\nb\\nc'
     >>> f.write('al pha\\na\\nb\\nc')
     >>> f.close()
index 617a7ab..c863195 100644 (file)
@@ -38,7 +38,7 @@ class DebianGitTestRepo(unittest.TestCase):
         if not os.path.exists(d):
             os.makedirs(d)
 
-        with file(path, 'w+') as f:
+        with open(path, 'w+') as f:
             content == None or f.write(content)
         self.repo.add_files(name, force=True)
         self.repo.commit_files(path, msg or "added %s" % name)