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):
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():
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)
'quilt'
>>> os.unlink(t.name)
"""
- with file(filename) as f:
+ with open(filename) as f:
return klass(f.read())
@classmethod
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)
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
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)
return []
try:
- s = file(seriesfile)
+ s = open(seriesfile)
except Exception as err:
raise GbpError("Cannot open series file: %s" % err)
"""
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)
"""
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())
"""
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)
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)
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)
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():
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
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):
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
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(
>>> 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()
>>> 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()
>>> 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()
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)