Imported Upstream version 0.6.27
[platform/upstream/libsolv.git] / examples / pysolv
index bc12766..3d6ca07 100755 (executable)
@@ -68,11 +68,7 @@ class repo_generic(dict):
         chksum.add("1.1");
         chksum.add(cookie)
         chksum.add_fstat(f.fileno())
-        extcookie = chksum.raw()
-        # compatibility to c code
-        if ord(extcookie[0]) == 0:
-            extcookie[0] = chr(1)
-        return extcookie
+        return chksum.raw()
 
     def cachepath(self, ext = None):
         path = re.sub(r'^\.', '_', self.name)
@@ -92,11 +88,12 @@ class repo_generic(dict):
                 st = os.stat(self.cachepath())
                 if self['metadata_expire'] == -1 or time.time() - st[ST_MTIME] < self['metadata_expire']:
                     dorefresh = False
-            except OSError, e:
+            except OSError:
                 pass
         self['cookie'] = ''
+        self['extcookie'] = ''
         if not dorefresh and self.usecachedrepo(None):
-            print "repo: '%s': cached" % self.name
+            print("repo: '%s': cached" % self.name)
             return True
         return False
 
@@ -107,7 +104,7 @@ class repo_generic(dict):
         if not urls:
             return
         url = urls[0]
-        print "[using mirror %s]" % re.sub(r'^(.*?/...*?)/.*$', r'\1', url)
+        print("[using mirror %s]" % re.sub(r'^(.*?/...*?)/.*$', r'\1', url))
         self['baseurl'] = url
 
     def setfrommetalink(self, metalink):
@@ -161,7 +158,7 @@ class repo_generic(dict):
                     url = file
         if not url:
             if 'baseurl' not in self:
-                print "%s: no baseurl" % self.name
+                print("%s: no baseurl" % self.name)
                 return None
             url = re.sub(r'/$', '', self['baseurl']) + '/' + file
         f = tempfile.TemporaryFile()
@@ -170,20 +167,20 @@ class repo_generic(dict):
             return None
         os.lseek(f.fileno(), 0, os.SEEK_SET)
         if st:
-            print "%s: download error %d" % (file, st)
+            print("%s: download error %d" % (file, st))
             if markincomplete:
                 self['incomplete'] = True
             return None
         if chksum:
             fchksum = solv.Chksum(chksum.type)
             if not fchksum:
-                print "%s: unknown checksum type" % file
+                print("%s: unknown checksum type" % file)
                 if markincomplete:
                     self['incomplete'] = True
                 return None
             fchksum.add_fd(f.fileno())
             if fchksum != chksum:
-                print "%s: checksum mismatch" % file
+                print("%s: checksum mismatch" % file)
                 if markincomplete:
                     self['incomplete'] = True
                 return None
@@ -194,7 +191,7 @@ class repo_generic(dict):
     def usecachedrepo(self, ext, mark=False):
         try: 
             repopath = self.cachepath(ext)
-            f = open(repopath, 'r')
+            f = open(repopath, 'rb')
             f.seek(-32, os.SEEK_END)
             fcookie = f.read(32)
             if len(fcookie) != 32:
@@ -211,6 +208,7 @@ class repo_generic(dict):
                 if len(fextcookie) != 32:
                     return False
             f.seek(0)
+            f = solv.xfopen_fd('', f.fileno())
             flags = 0
             if ext:
                 flags = solv.Repo.REPO_USE_LOADING|solv.Repo.REPO_EXTEND_SOLVABLES
@@ -225,58 +223,64 @@ class repo_generic(dict):
                 # no futimes in python?
                 try:
                     os.utime(repopath, None)
-                except Exception, e:
+                except Exception:
                     pass
-        except IOError, e:
+        except IOError:
             return False
         return True
 
-    def writecachedrepo(self, ext, info=None):
+    def writecachedrepo(self, ext, repodata=None):
         if 'incomplete' in self:
             return
+        tmpname = None
         try:
             if not os.path.isdir("/var/cache/solv"):
-                os.mkdir("/var/cache/solv", 0755)
+                os.mkdir("/var/cache/solv", 0o755)
             (fd, tmpname) = tempfile.mkstemp(prefix='.newsolv-', dir='/var/cache/solv')
-            os.fchmod(fd, 0444)
-            f = os.fdopen(fd, 'w+')
-            if not info:
+            os.fchmod(fd, 0o444)
+            f = os.fdopen(fd, 'wb+')
+            f = solv.xfopen_fd(None, f.fileno())
+            if not repodata:
                 self.handle.write(f)
             elif ext:
-                info.write(f)
-            else:       # rewrite_repos case
+                repodata.write(f)
+            else:       # rewrite_repos case, do not write stubs
                 self.handle.write_first_repodata(f)
+            f.flush()
             if self.type != 'system' and not ext:
-                if 'extcookie' not in self:
+                if not self['extcookie']:
                     self['extcookie'] = self.calc_cookie_ext(f, self['cookie'])
                 f.write(self['extcookie'])
             if not ext:
                 f.write(self['cookie'])
             else:
                 f.write(self['extcookie'])
-            f.close()
+            f.close
             if self.handle.iscontiguous():
                 # switch to saved repo to activate paging and save memory
                 nf = solv.xfopen(tmpname)
                 if not ext:
                     # main repo
                     self.handle.empty()
-                    if not self.handle.add_solv(nf, solv.Repo.SOLV_ADD_NO_STUBS):
+                    flags = solv.Repo.SOLV_ADD_NO_STUBS
+                    if repodata:
+                        flags = 0       # rewrite repos case, recreate stubs
+                    if not self.handle.add_solv(nf, flags):
                         sys.exit("internal error, cannot reload solv file")
                 else:
                     # extension repodata
                     # need to extend to repo boundaries, as this is how
-                    # info.write() has written the data
-                    info.extend_to_repo()
+                    # repodata.write() has written the data
+                    repodata.extend_to_repo()
                     flags = solv.Repo.REPO_EXTEND_SOLVABLES
                     if ext != 'DL':
                         flags |= solv.Repo.REPO_LOCALPOOL
-                    info.add_solv(nf, flags)
+                    repodata.add_solv(nf, flags)
             os.rename(tmpname, self.cachepath(ext))
-        except IOError, e:
+        except (OSError, IOError):
             if tmpname:
                 os.unlink(tmpname)
-                
+
     def updateaddedprovides(self, addedprovides):
         if 'incomplete' in self:
             return 
@@ -298,24 +302,47 @@ class repo_generic(dict):
     def packagespath(self):
         return ''
 
+    def add_ext_keys(self, ext, repodata, handle):
+        if ext == 'DL':
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOSITORY_DELTAINFO)
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_FLEXARRAY)
+        elif ext == 'DU':
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_DISKUSAGE)
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRNUMNUMARRAY)
+        elif ext == 'FL':
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
+            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
+        else:
+            for langtag, langtagtype in [
+                (solv.SOLVABLE_SUMMARY, solv.REPOKEY_TYPE_STR),
+                (solv.SOLVABLE_DESCRIPTION, solv.REPOKEY_TYPE_STR),
+                (solv.SOLVABLE_EULA, solv.REPOKEY_TYPE_STR),
+                (solv.SOLVABLE_MESSAGEINS, solv.REPOKEY_TYPE_STR),
+                (solv.SOLVABLE_MESSAGEDEL, solv.REPOKEY_TYPE_STR),
+                (solv.SOLVABLE_CATEGORY, solv.REPOKEY_TYPE_ID)
+            ]:
+                repodata.add_idarray(handle, solv.REPOSITORY_KEYS, self.handle.pool.id2langid(langtag, ext, 1))
+                repodata.add_idarray(handle, solv.REPOSITORY_KEYS, langtagtype)
+        
+
 class repo_repomd(repo_generic):
     def load(self, pool):
         if super(repo_repomd, self).load(pool):
             return True
-        print "rpmmd repo '%s':" % self.name,
+        sys.stdout.write("rpmmd repo '%s': " % self.name)
         sys.stdout.flush()
         f = self.download("repodata/repomd.xml", False, None, None)
         if not f:
-            print "no repomd.xml file, skipped"
+            print("no repomd.xml file, skipped")
             self.handle.free(True)
             del self.handle
             return False
         self['cookie'] = self.calc_cookie_fp(f)
         if self.usecachedrepo(None, True):
-            print "cached"
+            print("cached")
             return True
         self.handle.add_repomdxml(f, 0)
-        print "fetching"
+        print("fetching")
         (filename, filechksum) = self.find('primary')
         if filename:
             f = self.download(filename, True, filechksum, True)
@@ -335,14 +362,14 @@ class repo_repomd(repo_generic):
         return True
 
     def find(self, what):
-        di = self.handle.Dataiterator(solv.SOLVID_META, solv.REPOSITORY_REPOMD_TYPE, what, solv.Dataiterator.SEARCH_STRING)
+        di = self.handle.Dataiterator_meta(solv.REPOSITORY_REPOMD_TYPE, what, solv.Dataiterator.SEARCH_STRING)
         di.prepend_keyname(solv.REPOSITORY_REPOMD)
         for d in di:
             dp = d.parentpos()
             filename = dp.lookup_str(solv.REPOSITORY_REPOMD_LOCATION)
             chksum = dp.lookup_checksum(solv.REPOSITORY_REPOMD_CHECKSUM)
             if filename and not chksum:
-                print "no %s file checksum!" % filename
+                print("no %s file checksum!" % filename)
                 filename = None
                 chksum = None
             if filename:
@@ -359,12 +386,7 @@ class repo_repomd(repo_generic):
         repodata.set_poolstr(handle, solv.REPOSITORY_REPOMD_TYPE, what)
         repodata.set_str(handle, solv.REPOSITORY_REPOMD_LOCATION, filename)
         repodata.set_checksum(handle, solv.REPOSITORY_REPOMD_CHECKSUM, chksum)
-        if ext == 'DL':
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOSITORY_DELTAINFO)
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_FLEXARRAY)
-        elif ext == 'FL':
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
+        self.add_ext_keys(ext, repodata, handle)
         repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
 
     def add_exts(self):
@@ -404,20 +426,20 @@ class repo_susetags(repo_generic):
     def load(self, pool):
         if super(repo_susetags, self).load(pool):
             return True
-        print "susetags repo '%s':" % self.name,
+        sys.stdout.write("susetags repo '%s': " % self.name)
         sys.stdout.flush()
         f = self.download("content", False, None, None)
         if not f:
-            print "no content file, skipped"
+            print("no content file, skipped")
             self.handle.free(True)
             del self.handle
             return False
         self['cookie'] = self.calc_cookie_fp(f)
         if self.usecachedrepo(None, True):
-            print "cached"
+            print("cached")
             return True
         self.handle.add_content(f, 0)
-        print "fetching"
+        print("fetching")
         defvendorid = self.handle.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
         descrdir = self.handle.meta.lookup_str(solv.SUSETAGS_DESCRDIR)
         if not descrdir:
@@ -444,7 +466,7 @@ class repo_susetags(repo_generic):
         return True
 
     def find(self, what):
-        di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, what, solv.Dataiterator.SEARCH_STRING)
+        di = self.handle.Dataiterator_meta(solv.SUSETAGS_FILE_NAME, what, solv.Dataiterator.SEARCH_STRING)
         di.prepend_keyname(solv.SUSETAGS_FILE)
         for d in di:
             dp = d.parentpos()
@@ -460,31 +482,15 @@ class repo_susetags(repo_generic):
         repodata.set_str(handle, solv.SUSETAGS_FILE_NAME, filename)
         if chksum:
             repodata.set_checksum(handle, solv.SUSETAGS_FILE_CHECKSUM, chksum)
-        if ext == 'DU':
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_DISKUSAGE)
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRNUMNUMARRAY)
-        elif ext == 'FL':
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
-            repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
-        else:
-            for langtag, langtagtype in [
-                (solv.SOLVABLE_SUMMARY, solv.REPOKEY_TYPE_STR),
-                (solv.SOLVABLE_DESCRIPTION, solv.REPOKEY_TYPE_STR),
-                (solv.SOLVABLE_EULA, solv.REPOKEY_TYPE_STR),
-                (solv.SOLVABLE_MESSAGEINS, solv.REPOKEY_TYPE_STR),
-                (solv.SOLVABLE_MESSAGEDEL, solv.REPOKEY_TYPE_STR),
-                (solv.SOLVABLE_CATEGORY, solv.REPOKEY_TYPE_ID)
-            ]:
-                repodata.add_idarray(handle, solv.REPOSITORY_KEYS, self.handle.pool.id2langid(langtag, ext, 1))
-                repodata.add_idarray(handle, solv.REPOSITORY_KEYS, langtagtype)
+        self.add_ext_keys(ext, repodata, handle)
         repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
         
     def add_exts(self):
         repodata = self.handle.add_repodata(0)
