Open files as binary where needed
In many cases we need to open files as binary to avoid errors on Py3 about writing binary data to file opened in text mode. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
fcbc3ed4ae
commit
65910f2c33
|
@ -142,7 +142,7 @@ class CompsFilter(object):
|
||||||
|
|
||||||
def write(self, file_obj):
|
def write(self, file_obj):
|
||||||
self.tree.write(file_obj, pretty_print=self.reindent, xml_declaration=True, encoding=self.encoding)
|
self.tree.write(file_obj, pretty_print=self.reindent, xml_declaration=True, encoding=self.encoding)
|
||||||
file_obj.write("\n")
|
file_obj.write(b"\n")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -174,7 +174,7 @@ def main():
|
||||||
|
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
|
|
||||||
file_obj = open(opts.comps_file, "r")
|
with open(opts.comps_file, "rb") as file_obj:
|
||||||
f = CompsFilter(file_obj, reindent=not opts.no_reindent)
|
f = CompsFilter(file_obj, reindent=not opts.no_reindent)
|
||||||
f.filter_packages(opts.arch, opts.arch_only_packages)
|
f.filter_packages(opts.arch, opts.arch_only_packages)
|
||||||
f.filter_groups(opts.arch, opts.arch_only_groups)
|
f.filter_groups(opts.arch, opts.arch_only_groups)
|
||||||
|
@ -199,7 +199,7 @@ def main():
|
||||||
if opts.remove_environments:
|
if opts.remove_environments:
|
||||||
f.remove_environments()
|
f.remove_environments()
|
||||||
|
|
||||||
f.write(open(opts.output, 'w') if opts.output else sys.stdout)
|
f.write(open(opts.output, 'wb') if opts.output else sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -205,7 +205,8 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
|
||||||
if compose.DEBUG and os.path.isfile(global_pkgset_path):
|
if compose.DEBUG and os.path.isfile(global_pkgset_path):
|
||||||
msg = "Populating the global package set from tag '%s'" % compose_tags
|
msg = "Populating the global package set from tag '%s'" % compose_tags
|
||||||
compose.log_warning("[SKIP ] %s" % msg)
|
compose.log_warning("[SKIP ] %s" % msg)
|
||||||
global_pkgset = pickle.load(open(global_pkgset_path, "r"))
|
with open(global_pkgset_path, "rb") as f:
|
||||||
|
global_pkgset = pickle.load(f)
|
||||||
else:
|
else:
|
||||||
global_pkgset = pungi.phases.pkgset.pkgsets.KojiPackageSet(
|
global_pkgset = pungi.phases.pkgset.pkgsets.KojiPackageSet(
|
||||||
koji_wrapper, compose.conf["sigkeys"], logger=compose._logger,
|
koji_wrapper, compose.conf["sigkeys"], logger=compose._logger,
|
||||||
|
@ -239,8 +240,9 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
|
||||||
global_pkgset = pkgset
|
global_pkgset = pkgset
|
||||||
else:
|
else:
|
||||||
global_pkgset.merge(pkgset, None, list(all_arches))
|
global_pkgset.merge(pkgset, None, list(all_arches))
|
||||||
with open(global_pkgset_path, 'w') as f:
|
with open(global_pkgset_path, 'wb') as f:
|
||||||
f.write(pickle.dumps(global_pkgset))
|
data = pickle.dumps(global_pkgset)
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
# write global package list
|
# write global package list
|
||||||
global_pkgset.save_file_list(
|
global_pkgset.save_file_list(
|
||||||
|
|
|
@ -131,15 +131,14 @@ def populate_global_pkgset(compose, file_list, path_prefix):
|
||||||
global_pkgset_path = os.path.join(compose.paths.work.topdir(arch="global"), "packages.pickle")
|
global_pkgset_path = os.path.join(compose.paths.work.topdir(arch="global"), "packages.pickle")
|
||||||
if compose.DEBUG and os.path.isfile(global_pkgset_path):
|
if compose.DEBUG and os.path.isfile(global_pkgset_path):
|
||||||
compose.log_warning("[SKIP ] %s" % msg)
|
compose.log_warning("[SKIP ] %s" % msg)
|
||||||
pkgset = pickle.load(open(global_pkgset_path, "r"))
|
with open(global_pkgset_path, "rb") as f:
|
||||||
|
pkgset = pickle.load(f)
|
||||||
else:
|
else:
|
||||||
compose.log_info(msg)
|
compose.log_info(msg)
|
||||||
pkgset = pungi.phases.pkgset.pkgsets.FilelistPackageSet(compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES)
|
pkgset = pungi.phases.pkgset.pkgsets.FilelistPackageSet(compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES)
|
||||||
pkgset.populate(file_list)
|
pkgset.populate(file_list)
|
||||||
f = open(global_pkgset_path, "w")
|
with open(global_pkgset_path, "wb") as f:
|
||||||
data = pickle.dumps(pkgset)
|
pickle.dump(pkgset, f)
|
||||||
f.write(data)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# write global package list
|
# write global package list
|
||||||
pkgset.save_file_list(compose.paths.work.package_list(arch="global"), remove_path_prefix=path_prefix)
|
pkgset.save_file_list(compose.paths.work.package_list(arch="global"), remove_path_prefix=path_prefix)
|
||||||
|
|
|
@ -71,7 +71,7 @@ class CompsWrapper(object):
|
||||||
if not target_file:
|
if not target_file:
|
||||||
target_file = self.comps_file
|
target_file = self.comps_file
|
||||||
|
|
||||||
with open(target_file, "w") as stream:
|
with open(target_file, "wb") as stream:
|
||||||
stream.write(comps_obj.toprettyxml(indent=" ", encoding="UTF-8"))
|
stream.write(comps_obj.toprettyxml(indent=" ", encoding="UTF-8"))
|
||||||
|
|
||||||
def generate_comps(self):
|
def generate_comps(self):
|
||||||
|
|
|
@ -141,7 +141,7 @@ def touch(path, content=None):
|
||||||
os.makedirs(os.path.dirname(path))
|
os.makedirs(os.path.dirname(path))
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
with open(path, 'w') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue