Commit c9d3d93d authored by Guido Günther's avatar Guido Günther

Use open() instead of file()

since the later doesn't exist in python3
parent 8f073ebc
...@@ -115,7 +115,7 @@ class ChangeLog(object): ...@@ -115,7 +115,7 @@ class ChangeLog(object):
self._cp = cp self._cp = cp
def _read(self): def _read(self):
with file(self.filename) as f: with open(self.filename) as f:
self._contents = f.read() self._contents = f.read()
def __getitem__(self, item): def __getitem__(self, item):
......
...@@ -47,7 +47,7 @@ class Control(object): ...@@ -47,7 +47,7 @@ class Control(object):
if not os.access(filename, os.F_OK): if not os.access(filename, os.F_OK):
raise NoControlError("Control file %s does not exist" % filename) 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) control = email.message_from_file(f)
if not control.items(): if not control.items():
......
...@@ -49,7 +49,7 @@ class DscFile(object): ...@@ -49,7 +49,7 @@ class DscFile(object):
self.native = False self.native = False
self.dscfile = os.path.abspath(dscfile) self.dscfile = os.path.abspath(dscfile)
f = file(self.dscfile) f = open(self.dscfile)
fromdir = os.path.dirname(os.path.abspath(dscfile)) fromdir = os.path.dirname(os.path.abspath(dscfile))
for line in f: for line in f:
m = self.version_re.match(line) m = self.version_re.match(line)
......
...@@ -92,7 +92,7 @@ class DebianSourceFormat(object): ...@@ -92,7 +92,7 @@ class DebianSourceFormat(object):
'quilt' 'quilt'
>>> os.unlink(t.name) >>> os.unlink(t.name)
""" """
with file(filename) as f: with open(filename) as f:
return klass(f.read()) return klass(f.read())
@classmethod @classmethod
...@@ -107,7 +107,7 @@ class DebianSourceFormat(object): ...@@ -107,7 +107,7 @@ class DebianSourceFormat(object):
the above parameters the above parameters
""" """
format_file = format_file or klass.format_file 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)) f.write("%s (%s)" % (version, type))
return klass.parse_file(klass.format_file) return klass.parse_file(klass.format_file)
......
...@@ -32,7 +32,7 @@ class FileVfs(object): ...@@ -32,7 +32,7 @@ class FileVfs(object):
def open(self, path, flags=None): def open(self, path, flags=None):
flags = flags or 'r' 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): class DebianSourceError(Exception):
pass pass
......
...@@ -1653,7 +1653,7 @@ class GitRepository(object): ...@@ -1653,7 +1653,7 @@ class GitRepository(object):
raise GitRepositoryError("Error running git init: %s" % stderr) raise GitRepositoryError("Error running git init: %s" % stderr)
if description: 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 '' description += '\n' if description[-1] != '\n' else ''
f.write(description) f.write(description)
return klass(abspath) return klass(abspath)
......
...@@ -167,7 +167,7 @@ class PatchSeries(list): ...@@ -167,7 +167,7 @@ class PatchSeries(list):
return [] return []
try: try:
s = file(seriesfile) s = open(seriesfile)
except Exception as err: except Exception as err:
raise GbpError("Cannot open series file: %s" % err) raise GbpError("Cannot open series file: %s" % err)
......
...@@ -148,14 +148,14 @@ def patch_write_header(srcname, dstname): ...@@ -148,14 +148,14 @@ def patch_write_header(srcname, dstname):
""" """
topic = None topic = None
with file(srcname) as src: with open(srcname) as src:
header = patch_read_header(src) header = patch_read_header(src)
header_len = len(''.join(header)) header_len = len(''.join(header))
topic = patch_header_parse_topic(header) topic = patch_header_parse_topic(header)
patch_header_mangle_newline(header) patch_header_mangle_newline(header)
with file(dstname, 'w') as dst: with open(dstname, 'w') as dst:
dst.write(''.join(header[1:])) dst.write(''.join(header[1:]))
return (header_len, topic) return (header_len, topic)
...@@ -165,9 +165,9 @@ def patch_write_content(srcname, dstname, header_len): ...@@ -165,9 +165,9 @@ def patch_write_content(srcname, dstname, header_len):
""" """
Write out the patch body skipping the header Write out the patch body skipping the header
""" """
with file(srcname) as src: with open(srcname) as src:
src.seek(header_len, 0) src.seek(header_len, 0)
with file(dstname, 'a') as dst: with open(dstname, 'a') as dst:
dst.write(src.read()) dst.write(src.read())
......
...@@ -126,8 +126,8 @@ def mangle_changelog(changelog, cp, snapshot=''): ...@@ -126,8 +126,8 @@ def mangle_changelog(changelog, cp, snapshot=''):
""" """
try: try:
tmpfile = '%s.%s' % (changelog, snapshot) tmpfile = '%s.%s' % (changelog, snapshot)
cw = file(tmpfile, 'w') cw = open(tmpfile, 'w')
cr = file(changelog, 'r') cr = open(changelog, 'r')
print >>cw, ("%(Source)s (%(MangledVersion)s) " print >>cw, ("%(Source)s (%(MangledVersion)s) "
"%(Distribution)s; urgency=%(urgency)s\n" % cp) "%(Distribution)s; urgency=%(urgency)s\n" % cp)
......
...@@ -59,7 +59,7 @@ def export_patches(repo, branch, options): ...@@ -59,7 +59,7 @@ def export_patches(repo, branch, options):
signature=False, signature=False,
symmetric=False) symmetric=False)
if patches: if patches:
f = file(SERIES_FILE, 'w') f = open(SERIES_FILE, 'w')
gbp.log.info("Regenerating patch queue in '%s'." % PATCH_DIR) gbp.log.info("Regenerating patch queue in '%s'." % PATCH_DIR)
for patch in patches: for patch in patches:
filename = write_patch(patch, PATCH_DIR, options) filename = write_patch(patch, PATCH_DIR, options)
......
...@@ -36,7 +36,7 @@ def fetch_version(): ...@@ -36,7 +36,7 @@ def fetch_version():
except OSError: except OSError:
pass # Failing is fine, we just can't print the version then 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('"The current gbp version number"\n')
f.write('gbp_version="%s"\n' % version) f.write('gbp_version="%s"\n' % version)
......
...@@ -38,7 +38,7 @@ def test_add_file(): ...@@ -38,7 +38,7 @@ def test_add_file():
fastimport.deleteall() fastimport.deleteall()
testfile = os.path.join(repo.path, '.git', 'description') testfile = os.path.join(repo.path, '.git', 'description')
fastimport.add_file('./testfile', fastimport.add_file('./testfile',
file(testfile), open(testfile),
os.path.getsize(testfile)) os.path.getsize(testfile))
def test_add_symlink(): def test_add_symlink():
......
...@@ -19,7 +19,7 @@ class TestWriteTree(testutils.DebianGitTestRepo): ...@@ -19,7 +19,7 @@ class TestWriteTree(testutils.DebianGitTestRepo):
paths = [] paths = []
for i in range(4): for i in range(4):
path = os.path.join(self.repo.path, 'testfile%d' % i) 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 print >>f, "testdata %d" % i
paths.append(path) paths.append(path)
return paths return paths
......
...@@ -79,7 +79,7 @@ class TestScriptDch(DebianGitTestRepo): ...@@ -79,7 +79,7 @@ class TestScriptDch(DebianGitTestRepo):
options.extend(dch_options) options.extend(dch_options)
ret = dch.main(options) ret = dch.main(options)
self.assertEqual(ret, 0) self.assertEqual(ret, 0)
return file("debian/changelog").readlines() return open("debian/changelog").readlines()
def test_dch_main_new_upstream_version(self): def test_dch_main_new_upstream_version(self):
......
...@@ -52,7 +52,7 @@ class TestDebianSource(testutils.DebianGitTestRepo): ...@@ -52,7 +52,7 @@ class TestDebianSource(testutils.DebianGitTestRepo):
self.assertRaises(DebianSourceError, self.assertRaises(DebianSourceError,
source.is_native) 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 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 * git doesn't like '~' in tag names so replace this with a dot when tagging
......
...@@ -37,7 +37,7 @@ class TestSuperCommand(unittest.TestCase): ...@@ -37,7 +37,7 @@ class TestSuperCommand(unittest.TestCase):
def test_invalid_command(self): def test_invalid_command(self):
"""Test if we fail correctly with an invalid command""" """Test if we fail correctly with an invalid command"""
old_stderr = sys.stderr 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( self.assertEqual(gbp.scripts.supercommand.supercommand(
['argv0', 'asdf']), 2) ['argv0', 'asdf']), 2)
self.assertEqual(gbp.scripts.supercommand.supercommand( self.assertEqual(gbp.scripts.supercommand.supercommand(
......
...@@ -71,7 +71,7 @@ def test_parser_fallback(): ...@@ -71,7 +71,7 @@ def test_parser_fallback():
>>> tmpdir = str(context.new_tmpdir('foo')) >>> tmpdir = str(context.new_tmpdir('foo'))
>>> confname = os.path.join(tmpdir, 'gbp.conf') >>> confname = os.path.join(tmpdir, 'gbp.conf')
>>> parser.config_files = [confname] >>> parser.config_files = [confname]
>>> f = file(confname, 'w') >>> f = open(confname, 'w')
>>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n') >>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n')
>>> f.close() >>> f.close()
>>> parser._parse_config_files() >>> parser._parse_config_files()
...@@ -90,13 +90,13 @@ def test_filter(): ...@@ -90,13 +90,13 @@ def test_filter():
>>> tmpdir = str(context.new_tmpdir('bar')) >>> tmpdir = str(context.new_tmpdir('bar'))
>>> confname = os.path.join(tmpdir, 'gbp.conf') >>> confname = os.path.join(tmpdir, 'gbp.conf')
>>> parser.config_files = [confname] >>> parser.config_files = [confname]
>>> f = file(confname, 'w') >>> f = open(confname, 'w')
>>> f.write('[bar]\\nfilter = asdf\\n') >>> f.write('[bar]\\nfilter = asdf\\n')
>>> f.close() >>> f.close()
>>> parser._parse_config_files() >>> parser._parse_config_files()
>>> parser.config['filter'] >>> parser.config['filter']
['asdf'] ['asdf']
>>> f = file(confname, 'w') >>> f = open(confname, 'w')
>>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n") >>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
>>> f.close() >>> f.close()
>>> parser._parse_config_files() >>> parser._parse_config_files()
......
...@@ -26,7 +26,7 @@ def test_read(): ...@@ -26,7 +26,7 @@ def test_read():
>>> import os, gbp.git.vfs >>> import os, gbp.git.vfs
>>> repo_dir = context.new_tmpdir(__name__) >>> repo_dir = context.new_tmpdir(__name__)
>>> repo = gbp.git.GitRepository.create(str(repo_dir)) >>> 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' >>> content = 'al pha\\na\\nb\\nc'
>>> f.write('al pha\\na\\nb\\nc') >>> f.write('al pha\\na\\nb\\nc')
>>> f.close() >>> f.close()
......
...@@ -38,7 +38,7 @@ class DebianGitTestRepo(unittest.TestCase): ...@@ -38,7 +38,7 @@ class DebianGitTestRepo(unittest.TestCase):
if not os.path.exists(d): if not os.path.exists(d):
os.makedirs(d) os.makedirs(d)
with file(path, 'w+') as f: with open(path, 'w+') as f:
content == None or f.write(content) content == None or f.write(content)
self.repo.add_files(name, force=True) self.repo.add_files(name, force=True)
self.repo.commit_files(path, msg or "added %s" % name) self.repo.commit_files(path, msg or "added %s" % name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment