python-modernize -f libmodernize.fixes.fix_file

This commit is contained in:
Tomas Kopecek 2017-05-03 11:42:09 +02:00
parent 68bf19c739
commit a4a1536a03
13 changed files with 58 additions and 58 deletions

View file

@ -256,7 +256,7 @@ class BuildRoot(object):
output = koji.genMockConfig(self.name, self.br_arch, managed=True, **opts)
#write config
fo = file(configfile,'w')
fo = open(configfile,'w')
fo.write(output)
fo.close()
@ -356,7 +356,7 @@ class BuildRoot(object):
</settings>
"""
settings = settings % locals()
fo = file(self.rootdir() + destfile, 'w')
fo = open(self.rootdir() + destfile, 'w')
fo.write(settings)
fo.close()
@ -410,7 +410,7 @@ class BuildRoot(object):
self.logger.info('Rereading %s, inode: %s -> %s, size: %s -> %s' %
(fpath, inode, stat_info.st_ino, size, stat_info.st_size))
fd.close()
fd = file(fpath, 'r')
fd = open(fpath, 'r')
logs[fname] = (fd, stat_info.st_ino, stat_info.st_size, fpath)
except:
self.logger.error("Error reading mock log: %s", fpath)
@ -1746,7 +1746,7 @@ class WrapperRPMTask(BaseBuildTask):
contents = contents.encode('utf-8')
specfile = spec_template[:-5]
specfd = file(specfile, 'w')
specfd = open(specfile, 'w')
specfd.write(contents)
specfd.close()
@ -4849,7 +4849,7 @@ class CreaterepoTask(BaseTaskHandler):
if external_repos:
self.merge_repos(external_repos, arch, groupdata)
elif pkglist is None:
fo = file(os.path.join(self.datadir, "EMPTY_REPO"), 'w')
fo = open(os.path.join(self.datadir, "EMPTY_REPO"), 'w')
fo.write("This repo is empty because its tag has no content for this arch\n")
fo.close()
@ -5064,7 +5064,7 @@ class createDistRepoTask(CreaterepoTask):
self.pkglist = None
self.create_local_repo(self.rinfo, arch, self.pkglist, groupdata, None, oldpkgs=oldpkgs)
if self.pkglist is None:
fo = file(os.path.join(self.datadir, "EMPTY_REPO"), 'w')
fo = open(os.path.join(self.datadir, "EMPTY_REPO"), 'w')
fo.write("This repo is empty because its tag has no content for this arch\n")
fo.close()
files = ['pkglist', 'kojipkgs']
@ -5271,7 +5271,7 @@ enabled=1
#generate pkglist files
pkgfile = os.path.join(self.repodir, 'pkglist')
pkglist = file(pkgfile, 'w')
pkglist = open(pkgfile, 'w')
fs_missing = []
sig_missing = []
kojipkgs = {}
@ -5344,7 +5344,7 @@ enabled=1
def write_kojipkgs(self):
filename = os.path.join(self.repodir, 'kojipkgs')
datafile = file(filename, 'w')
datafile = open(filename, 'w')
try:
json.dump(self.kojipkgs, datafile, indent=4)
finally:

View file

@ -238,7 +238,7 @@ class RepoMerge(object):
include_srpms[srpm_name] = (pkg.sourcerpm, pkg.repoid)
pkgorigins = os.path.join(self.yumbase.conf.cachedir, 'pkgorigins')
origins = file(pkgorigins, 'w')
origins = open(pkgorigins, 'w')
seen_rpms = {}
for repo in repos:
@ -283,7 +283,7 @@ def main(args):
opts = parse_args(args)
if opts.blocked:
blocked_fo = file(opts.blocked)
blocked_fo = open(opts.blocked)
blocked_list = blocked_fo.readlines()
blocked_fo.close()
blocked = dict([(b.strip(), 1) for b in blocked_list])

View file

@ -1496,7 +1496,7 @@ def anon_handle_mock_config(options, session, args):
name = "%(tag_name)s-repo_%(repoid)s" % opts
output = koji.genMockConfig(name, arch, **opts)
if options.ofile:
fo = file(options.ofile, 'w')
fo = open(options.ofile, 'w')
fo.write(output)
fo.close()
else:
@ -1764,7 +1764,7 @@ def handle_import_cg(options, session, args):
parser.error(_("Unable to find json module"))
assert False # pragma: no cover
activate_session(session)
metadata = json.load(file(args[0], 'r'))
metadata = json.load(open(args[0], 'r'))
if 'output' not in metadata:
print(_("Metadata contains no output"))
sys.exit(1)
@ -2029,11 +2029,11 @@ def handle_prune_signed_copies(options, session, args):
#(with the modification that we check to see if the build was latest within
#the last N days)
if options.ignore_tag_file:
fo = file(options.ignore_tag_file)
fo = open(options.ignore_tag_file)
options.ignore_tag.extend([line.strip() for line in fo.readlines()])
fo.close()
if options.protect_tag_file:
fo = file(options.protect_tag_file)
fo = open(options.protect_tag_file)
options.protect_tag.extend([line.strip() for line in fo.readlines()])
fo.close()
if options.debug:
@ -6866,7 +6866,7 @@ def anon_handle_download_logs(options, session, args):
full_filename = os.path.normpath(os.path.join(task_log_dir, FAIL_LOG))
koji.ensuredir(os.path.dirname(full_filename))
sys.stdout.write("Writing: %s\n" % full_filename)
file(full_filename, 'w').write(content)
open(full_filename, 'w').write(content)
def download_log(task_log_dir, task_id, filename, blocksize=102400, volume=None):
# Create directories only if there is any log file to write to
@ -6879,11 +6879,11 @@ def anon_handle_download_logs(options, session, args):
contents = 'IGNORE ME!'
if suboptions.cont and os.path.exists(full_filename):
sys.stdout.write("Continuing: %s\n" % full_filename)
fd = file(full_filename, 'ab')
fd = open(full_filename, 'ab')
offset = fd.tell()
else:
sys.stdout.write("Downloading: %s\n" % full_filename)
fd = file(full_filename, 'wb')
fd = open(full_filename, 'wb')
offset = 0
try:
while contents:

View file

@ -2330,7 +2330,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None):
groupsdir = "%s/groups" % (repodir)
koji.ensuredir(groupsdir)
comps = koji.generate_comps(groups, expand_groups=True)
fo = file("%s/comps.xml" % groupsdir, 'w')
fo = open("%s/comps.xml" % groupsdir, 'w')
fo.write(comps)
fo.close()
@ -2349,7 +2349,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None):
top_relpath = koji.util.relpath(koji.pathinfo.topdir, archdir)
top_link = os.path.join(archdir, 'toplink')
os.symlink(top_relpath, top_link)
pkglist[repoarch] = file(os.path.join(archdir, 'pkglist'), 'w')
pkglist[repoarch] = open(os.path.join(archdir, 'pkglist'), 'w')
#NOTE - rpms is now an iterator
for rpminfo in rpms:
if not with_debuginfo and koji.is_debuginfo(rpminfo['name']):
@ -2374,7 +2374,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None):
#write blocked package lists
for repoarch in repo_arches:
blocklist = file(os.path.join(repodir, repoarch, 'blocklist'), 'w')
blocklist = open(os.path.join(repodir, repoarch, 'blocklist'), 'w')
for pkg in blocks:
blocklist.write(pkg['package_name'])
blocklist.write('\n')
@ -2441,7 +2441,7 @@ def _write_maven_repo_metadata(destdir, artifacts):
</versioning>
</metadata>
""" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')
mdfile = file(os.path.join(destdir, 'maven-metadata.xml'), 'w')
mdfile = open(os.path.join(destdir, 'maven-metadata.xml'), 'w')
mdfile.write(contents)
mdfile.close()
_generate_maven_metadata(destdir)
@ -5973,7 +5973,7 @@ def check_old_image_files(old):
(img_path, img_size, old['filesize']))
# old images always used sha256 hashes
sha256sum = hashlib.sha256()
image_fo = file(img_path, 'r')
image_fo = open(img_path, 'r')
while True:
data = image_fo.read(1048576)
sha256sum.update(data)
@ -6125,7 +6125,7 @@ def import_archive_internal(filepath, buildinfo, type, typeInfo, buildroot_id=No
filename = koji.fixEncoding(os.path.basename(filepath))
archiveinfo['filename'] = filename
archiveinfo['size'] = os.path.getsize(filepath)
archivefp = file(filepath)
archivefp = open(filepath)
m = md5_constructor()
while True:
contents = archivefp.read(8192)
@ -6265,14 +6265,14 @@ def _generate_maven_metadata(mavendir):
sumfile = mavenfile + ext
if sumfile not in mavenfiles:
sum = sum_constr()
fobj = file('%s/%s' % (mavendir, mavenfile))
fobj = open('%s/%s' % (mavendir, mavenfile))
while True:
content = fobj.read(8192)
if not content:
break
sum.update(content)
fobj.close()
sumobj = file('%s/%s' % (mavendir, sumfile), 'w')
sumobj = open('%s/%s' % (mavendir, sumfile), 'w')
sumobj.write(sum.hexdigest())
sumobj.close()
@ -6328,7 +6328,7 @@ def add_rpm_sig(an_rpm, sighdr):
# - write to fs
sigpath = "%s/%s" % (builddir, koji.pathinfo.sighdr(rinfo, sigkey))
koji.ensuredir(os.path.dirname(sigpath))
fo = file(sigpath, 'wb')
fo = open(sigpath, 'wb')
fo.write(sighdr)
fo.close()
koji.plugin.run_callbacks('postRPMSign', sigkey=sigkey, sighash=sighash, build=binfo, rpm=rinfo)
@ -6344,7 +6344,7 @@ def _scan_sighdr(sighdr, fn):
sig_start, sigsize = koji.find_rpm_sighdr(fn)
hdr_start = sig_start + sigsize
hdrsize = koji.rpm_hdr_size(fn, hdr_start)
inp = file(fn, 'rb')
inp = open(fn, 'rb')
outp = tempfile.TemporaryFile(mode='w+b')
#before signature
outp.write(inp.read(sig_start))
@ -6381,7 +6381,7 @@ def check_rpm_sig(an_rpm, sigkey, sighdr):
koji.splice_rpm_sighdr(sighdr, rpm_path, temp)
ts = rpm.TransactionSet()
ts.setVSFlags(0) #full verify
fo = file(temp, 'rb')
fo = open(temp, 'rb')
hdr = ts.hdrFromFdno(fo.fileno())
fo.close()
except:
@ -6444,7 +6444,7 @@ def write_signed_rpm(an_rpm, sigkey, force=False):
else:
os.unlink(signedpath)
sigpath = "%s/%s" % (builddir, koji.pathinfo.sighdr(rinfo, sigkey))
fo = file(sigpath, 'rb')
fo = open(sigpath, 'rb')
sighdr = fo.read()
fo.close()
koji.ensuredir(os.path.dirname(signedpath))
@ -8916,7 +8916,7 @@ class RootExports(object):
if not os.path.isfile(filePath):
raise koji.GenericError('no file "%s" output by task %i' % (fileName, taskID))
# Let the caller handler any IO or permission errors
f = file(filePath, 'r')
f = open(filePath, 'r')
if isinstance(offset, str):
offset = int(offset)
if offset != None and offset > 0:
@ -12478,11 +12478,11 @@ def get_upload_path(reldir, name, create=False, volume=None):
# assuming login was asserted earlier
u_fn = os.path.join(udir, '.user')
if os.path.exists(u_fn):
user_id = int(file(u_fn, 'r').read())
user_id = int(open(u_fn, 'r').read())
if context.session.user_id != user_id:
raise koji.GenericError("Invalid upload directory, not owner: %s" % orig_reldir)
else:
fo = file(u_fn, 'w')
fo = open(u_fn, 'w')
fo.write(str(context.session.user_id))
fo.close()
return os.path.join(udir, name)

View file

@ -552,7 +552,7 @@ def rpm_hdr_size(f, ofs=None):
ofs = offset of the header
"""
if isinstance(f, (str, six.text_type)):
fo = file(f, 'rb')
fo = open(f, 'rb')
else:
fo = f
if ofs != None:
@ -742,7 +742,7 @@ class RawHeader(object):
def rip_rpm_sighdr(src):
"""Rip the signature header out of an rpm"""
(start, size) = find_rpm_sighdr(src)
fo = file(src, 'rb')
fo = open(src, 'rb')
fo.seek(start, 0)
sighdr = fo.read(size)
fo.close()
@ -753,7 +753,7 @@ def rip_rpm_hdr(src):
(start, size) = find_rpm_sighdr(src)
start += size
size = rpm_hdr_size(src, start)
fo = file(src, 'rb')
fo = open(src, 'rb')
fo.seek(start, 0)
hdr = fo.read(size)
fo.close()
@ -852,8 +852,8 @@ def splice_rpm_sighdr(sighdr, src, dst=None, bufsize=8192):
if dst is None:
(fd, dst) = tempfile.mkstemp()
os.close(fd)
src_fo = file(src, 'rb')
dst_fo = file(dst, 'wb')
src_fo = open(src, 'rb')
dst_fo = open(dst, 'wb')
dst_fo.write(src_fo.read(start))
dst_fo.write(sighdr)
src_fo.seek(size, 1)
@ -872,7 +872,7 @@ def get_rpm_header(f, ts=None):
ts = rpm.TransactionSet()
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
if isinstance(f, (str, six.text_type)):
fo = file(f, "r")
fo = open(f, "r")
else:
fo = f
hdr = ts.hdrFromFdno(fo.fileno())
@ -1116,7 +1116,7 @@ def parse_pom(path=None, contents=None):
values = {}
handler = POMHandler(values, fields)
if path:
fd = file(path)
fd = open(path)
contents = fd.read()
fd.close()
@ -1431,7 +1431,7 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
if opts.get('use_host_resolv', False) and os.path.exists('/etc/hosts'):
# if we're setting up DNS,
# also copy /etc/hosts from the host
etc_hosts = file('/etc/hosts')
etc_hosts = open('/etc/hosts')
files['etc/hosts'] = etc_hosts.read()
etc_hosts.close()
mavenrc = ''
@ -2494,7 +2494,7 @@ class ClientSession(object):
if name is None:
name = os.path.basename(localfile)
self.logger.debug("Fast upload: %s to %s/%s", localfile, path, name)
fo = file(localfile, 'rb')
fo = open(localfile, 'rb')
ofs = 0
size = os.path.getsize(localfile)
start = time.time()
@ -2602,7 +2602,7 @@ class ClientSession(object):
start = time.time()
# XXX - stick in a config or something
retries = 3
fo = file(localfile, "r") #specify bufsize?
fo = open(localfile, "r") #specify bufsize?
totalsize = os.path.getsize(localfile)
ofs = 0
md5sum = md5_constructor()

View file

@ -146,7 +146,7 @@ def log_output(session, path, args, outfile, uploadpath, cwd=None, logerror=0, a
if not outfd:
try:
outfd = file(outfile, 'r')
outfd = open(outfile, 'r')
except IOError:
# will happen if the forked process has not created the logfile yet
continue
@ -665,7 +665,7 @@ class TaskManager(object):
fn = "%s/%s" % (configdir, f)
if not os.path.isfile(fn):
continue
fo = file(fn, 'r')
fo = open(fn, 'r')
id = None
name = None
for n in range(10):
@ -931,14 +931,14 @@ class TaskManager(object):
proc_path = '/proc/%i/stat' % pid
if not os.path.isfile(proc_path):
return None
proc_file = file(proc_path)
proc_file = open(proc_path)
procstats = [not field.isdigit() and field or int(field) for field in proc_file.read().split()]
proc_file.close()
cmd_path = '/proc/%i/cmdline' % pid
if not os.path.isfile(cmd_path):
return None
cmd_file = file(cmd_path)
cmd_file = open(cmd_path)
procstats[1] = cmd_file.read().replace('\0', ' ').strip()
cmd_file.close()
if not procstats[1]:

View file

@ -314,7 +314,7 @@ class BaseTaskHandler(object):
fsrc = urllib2.urlopen(url)
if not os.path.exists(os.path.dirname(fn)):
os.makedirs(os.path.dirname(fn))
fdst = file(fn, 'w')
fdst = open(fn, 'w')
shutil.copyfileobj(fsrc, fdst)
fsrc.close()
fdst.close()

View file

@ -591,7 +591,7 @@ def parse_maven_params(confs, chain=False, scratch=False):
confs = [confs]
config = six.moves.configparser.ConfigParser()
for conf in confs:
conf_fd = file(conf)
conf_fd = open(conf)
config.readfp(conf_fd)
conf_fd.close()
builds = {}

View file

@ -51,7 +51,7 @@ def maven_import(cbtype, *args, **kws):
shutil.rmtree(tmpdir)
def expand_rpm(filepath, tmpdir):
devnull = file('/dev/null', 'r+')
devnull = open('/dev/null', 'r+')
rpm2cpio = subprocess.Popen(['/usr/bin/rpm2cpio', filepath],
stdout=subprocess.PIPE,
stdin=devnull, stderr=devnull,

View file

@ -36,7 +36,7 @@ class TestGetUploadPath(unittest.TestCase):
fullpath = '{0}/{1}'.format(work.return_value, reldir)
os.makedirs(fullpath)
with file('{0}/.user'.format(fullpath), 'wb') as f:
with open('{0}/.user'.format(fullpath), 'wb') as f:
f.write('1')
with self.assertRaises(GenericError):

View file

@ -736,7 +736,7 @@ def read_policies(fn=None):
The expected format as follows
test [params] [&& test [params] ...] :: (keep|untag|skip)
"""
fo = file(fn, 'r')
fo = open(fn, 'r')
tests = koji.policy.findSimpleTests(globals())
ret = koji.policy.SimpleRuleSet(fo, tests)
fo.close()

View file

@ -452,7 +452,7 @@ class TrackedBuild(object):
fsrc = urllib2.urlopen(url)
fn = "%s/%s.src.rpm" % (options.workpath, self.nvr)
koji.ensuredir(os.path.dirname(fn))
fdst = file(fn, 'w')
fdst = open(fn, 'w')
shutil.copyfileobj(fsrc, fdst)
fsrc.close()
fdst.close()
@ -892,7 +892,7 @@ class BuildTracker(object):
os.chown(os.path.dirname(dst), 48, 48) #XXX - hack
log ("Downloading %s to %s" % (url, dst))
fsrc = urllib2.urlopen(url)
fdst = file(fn, 'w')
fdst = open(fn, 'w')
shutil.copyfileobj(fsrc, fdst)
fsrc.close()
fdst.close()
@ -905,7 +905,7 @@ class BuildTracker(object):
dst = "%s/%s" % (options.workpath, fn)
log ("Downloading %s to %s..." % (url, dst))
fsrc = urllib2.urlopen(url)
fdst = file(dst, 'w')
fdst = open(dst, 'w')
shutil.copyfileobj(fsrc, fdst)
fsrc.close()
fdst.close()

View file

@ -303,7 +303,7 @@ class WindowsBuild(object):
"""Download the file from buildreq, at filepath, into the basedir"""
destpath = os.path.join(basedir, fileinfo['localpath'])
ensuredir(os.path.dirname(destpath))
destfile = file(destpath, 'w')
destfile = open(destpath, 'w')
offset = 0
checksum = hashlib.md5()
while True:
@ -562,7 +562,7 @@ def upload_file(server, prefix, path):
"""upload a single file to the vmd"""
logger = logging.getLogger('koji.vm')
destpath = os.path.join(prefix, path)
fobj = file(destpath, 'r')
fobj = open(destpath, 'r')
offset = 0
sum = hashlib.md5()
while True:
@ -616,7 +616,7 @@ def setup_logging(opts):
if opts.debug:
level = logging.DEBUG
logger.setLevel(level)
logfd = file(logfile, 'w')
logfd = open(logfile, 'w')
handler = logging.StreamHandler(logfd)
handler.setLevel(level)
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s'))
@ -645,7 +645,7 @@ def stream_logs(server, handler, builds):
if not fd:
if os.path.isfile(log):
try:
fd = file(log, 'r')
fd = open(log, 'r')
logs[log] = (relpath, fd)
except:
log_local('Error opening %s' % log)