-        di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, None, 0)
+        di = self.handle.Dataiterator_meta(solv.SUSETAGS_FILE_NAME, None, 0)
         di.prepend_keyname(solv.SUSETAGS_FILE)
         for d in di:
-            filename = d.str()
+            filename = d.str
             if not filename:
                 continue
             if filename[0:9] != "packages.":
@@ -533,7 +539,7 @@ class repo_susetags(repo_generic):
 
 class repo_unknown(repo_generic):
     def load(self, pool):
-        print "unsupported repo '%s': skipped" % self.name
+        print("unsupported repo '%s': skipped" % self.name)
         return False
 
 class repo_system(repo_generic):
@@ -541,12 +547,12 @@ class repo_system(repo_generic):
         self.handle = pool.add_repo(self.name)
         self.handle.appdata = self
         pool.installed = self.handle
-        print "rpm database:",
+        sys.stdout.write("rpm database: ")
         self['cookie'] = self.calc_cookie_file("/var/lib/rpm/Packages")
         if self.usecachedrepo(None):
-            print "cached"
+            print("cached")
             return True
-        print "reading"
+        print("reading")
         if hasattr(self.handle.__class__, 'add_products'):
             self.handle.add_products("/etc/products.d", solv.Repo.REPO_NO_INTERNALIZE)
         f = solv.xfopen(self.cachepath())
@@ -638,7 +644,7 @@ if options.repos:
     for reponame in options.repos:
         mrepos = [ repo for repo in repos if repo.name == reponame ]
         if not mrepos:
-            print "no repository matches '%s'" % reponame
+            print("no repository matches '%s'" % reponame)
             sys.exit(1)
         repo = mrepos[0]
         if hasattr(repo, 'handle'):
@@ -649,17 +655,17 @@ if options.repos:
 if cmd == 'search':
     pool.createwhatprovides()
     sel = pool.Selection()
-    di = pool.Dataiterator(0, solv.SOLVABLE_NAME, args[0], solv.Dataiterator.SEARCH_SUBSTRING|solv.Dataiterator.SEARCH_NOCASE)
+    di = pool.Dataiterator(solv.SOLVABLE_NAME, args[0], solv.Dataiterator.SEARCH_SUBSTRING|solv.Dataiterator.SEARCH_NOCASE)
     for d in di:
         sel.add_raw(solv.Job.SOLVER_SOLVABLE, d.solvid)
     if repofilter:
        sel.filter(repofilter)
     for s in sel.solvables():
-        print " - %s [%s]: %s" % (s, s.repo.name, s.lookup_str(solv.SOLVABLE_SUMMARY))
+        print(" - %s [%s]: %s" % (s, s.repo.name, s.lookup_str(solv.SOLVABLE_SUMMARY)))
     sys.exit(0)
 
 if cmd not in cmdactionmap:
-    print "unknown command", cmd
+    print("unknown command %s" % cmd)
     sys.exit(1)
 
 cmdlinerepo = None
@@ -670,7 +676,11 @@ if cmd == 'list' or cmd == 'info' or cmd == 'install':
                 cmdlinerepo = repo_cmdline('@commandline', 'cmdline')
                 cmdlinerepo.load(pool)
                 cmdlinerepo['packages'] = {}
-            cmdlinerepo['packages'][arg] = cmdlinerepo.handle.add_rpm(arg, solv.Repo.REPO_REUSE_REPODATA|solv.Repo.REPO_NO_INTERNALIZE)
+            s = cmdlinerepo.handle.add_rpm(arg, solv.Repo.REPO_REUSE_REPODATA|solv.Repo.REPO_NO_INTERNALIZE)
+            if not s:
+                print(pool.errstr)
+                sys.exit(1)
+            cmdlinerepo['packages'][arg] = s
     if cmdlinerepo:
         cmdlinerepo.handle.internalize()
 
@@ -686,7 +696,7 @@ pool.createwhatprovides()
 jobs = []
 for arg in args:
     if cmdlinerepo and arg in cmdlinerepo['packages']:
-        jobs.append(pool.Job(solv.Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg]))
+        jobs.append(pool.Job(solv.Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg].id))
     else:
         flags = solv.Selection.SELECTION_NAME|solv.Selection.SELECTION_PROVIDES|solv.Selection.SELECTION_GLOB
         flags |= solv.Selection.SELECTION_CANON|solv.Selection.SELECTION_DOTARCH|solv.Selection.SELECTION_REL
