From 6c001fa64c39aa60aea7a934e33b4daa854e4a58 Mon Sep 17 00:00:00 2001 From: lethliel 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 | 83 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/osc/build.py b/osc/build.py index b26ae9c9..457249e2 100644 --- a/osc/build.py +++ b/osc/build.py @@ -23,6 +23,7 @@ from osc.fetch import * 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 @@ -498,6 +499,22 @@ def check_trusted_projects(apiurl, projects): config['api_host_options'][apiurl]['trusted_prj'] = trusted conf.config_set_option(apiurl, 'trusted_prj', ' '.join(trusted)) +def get_kiwipath_from_buildinfo(apiurl, bi_filename, prj, repo): + bi = Buildinfo(bi_filename, apiurl, 'kiwi') + # If the project does not have a path defined we need to get the config + # via the repositories in the kiwi file. Unfortunately the buildinfo + # does not include a hint if this is the case, so we rely on a heuristic + # here: if the path list contains our own repo, it probably does not + # come from the kiwi file and thus a path is defined in the config. + # It is unlikely that our own repo is included in the kiwi file, as it + # contains no packages. + myprp = prj + '/' + repo + if myprp in bi.pathes: + return None + kiwipath = bi.pathes + kiwipath.insert(0, myprp) + return kiwipath + def main(apiurl, opts, argv): repo = argv[0] @@ -661,24 +678,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 +725,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,23 +784,27 @@ 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 bi_file.write(bi_text) bi_file.flush() + kiwipath = None + if build_type == 'kiwi': + kiwipath = get_kiwipath_from_buildinfo(apiurl, bi_filename, prj, repo) print('Getting buildconfig from server and store to %s' % bc_filename) - bc = get_buildconfig(apiurl, prj, repo) + bc = get_buildconfig(apiurl, prj, repo, kiwipath) 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 +835,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 +1163,7 @@ def main(apiurl, opts, argv): 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 +1263,13 @@ def main(apiurl, opts, argv): (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()