From f9001464d7d02a5b308a10a9adf3f17010e41a38 Mon Sep 17 00:00:00 2001
From: lethliel <mstrigl@suse.com>
Date: Thu, 13 Dec 2018 15:09:45 +0100
Subject: [PATCH] [python3] build with python3 (mostly bytestring) * return of
get_buildinfo is bytestring with python3 * other variables contain
bytestrings as well now
---
osc/build.py | 62 +++++++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/osc/build.py b/osc/build.py
index b26ae9c9..3caf53e6 100644
--- a/osc/build.py
+++ b/osc/build.py
@@ -23,6 +23,7 @@
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst
from osc.core import get_binarylist, get_binary_file, run_external, return_external, raw_input
from osc.util import rpmquery, debquery, archquery
+from osc.util.helper import decode_it
import osc.conf
from . import oscerr
import subprocess
@@ -440,11 +441,11 @@ def get_prefer_pkgs(dirs, wanted_arch, type, cpio):
packageQuery = packagequery.PackageQuery.query(path)
packageQueries.add(packageQuery)
- prefer_pkgs = dict((name, packageQuery.path())
+ prefer_pkgs = dict((decode_it(name), packageQuery.path())
for name, packageQuery in packageQueries.items())
depfile = create_deps(packageQueries.values())
- cpio.add('deps', '\n'.join(depfile))
+ cpio.add(b'deps', b'\n'.join(depfile))
return prefer_pkgs
@@ -455,22 +456,22 @@ def create_deps(pkgqs):
"""
depfile = []
for p in pkgqs:
- id = '%s.%s-0/0/0: ' % (p.name(), p.arch())
- depfile.append('P:%s%s' % (id, ' '.join(p.provides())))
- depfile.append('R:%s%s' % (id, ' '.join(p.requires())))
+ id = b'%s.%s-0/0/0: ' % (p.name(), p.arch())
+ depfile.append(b'P:%s%s' % (id, b' '.join(p.provides())))
+ depfile.append(b'R:%s%s' % (id, b' '.join(p.requires())))
d = p.conflicts()
if d:
- depfile.append('C:%s%s' % (id, ' '.join(d)))
+ depfile.append(b'C:%s%s' % (id, b' '.join(d)))
d = p.obsoletes()
if d:
- depfile.append('O:%s%s' % (id, ' '.join(d)))
+ depfile.append(b'O:%s%s' % (id, b' '.join(d)))
d = p.recommends()
if d:
- depfile.append('r:%s%s' % (id, ' '.join(d)))
+ depfile.append(b'r:%s%s' % (id, b' '.join(d)))
d = p.supplements()
if d:
- depfile.append('s:%s%s' % (id, ' '.join(d)))
- depfile.append('I:%s%s-%s 0-%s' % (id, p.name(), p.evr(), p.arch()))
+ depfile.append(b's:%s%s' % (id, b' '.join(d)))
+ depfile.append(b'I:%s%s-%s 0-%s' % (id, p.name(), p.evr().encode(), p.arch()))
return depfile
@@ -661,24 +662,24 @@ def main(apiurl, opts, argv):
extra_pkgs += xp
prefer_pkgs = {}
- build_descr_data = open(build_descr).read()
+ build_descr_data = open(build_descr, 'rb').read()
# XXX: dirty hack but there's no api to provide custom defines
if opts.without:
s = ''
for i in opts.without:
s += "%%define _without_%s 1\n" % i
- build_descr_data = s + build_descr_data
+ build_descr_data = s.encode() + build_descr_data
if opts._with:
s = ''
for i in opts._with:
s += "%%define _with_%s 1\n" % i
- build_descr_data = s + build_descr_data
+ build_descr_data = s.encode() + build_descr_data
if opts.define:
s = ''
for i in opts.define:
s += "%%define %s\n" % i
- build_descr_data = s + build_descr_data
+ build_descr_data = s.encode + build_descr_data
cpiodata = None
servicefile = os.path.join(os.path.dirname(build_descr), "_service")
@@ -708,12 +709,12 @@ def main(apiurl, opts, argv):
prefer_pkgs = get_prefer_pkgs(opts.prefer_pkgs, arch, build_type, cpiodata)
if cpiodata:
- cpiodata.add(os.path.basename(build_descr), build_descr_data)
+ cpiodata.add(os.path.basename(build_descr.encode()), build_descr_data)
# buildenv must come last for compatibility reasons...
if buildenvfile:
- cpiodata.add("buildenv", open(buildenvfile).read())
+ cpiodata.add(b"buildenv", open(buildenvfile, 'rb').read())
if servicefile:
- cpiodata.add("_service", open(servicefile).read())
+ cpiodata.add(b"_service", open(servicefile, 'rb').read())
build_descr_data = cpiodata.get()
# special handling for overlay and rsync-src/dest
@@ -767,13 +768,14 @@ def main(apiurl, opts, argv):
raise oscerr.WrongOptions('--offline is not possible, no local buildconfig file')
else:
print('Getting buildinfo from server and store to %s' % bi_filename)
- bi_text = ''.join(get_buildinfo(apiurl,
- prj,
- pac,
- repo,
- arch,
- specfile=build_descr_data,
- addlist=extra_pkgs))
+
+ bi_text = decode_it(get_buildinfo(apiurl,
+ prj,
+ pac,
+ repo,
+ arch,
+ specfile=build_descr_data,
+ addlist=extra_pkgs))
if not bi_file:
bi_file = open(bi_filename, 'w')
# maybe we should check for errors before saving the file
@@ -783,7 +785,7 @@ def main(apiurl, opts, argv):
bc = get_buildconfig(apiurl, prj, repo)
if not bc_file:
bc_file = open(bc_filename, 'w')
- bc_file.write(bc)
+ bc_file.write(decode_it(bc))
bc_file.flush()
except HTTPError as e:
if e.code == 404:
@@ -814,7 +816,7 @@ def main(apiurl, opts, argv):
# Set default binary type if cannot be detected
binary_type = 'rpm'
if os.path.exists('/usr/lib/build/queryconfig'):
- binary_type = return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'binarytype').decode('utf-8').strip()
+ binary_type = decode_it(return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'binarytype')).strip()
# If binary type is set to a useless value, reset to 'rpm'
if binary_type == 'UNDEFINED':
binary_type = 'rpm'
@@ -1142,7 +1144,7 @@ def __str__(self):
if bi.installonly_list:
rpmlist.append('installonly: ' + ' '.join(bi.installonly_list) + '\n')
- rpmlist_file = NamedTemporaryFile(prefix='rpmlist.')
+ rpmlist_file = NamedTemporaryFile(mode='w+t', prefix='rpmlist.')
rpmlist_filename = rpmlist_file.name
rpmlist_file.writelines(rpmlist)
rpmlist_file.flush()
@@ -1242,13 +1244,13 @@ def __str__(self):
(s_built, b_built) = get_built_files(pacdir, bi.buildtype)
print()
- if s_built: print(s_built)
+ if s_built: print(decode_it(s_built))
print()
- print(b_built)
+ print(decode_it(b_built))
if opts.keep_pkgs:
for i in b_built.splitlines() + s_built.splitlines():
- shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(i)))
+ shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(decode_it(i))))
if bi_file:
bi_file.close()