@@ -702,14 +712,14 @@ for arg in args:
             if repofilter:
                sel.filter(repofilter)
             if not sel.isempty():
-                print "[ignoring case for '%s']" % arg
+                print("[ignoring case for '%s']" % arg)
         if sel.isempty():
-            print "nothing matches '%s'" % arg
+            print("nothing matches '%s'" % arg)
             sys.exit(1)
         if sel.flags() & solv.Selection.SELECTION_FILELIST:
-            print "[using file list match for '%s']" % arg
+            print("[using file list match for '%s']" % arg)
         if sel.flags() & solv.Selection.SELECTION_PROVIDES:
-            print "[using capability match for '%s']" % arg
+            print("[using capability match for '%s']" % arg)
         jobs += sel.jobs(cmdactionmap[cmd])
 
 if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repofilter):
@@ -719,27 +729,27 @@ if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repofilter):
     jobs += sel.jobs(cmdactionmap[cmd])
 
 if not jobs:
-    print "no package matched."
+    print("no package matched.")
     sys.exit(1)
 
 if cmd == 'list' or cmd == 'info':
     for job in jobs:
         for s in job.solvables():
             if cmd == 'info':
-                print "Name:        %s" % s
-                print "Repo:        %s" % s.repo
-                print "Summary:     %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
+                print("Name:        %s" % s)
+                print("Repo:        %s" % s.repo)
+                print("Summary:     %s" % s.lookup_str(solv.SOLVABLE_SUMMARY))
                 str = s.lookup_str(solv.SOLVABLE_URL)
                 if str:
-                    print "Url:         %s" % str
+                    print("Url:         %s" % str)
                 str = s.lookup_str(solv.SOLVABLE_LICENSE)
                 if str:
-                    print "License:     %s" % str
-                print "Description:\n%s" % s.lookup_str(solv.SOLVABLE_DESCRIPTION)
-                print
+                    print("License:     %s" % str)
+                print("Description:\n%s" % s.lookup_str(solv.SOLVABLE_DESCRIPTION))
+                print('')
             else:
-                print "  - %s [%s]" % (s, s.repo)
-                print "    %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
+                print("  - %s [%s]" % (s, s.repo))
+                print("    %s" % s.lookup_str(solv.SOLVABLE_SUMMARY))
     sys.exit(0)
 
 # up magic: use install instead of update if no installed package matches
@@ -762,17 +772,15 @@ while True:
     if not problems:
         break
     for problem in problems:
-        print "Problem %d/%d:" % (problem.id, len(problems))
-        r = problem.findproblemrule()
-        ri = r.info()
-        print ri.problemstr()
+        print("Problem %d/%d:" % (problem.id, len(problems)))
+        print(problem)
         solutions = problem.solutions()
         for solution in solutions:
-            print "  Solution %d:" % solution.id
+            print("  Solution %d:" % solution.id)
             elements = solution.elements(True)
             for element in elements:
-                print "  - %s" % element.str()
-            print
+                print("  - %s" % element.str())
+            print('')
         sol = ''
         while not (sol == 's' or sol == 'q' or (sol.isdigit() and int(sol) >= 1 and int(sol) <= len(solutions))):
             sys.stdout.write("Please choose a solution: ")
@@ -795,39 +803,39 @@ while True:
 trans = solver.transaction()
 del solver
 if trans.isempty():
-    print "Nothing to do."
+    print("Nothing to do.")
     sys.exit(0)
-print
-print "Transaction summary:"
-print
+print('')
+print("Transaction summary:")
+print('')
 for cl in trans.classify(solv.Transaction.SOLVER_TRANSACTION_SHOW_OBSOLETES | solv.Transaction.SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE):
     if cl.type == solv.Transaction.SOLVER_TRANSACTION_ERASE:
