python-modernize -f lib2to3.fixes.file . -w

This commit is contained in:
Tomas Kopecek 2017-10-31 16:04:41 +01:00
parent d6a5cdf987
commit 379ec8ae63
10 changed files with 34 additions and 34 deletions

View file

@ -2331,7 +2331,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()
@ -2350,7 +2350,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']):
@ -2375,7 +2375,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')
@ -2442,7 +2442,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)
@ -6080,7 +6080,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)
@ -6232,7 +6232,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)
@ -6372,14 +6372,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()
@ -6435,7 +6435,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)
@ -6451,7 +6451,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))
@ -6488,7 +6488,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:
@ -6551,7 +6551,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))
@ -9018,7 +9018,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:
@ -12641,11 +12641,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

@ -142,7 +142,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
@ -691,7 +691,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 xrange(10):
@ -957,14 +957,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

@ -322,7 +322,7 @@ class BaseTaskHandler(object):
fsrc = six.moves.urllib.request.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

@ -52,7 +52,7 @@ def maven_import(cbtype, *args, **kws):
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

@ -71,7 +71,7 @@ class TestBuildNotification(unittest.TestCase):
# task_info['id'], method, params, self.session, self.options
task_id = 999
fn = os.path.join(os.path.dirname(__file__), 'data/calls', 'build_notif_1', 'params.json')
with file(fn) as fp:
with open(fn) as fp:
kwargs = json.load(fp)
self.session = MyClientSession('https://koji.example.com/kojihub')
self.session.load_calls('build_notif_1')
@ -95,6 +95,6 @@ class TestBuildNotification(unittest.TestCase):
self.assertEqual(from_addr, "koji@example.com")
self.assertEqual(recipients, ["user@example.com"])
fn = os.path.join(os.path.dirname(__file__), 'data/calls', 'build_notif_1', 'message.txt')
with file(fn) as fp:
with open(fn) as fp:
msg_expect = fp.read()
self.assertEqual(message, msg_expect)

View file

@ -83,15 +83,15 @@ class TestCompleteImageBuild(unittest.TestCase):
def set_up_files(self, name):
datadir = os.path.join(os.path.dirname(__file__), 'data/image', name)
# load image result data for our test build
data = json.load(file(datadir + '/data.json'))
self.db_expect = json.load(file(datadir + '/db.json'))
data = json.load(open(datadir + '/data.json'))
self.db_expect = json.load(open(datadir + '/db.json'))
for arch in data:
taskdir = koji.pathinfo.task(data[arch]['task_id'])
os.makedirs(taskdir)
filenames = data[arch]['files'] + data[arch]['logs']
for filename in filenames:
path = os.path.join(taskdir, filename)
with file(path, 'w') as fp:
with open(path, 'w') as fp:
fp.write('Test file for %s\n%s\n' % (arch, filename))
self.image_data = data

View file

@ -49,7 +49,7 @@ class TestCompleteMavenBuild(unittest.TestCase):
def set_up_files(self, name):
datadir = os.path.join(os.path.dirname(__file__), 'data/maven', name)
# load maven result data for our test build
data = json.load(file(datadir + '/data.json'))
data = json.load(open(datadir + '/data.json'))
data['task_id'] = 9999
taskdir = koji.pathinfo.task(data['task_id'])
for subdir in data['files']:
@ -64,7 +64,7 @@ class TestCompleteMavenBuild(unittest.TestCase):
dst = os.path.join(taskdir, fn)
shutil.copy(src, dst)
self.maven_data = data
files = file(datadir + '/files').readlines()
files = open(datadir + '/files').readlines()
files = [l.strip() for l in files]
self.expected_files = files

View file

@ -31,7 +31,7 @@ class TestGetBuildLogs(unittest.TestCase):
dirpath = os.path.dirname(path)
koji.ensuredir(dirpath)
if path:
with file(path, 'w') as fo:
with open(path, 'w') as fo:
fo.write('TEST LOG FILE CONTENTS\n')
def test_get_build_logs_basic(self):

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

@ -301,7 +301,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:
@ -560,7 +560,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:
@ -614,7 +614,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'))
@ -643,7 +643,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)