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