-        print "%d erased packages:" % cl.count
+        print("%d erased packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_INSTALL:
-        print "%d installed packages:" % cl.count
+        print("%d installed packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_REINSTALLED:
-        print "%d reinstalled packages:" % cl.count
+        print("%d reinstalled packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_DOWNGRADED:
-        print "%d downgraded packages:" % cl.count
+        print("%d downgraded packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_CHANGED:
-        print "%d changed packages:" % cl.count
+        print("%d changed packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_UPGRADED:
-        print "%d upgraded packages:" % cl.count
+        print("%d upgraded packages:" % cl.count)
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_VENDORCHANGE:
-        print "%d vendor changes from '%s' to '%s':" % (cl.count, cl.fromstr, cl.tostr)
+        print("%d vendor changes from '%s' to '%s':" % (cl.count, cl.fromstr, cl.tostr))
     elif cl.type == solv.Transaction.SOLVER_TRANSACTION_ARCHCHANGE:
-        print "%d arch changes from '%s' to '%s':" % (cl.count, cl.fromstr, cl.tostr)
+        print("%d arch changes from '%s' to '%s':" % (cl.count, cl.fromstr, cl.tostr))
     else:
         continue
     for p in cl.solvables():
         if cl.type == solv.Transaction.SOLVER_TRANSACTION_UPGRADED or cl.type == solv.Transaction.SOLVER_TRANSACTION_DOWNGRADED:
             op = trans.othersolvable(p)
-            print "  - %s -> %s" % (p, op)
+            print("  - %s -> %s" % (p, op))
         else:
-            print "  - %s" % p
-    print
-print "install size change: %d K" % trans.calc_installsizechange()
-print
+            print("  - %s" % p)
+    print('')
+print("install size change: %d K" % trans.calc_installsizechange())
+print('')
 
 while True:
     sys.stdout.write("OK to continue (y/n)? ")
@@ -841,7 +849,7 @@ if newpkgs:
     downloadsize = 0
     for p in newpkgs:
         downloadsize += p.lookup_num(solv.SOLVABLE_DOWNLOADSIZE)
-    print "Downloading %d packages, %d K" % (len(newpkgs), downloadsize)
+    print("Downloading %d packages, %d K" % (len(newpkgs), downloadsize / 1024))
     for p in newpkgs:
         repo = p.repo.appdata
         location, medianr = p.lookup_location()
@@ -855,7 +863,7 @@ if newpkgs:
             continue
         if not sysrepo.handle.isempty() and os.access('/usr/bin/applydeltarpm', os.X_OK):
             pname = p.name
-            di = p.repo.Dataiterator(solv.SOLVID_META, solv.DELTA_PACKAGE_NAME, pname, solv.Dataiterator.SEARCH_STRING)
+            di = p.repo.Dataiterator_meta(solv.DELTA_PACKAGE_NAME, pname, solv.Dataiterator.SEARCH_STRING)
             di.prepend_keyname(solv.REPOSITORY_DELTAINFO)
             for d in di:
                 dp = d.parentpos()
@@ -882,7 +890,11 @@ if newpkgs:
                     continue
                 nf = tempfile.TemporaryFile()
                 nf = os.dup(nf.fileno())   # get rid of CLOEXEC
+                f.cloexec(0)
                 st = subprocess.call(['/usr/bin/applydeltarpm', '-a', p.arch, "/dev/fd/%d" % f.fileno(), "/dev/fd/%d" % nf])
+                if st:
+                    os.close(nf)
+                    continue
                 os.lseek(nf, 0, os.SEEK_SET)
                 newpkgsfp[p.id] = solv.xfopen_fd("", nf)
                 os.close(nf)
@@ -900,9 +912,9 @@ if newpkgs:
         newpkgsfp[p.id] = f
         sys.stdout.write(".")
         sys.stdout.flush()
-    print
-print "Committing transaction:"
-print
+    print('')
+print("Committing transaction:")
+print('')
 ts = rpm.TransactionSet('/')
 ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
 erasenamehelper = {}
@@ -926,22 +938,22 @@ for p in trans.steps():
         ts.addInstall(h, p, 'i')
 checkproblems = ts.check()
 if checkproblems:
-    print checkproblems
+    print(checkproblems)
     sys.exit("Sorry.")
 ts.order()
 def runCallback(reason, amount, total, p, d):
     if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
         return newpkgsfp[p.id].fileno()
     if reason == rpm.RPMCALLBACK_INST_START:
-        print "install", p
+        print("install %s" % p)
     if reason == rpm.RPMCALLBACK_UNINST_START:
         # argh, p is just the name of the package
         if p in erasenamehelper:
             p = erasenamehelper[p]
-            print "erase", p
+            print("erase %s" % p)
 runproblems = ts.run(runCallback, '')
 if runproblems:
-    print runproblems
+    print(runproblems)
     sys.exit(1)
 sys.exit(0)