4 # Copyright (c) 2011, Novell Inc.
6 # This program is licensed under the BSD license, read LICENSE.BSD
7 # for further information
10 # pysolv a little software installer demoing the sat solver library/bindings
13 # - understands globs for package names / dependencies
14 # - understands .arch suffix
15 # - repository data caching
16 # - on demand loading of secondary repository data
17 # - checksum verification
19 # - installation of commandline packages
21 # things not yet ported:
24 # - fastestmirror implementation
26 # things available in the library but missing from pysolv:
27 # - vendor policy loading
28 # - soft locks file handling
29 # - multi version handling
41 from solv import Pool, Repo, Dataiterator, Job, Solver, Transaction, Selection
42 from iniparse import INIConfig
43 from optparse import OptionParser
46 #gc.set_debug(gc.DEBUG_LEAK)
48 class repo_generic(dict):
49 def __init__(self, name, type, attribs = {}):
55 def calc_cookie_file(self, filename):
56 chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
58 chksum.add_stat(filename)
61 def calc_cookie_fp(self, fp):
62 chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
67 def calc_cookie_ext(self, f, cookie):
68 chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
71 chksum.add_fstat(f.fileno())
72 extcookie = chksum.raw()
73 # compatibility to c code
74 if ord(extcookie[0]) == 0:
78 def cachepath(self, ext = None):
79 path = re.sub(r'^\.', '_', self.name)
81 path += "_" + ext + ".solvx"
84 return "/var/cache/solv/" + re.sub(r'[/]', '_', path)
87 self.handle = pool.add_repo(self.name)
88 self.handle.appdata = self
89 self.handle.priority = 99 - self['priority']
90 dorefresh = bool(int(self['autorefresh']))
93 st = os.stat(self.cachepath())
94 if self['metadata_expire'] == -1 or time.time() - st[ST_MTIME] < self['metadata_expire']:
99 if not dorefresh and self.usecachedrepo(None):
100 print "repo: '%s': cached" % self.name
102 return self.load_if_changed()
104 def load_if_changed(self):
107 def load_ext(self, repodata):
110 def setfromurls(self, urls):
114 print "[using mirror %s]" % re.sub(r'^(.*?/...*?)/.*$', r'\1', url)
115 self['baseurl'] = url
117 def setfrommetalink(self, metalink):
118 nf = self.download(metalink, False, None)
121 f = os.fdopen(os.dup(solv.xfileno(nf)), 'r')
125 for l in f.readlines():
127 m = re.match(r'^<hash type="sha256">([0-9a-fA-F]{64})</hash>', l)
129 chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256, m.group(1))
130 m = re.match(r'^<url.*>(https?://.+)repodata/repomd.xml</url>', l)
132 urls.append(m.group(1))
134 chksum = None # in case the metalink is about a different file
136 self.setfromurls(urls)
139 def setfrommirrorlist(self, mirrorlist):
140 nf = self.download(mirrorlist, False, None)
143 f = os.fdopen(os.dup(solv.xfileno(nf)), 'r')
146 for l in f.readline():
148 if l[0:6] == 'http://' or l[0:7] == 'https://':
150 self.setfromurls(urls)
153 def download(self, file, uncompress, chksum, markincomplete=False):
155 if 'baseurl' not in self:
156 if 'metalink' in self:
157 if file != self['metalink']:
158 metalinkchksum = self.setfrommetalink(self['metalink'])
159 if file == 'repodata/repomd.xml' and metalinkchksum and not chksum:
160 chksum = metalinkchksum
163 elif 'mirrorlist' in self:
164 if file != self['mirrorlist']:
165 self.setfrommirrorlist(self['mirrorlist'])
169 if 'baseurl' not in self:
170 print "%s: no baseurl" % self.name
172 url = re.sub(r'/$', '', self['baseurl']) + '/' + file
173 f = tempfile.TemporaryFile()
174 st = subprocess.call(['curl', '-f', '-s', '-L', url], stdout=f.fileno())
175 if os.lseek(f.fileno(), 0, os.SEEK_CUR) == 0 and (st == 0 or not chksum):
177 os.lseek(f.fileno(), 0, os.SEEK_SET)
179 print "%s: download error %d" % (file, st)
181 self['incomplete'] = True
184 fchksum = solv.Chksum(chksum.type)
186 print "%s: unknown checksum type" % file
188 self['incomplete'] = True
190 fchksum.add_fd(f.fileno())
191 if fchksum != chksum:
192 print "%s: checksum mismatch" % file
194 self['incomplete'] = True
197 return solv.xfopen_fd(file, os.dup(f.fileno()))
198 return solv.xfopen_fd(None, os.dup(f.fileno()))
200 def usecachedrepo(self, ext, mark=False):
202 cookie = self['cookie']
204 cookie = self['extcookie']
206 repopath = self.cachepath(ext)
207 f = open(repopath, 'r')
208 f.seek(-32, os.SEEK_END)
210 if len(fcookie) != 32:
212 if cookie and fcookie != cookie:
214 if self.type != 'system' and not ext:
215 f.seek(-32 * 2, os.SEEK_END)
216 fextcookie = f.read(32)
217 if len(fextcookie) != 32:
222 flags = Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES
224 flags |= Repo.REPO_LOCALPOOL
225 if not self.handle.add_solv(f, flags):
227 if self.type != 'system' and not ext:
228 self['cookie'] = fcookie
229 self['extcookie'] = fextcookie
231 # no futimes in python?
233 os.utime(repopath, None)
240 def writecachedrepo(self, ext, info=None):
242 if not os.path.isdir("/var/cache/solv"):
243 os.mkdir("/var/cache/solv", 0755)
244 (fd, tmpname) = tempfile.mkstemp(prefix='.newsolv-', dir='/var/cache/solv')
246 f = os.fdopen(fd, 'w+')
251 else: # rewrite_repos case
252 self.handle.write_first_repodata(f)
253 if self.type != 'system' and not ext:
254 if 'extcookie' not in self:
255 self['extcookie'] = self.calc_cookie_ext(f, self['cookie'])
256 f.write(self['extcookie'])
258 f.write(self['cookie'])
260 f.write(self['extcookie'])
262 if self.handle.iscontiguous():
263 # switch to saved repo to activate paging and save memory
264 nf = solv.xfopen(tmpname)
268 if not self.handle.add_solv(nf, Repo.SOLV_ADD_NO_STUBS):
269 sys.exit("internal error, cannot reload solv file")
272 # need to extend to repo boundaries, as this is how
273 # info.write() has written the data
274 info.extend_to_repo()
275 # LOCALPOOL does not help as pool already contains all ids
276 info.add_solv(nf, Repo.REPO_EXTEND_SOLVABLES)
278 os.rename(tmpname, self.cachepath(ext))
283 def updateaddedprovides(self, addedprovides):
284 if 'incomplete' in self:
286 if not hasattr(self, 'handle'):
288 if self.handle.isempty():
290 # make sure there's just one real repodata with extensions
291 repodata = self.handle.first_repodata()
294 oldaddedprovides = repodata.lookup_idarray(solv.SOLVID_META, solv.REPOSITORY_ADDEDFILEPROVIDES)
295 if not set(addedprovides) <= set(oldaddedprovides):
296 for id in addedprovides:
297 repodata.add_idarray(solv.SOLVID_META, solv.REPOSITORY_ADDEDFILEPROVIDES, id)
298 repodata.internalize()
299 self.writecachedrepo(None, repodata)
301 def packagespath(self):
304 class repo_repomd(repo_generic):
305 def load_if_changed(self):
306 print "rpmmd repo '%s':" % self.name,
308 f = self.download("repodata/repomd.xml", False, None, None)
310 print "no repomd.xml file, skipped"
311 self.handle.free(True)
314 self['cookie'] = self.calc_cookie_fp(f)
315 if self.usecachedrepo(None, True):
319 self.handle.add_repomdxml(f, 0)
322 (filename, filechksum) = self.find('primary')
324 f = self.download(filename, True, filechksum, True)
326 self.handle.add_rpmmd(f, None, 0)
328 if 'incomplete' in self:
329 return False # hopeless, need good primary
330 (filename, filechksum) = self.find('updateinfo')
332 f = self.download(filename, True, filechksum, True)
334 self.handle.add_updateinfoxml(f, 0)
337 if 'incomplete' not in self:
338 self.writecachedrepo(None)
339 # must be called after writing the repo
340 self.handle.create_stubs()
343 def find(self, what):
344 di = self.handle.Dataiterator(solv.SOLVID_META, solv.REPOSITORY_REPOMD_TYPE, what, Dataiterator.SEARCH_STRING)
345 di.prepend_keyname(solv.REPOSITORY_REPOMD)
348 filename = dp.lookup_str(solv.REPOSITORY_REPOMD_LOCATION)
349 chksum = dp.lookup_checksum(solv.REPOSITORY_REPOMD_CHECKSUM)
350 if filename and not chksum:
351 print "no %s file checksum!" % filename
355 return (filename, chksum)
358 def add_ext(self, repodata, what, ext):
359 filename, chksum = self.find(what)
360 if not filename and what == 'deltainfo':
361 filename, chksum = self.find('prestodelta')
364 handle = repodata.new_handle()
365 repodata.set_poolstr(handle, solv.REPOSITORY_REPOMD_TYPE, what)
366 repodata.set_str(handle, solv.REPOSITORY_REPOMD_LOCATION, filename)
367 repodata.set_checksum(handle, solv.REPOSITORY_REPOMD_CHECKSUM, chksum)
369 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOSITORY_DELTAINFO)
370 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_FLEXARRAY)
372 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
373 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
374 repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
377 repodata = self.handle.add_repodata(0)
378 self.add_ext(repodata, 'deltainfo', 'DL')
379 self.add_ext(repodata, 'filelists', 'FL')
380 repodata.internalize()
382 def load_ext(self, repodata):
383 repomdtype = repodata.lookup_str(solv.SOLVID_META, solv.REPOSITORY_REPOMD_TYPE)
384 if repomdtype == 'filelists':
386 elif repomdtype == 'deltainfo':
390 sys.stdout.write("[%s:%s: " % (self.name, ext))
391 if self.usecachedrepo(ext):
392 sys.stdout.write("cached]\n")
395 sys.stdout.write("fetching]\n")
397 filename = repodata.lookup_str(solv.SOLVID_META, solv.REPOSITORY_REPOMD_LOCATION)
398 filechksum = repodata.lookup_checksum(solv.SOLVID_META, solv.REPOSITORY_REPOMD_CHECKSUM)
399 f = self.download(filename, True, filechksum)
403 self.handle.add_rpmmd(f, 'FL', Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES)
405 self.handle.add_deltainfoxml(f, Repo.REPO_USE_LOADING)
407 self.writecachedrepo(ext, repodata)
410 class repo_susetags(repo_generic):
411 def load_if_changed(self):
412 print "susetags repo '%s':" % self.name,
414 f = self.download("content", False, None, None)
416 print "no content file, skipped"
417 self.handle.free(True)
420 self['cookie'] = self.calc_cookie_fp(f)
421 if self.usecachedrepo(None, True):
425 self.handle.add_content(f, 0)
428 defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
429 descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
431 descrdir = "suse/setup/descr"
432 (filename, filechksum) = self.find('packages.gz')
434 (filename, filechksum) = self.find('packages')
436 f = self.download(descrdir + '/' + filename, True, filechksum, True)
438 self.handle.add_susetags(f, defvendorid, None, Repo.REPO_NO_INTERNALIZE|Repo.SUSETAGS_RECORD_SHARES)
440 (filename, filechksum) = self.find('packages.en.gz')
442 (filename, filechksum) = self.find('packages.en')
444 f = self.download(descrdir + '/' + filename, True, filechksum, True)
446 self.handle.add_susetags(f, defvendorid, None, Repo.REPO_NO_INTERNALIZE|Repo.REPO_REUSE_REPODATA|Repo.REPO_EXTEND_SOLVABLES)
448 self.handle.internalize()
450 if 'incomplete' not in self:
451 self.writecachedrepo(None)
452 # must be called after writing the repo
453 self.handle.create_stubs()
456 def find(self, what):
457 di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, what, Dataiterator.SEARCH_STRING)
458 di.prepend_keyname(solv.SUSETAGS_FILE)
461 chksum = dp.lookup_checksum(solv.SUSETAGS_FILE_CHECKSUM)
462 return (what, chksum)
465 def add_ext(self, repodata, what, ext):
466 (filename, chksum) = self.find(what)
469 handle = repodata.new_handle()
470 repodata.set_str(handle, solv.SUSETAGS_FILE_NAME, filename)
472 repodata.set_checksum(handle, solv.SUSETAGS_FILE_CHECKSUM, chksum)
474 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_DISKUSAGE)
475 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRNUMNUMARRAY)
477 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
478 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
480 for langtag, langtagtype in [
481 (solv.SOLVABLE_SUMMARY, solv.REPOKEY_TYPE_STR),
482 (solv.SOLVABLE_DESCRIPTION, solv.REPOKEY_TYPE_STR),
483 (solv.SOLVABLE_EULA, solv.REPOKEY_TYPE_STR),
484 (solv.SOLVABLE_MESSAGEINS, solv.REPOKEY_TYPE_STR),
485 (solv.SOLVABLE_MESSAGEDEL, solv.REPOKEY_TYPE_STR),
486 (solv.SOLVABLE_CATEGORY, solv.REPOKEY_TYPE_ID)
488 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, self.handle.pool.id2langid(langtag, ext, 1))
489 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, langtagtype)
490 repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
493 repodata = self.handle.add_repodata(0)
494 di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, None, 0)
495 di.prepend_keyname(solv.SUSETAGS_FILE)
500 if filename[0:9] != "packages.":
502 if len(filename) == 11 and filename != "packages.gz":
504 elif filename[11:12] == ".":
510 self.add_ext(repodata, filename, ext)
511 repodata.internalize()
513 def load_ext(self, repodata):
514 filename = repodata.lookup_str(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME)
516 sys.stdout.write("[%s:%s: " % (self.name, ext))
517 if self.usecachedrepo(ext):
518 sys.stdout.write("cached]\n")
521 sys.stdout.write("fetching]\n")
523 defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
524 descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
526 descrdir = "suse/setup/descr"
527 filechksum = repodata.lookup_checksum(solv.SOLVID_META, solv.SUSETAGS_FILE_CHECKSUM)
528 f = self.download(descrdir + '/' + filename, True, filechksum)
531 self.handle.add_susetags(f, defvendorid, ext, Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES)
533 self.writecachedrepo(ext, repodata)
536 def packagespath(self):
537 datadir = repo.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DATADIR)
542 class repo_unknown(repo_generic):
543 def load(self, pool):
544 print "unsupported repo '%s': skipped" % self.name
547 class repo_system(repo_generic):
548 def load(self, pool):
549 self.handle = pool.add_repo(self.name)
550 self.handle.appdata = self
551 pool.installed = self.handle
552 print "rpm database:",
553 self['cookie'] = self.calc_cookie_file("/var/lib/rpm/Packages")
554 if self.usecachedrepo(None):
558 if hasattr(self.handle.__class__, 'add_products'):
559 self.handle.add_products("/etc/products.d", Repo.REPO_NO_INTERNALIZE)
560 self.handle.add_rpmdb(None, Repo.REPO_REUSE_REPODATA)
561 self.writecachedrepo(None)
564 class repo_cmdline(repo_generic):
565 def load(self, pool):
566 self.handle = pool.add_repo(self.name)
567 self.handle.appdata = self
570 def load_stub(repodata):
571 repo = repodata.repo.appdata
573 return repo.load_ext(repodata)
577 parser = OptionParser(usage="usage: solv.py [options] COMMAND")
578 parser.add_option('-r', '--repo', action="append", type="string", dest="repos")
579 (options, args) = parser.parse_args()
581 parser.print_help(sys.stderr)
598 # read all repo configs
601 if os.path.isdir("/etc/zypp/repos.d"):
602 reposdirs = [ "/etc/zypp/repos.d" ]
604 reposdirs = [ "/etc/yum/repos.d" ]
606 for reposdir in ["/etc/zypp/repos.d"]:
607 if not os.path.isdir(reposdir):
609 for reponame in sorted(glob.glob('%s/*.repo' % reposdir)):
610 cfg = INIConfig(open(reponame))
612 repoattr = {'enabled': 0, 'priority': 99, 'autorefresh': 1, 'type': 'rpm-md', 'metadata_expire': 900}
614 repoattr[k] = cfg[alias][k]
615 if 'mirrorlist' in repoattr and 'metalink' not in repoattr:
616 if repoattr['mirrorlist'].find('/metalink'):
617 repoattr['metalink'] = repoattr['mirrorlist']
618 del repoattr['mirrorlist']
619 if repoattr['type'] == 'rpm-md':
620 repo = repo_repomd(alias, 'repomd', repoattr)
621 elif repoattr['type'] == 'yast2':
622 repo = repo_susetags(alias, 'susetags', repoattr)
624 repo = repo_unknown(alias, 'unknown', repoattr)
628 pool.setarch(os.uname()[4])
629 pool.set_loadcallback(load_stub)
631 # now load all enabled repos into the pool
632 sysrepo = repo_system('@System', 'system')
635 if int(repo['enabled']):
640 for reponame in options.repos:
641 mrepos = [ repo for repo in repos if repo.name == reponame ]
643 print "no repository matches '%s'" % reponame
646 if hasattr(repo, 'handle'):
648 repolimiter = pool.Selection()
649 repolimiter.addsimple(Job.SOLVER_SOLVABLE_REPO|Job.SOLVER_SETREPO|Job.SOLVER_SETVENDOR, repo.handle.id)
653 di = pool.Dataiterator(0, solv.SOLVABLE_NAME, args[0], Dataiterator.SEARCH_SUBSTRING|Dataiterator.SEARCH_NOCASE)
655 matches[d.solvid] = True
656 for solvid in sorted(matches.keys()):
657 print " - %s [%s]: %s" % (pool.solvid2str(solvid), pool.solvables[solvid].repo.name, pool.lookup_str(solvid, solv.SOLVABLE_SUMMARY))
661 if cmd == 'list' or cmd == 'info' or cmd == 'install':
663 if arg.endswith(".rpm") and os.access(arg, os.R_OK):
665 cmdlinerepo = repo_cmdline('@commandline', 'cmdline')
666 cmdlinerepo.load(pool)
667 cmdlinerepo['packages'] = {}
668 cmdlinerepo['packages'][arg] = cmdlinerepo.handle.add_rpm(arg, Repo.REPO_REUSE_REPODATA|Repo.REPO_NO_INTERNALIZE)
670 cmdlinerepo.handle.internalize()
672 addedprovides = pool.addfileprovides_queue()
674 sysrepo.updateaddedprovides(addedprovides)
676 repo.updateaddedprovides(addedprovides)
678 pool.createwhatprovides()
680 # convert arguments into jobs
683 if cmdlinerepo and arg in cmdlinerepo['packages']:
684 jobs.append(pool.Job(Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg]))
686 flags = Selection.SELECTION_NAME|Selection.SELECTION_PROVIDES|Selection.SELECTION_GLOB
687 if len(arg) and arg[0] == '/':
688 flags |= Selection.SELECTION_FILELIST
690 flags |= Selection.SELECTION_INSTALLED_ONLY
691 sel = pool.select(arg, flags)
693 sel.limit(repolimiter)
695 sel = pool.select(arg, flags | Selection.SELECTION_NOCASE)
697 sel.limit(repolimiter)
698 if not sel.isempty():
699 print "[ignoring case for '%s']" % arg
701 print "nothing matches '%s'" % arg
703 if sel.flags() & Selection.SELECTION_FILELIST:
704 print "[using file list match for '%s']" % arg
705 if sel.flags() & Selection.SELECTION_PROVIDES:
706 print "[using capability match for '%s']" % arg
709 if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repolimiter):
710 sel = pool.Selection()
711 sel.addsimple(Job.SOLVER_SOLVABLE_ALL, 0)
713 sel.limit(repolimiter)
716 if cmd == 'list' or cmd == 'info':
718 print "no package matched."
721 for s in job.solvables():
724 print "Repo: %s" % s.repo
725 print "Summary: %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
726 str = s.lookup_str(solv.SOLVABLE_URL)
728 print "Url: %s" % str
729 str = s.lookup_str(solv.SOLVABLE_LICENSE)
731 print "License: %s" % str
732 print "Description:\n%s" % s.lookup_str(solv.SOLVABLE_DESCRIPTION)
735 print " - %s [%s]" % (s, s.repo)
736 print " %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
739 if cmd == 'install' or cmd == 'erase' or cmd == 'up' or cmd == 'dup' or cmd == 'verify':
741 print "no package matched."
745 # up magic: use install instead of update if no installed package matches
746 if job.how == Job.SOLVER_SOLVABLE_ALL or filter(lambda s: s.isinstalled(), job.solvables()):
747 job.how |= Job.SOLVER_UPDATE
749 job.how |= Job.SOLVER_INSTALL
750 elif cmd == 'install':
751 job.how |= Job.SOLVER_INSTALL
753 job.how |= Job.SOLVER_ERASE
755 job.how |= Job.SOLVER_DISTUPGRADE
756 elif cmd == 'verify':
757 job.how |= Job.SOLVER_VERIFY
759 #pool.set_debuglevel(2)
762 solver = pool.Solver()
763 solver.set_flag(Solver.SOLVER_FLAG_SPLITPROVIDES, 1);
765 solver.set_flag(Solver.SOLVER_FLAG_ALLOW_UNINSTALL, 1);
766 problems = solver.solve(jobs)
769 for problem in problems:
770 print "Problem %d:" % problem.id
771 r = problem.findproblemrule()
773 print ri.problemstr()
774 solutions = problem.solutions()
775 for solution in solutions:
776 print " Solution %d:" % solution.id
777 elements = solution.elements(True)
778 for element in elements:
779 print " - %s" % element.str()
782 while not (sol == 's' or sol == 'q' or (sol.isdigit() and int(sol) >= 1 and int(sol) <= len(solutions))):
783 sys.stdout.write("Please choose a solution: ")
785 sol = sys.stdin.readline().strip()
787 continue # skip problem
790 solution = solutions[int(sol) - 1]
791 for element in solution.elements():
792 newjob = element.Job()
793 if element.type == Solver.SOLVER_SOLUTION_JOB:
794 jobs[element.jobidx] = newjob
796 if newjob and newjob not in jobs:
799 # no problems, show transaction
800 trans = solver.transaction()
803 print "Nothing to do."
806 print "Transaction summary:"
808 for cl in trans.classify():
809 if cl.type == Transaction.SOLVER_TRANSACTION_ERASE:
810 print "%d erased packages:" % cl.count
811 elif cl.type == Transaction.SOLVER_TRANSACTION_INSTALL:
812 print "%d installed packages:" % cl.count
813 elif cl.type == Transaction.SOLVER_TRANSACTION_REINSTALLED:
814 print "%d reinstalled packages:" % cl.count
815 elif cl.type == Transaction.SOLVER_TRANSACTION_DOWNGRADED:
816 print "%d downgraded packages:" % cl.count
817 elif cl.type == Transaction.SOLVER_TRANSACTION_CHANGED:
818 print "%d changed packages:" % cl.count
819 elif cl.type == Transaction.SOLVER_TRANSACTION_UPGRADED:
820 print "%d upgraded packages:" % cl.count
821 elif cl.type == Transaction.SOLVER_TRANSACTION_VENDORCHANGE:
822 print "%d vendor changes from '%s' to '%s':" % (cl.count, pool.id2str(cl.fromid), pool.id2str(cl.toid))
823 elif cl.type == Transaction.SOLVER_TRANSACTION_ARCHCHANGE:
824 print "%d arch changes from '%s' to '%s':" % (cl.count, pool.id2str(cl.fromid), pool.id2str(cl.toid))
827 for p in cl.solvables():
828 if cl.type == Transaction.SOLVER_TRANSACTION_UPGRADED or cl.type == Transaction.SOLVER_TRANSACTION_DOWNGRADED:
829 op = trans.othersolvable(p)
830 print " - %s -> %s" % (p, op)
834 print "install size change: %d K" % trans.calc_installsizechange()
838 sys.stdout.write("OK to continue (y/n)? ")
840 yn = sys.stdin.readline().strip()
842 if yn == 'n': sys.exit(1)
843 newpkgs = trans.newpackages()
848 downloadsize += p.lookup_num(solv.SOLVABLE_DOWNLOADSIZE)
849 print "Downloading %d packages, %d K" % (len(newpkgs), downloadsize)
851 repo = p.repo.appdata
852 location, medianr = p.lookup_location()
855 if repo.type == 'commandline':
856 f = solv.xfopen(location)
858 sys.exit("\n%s: %s not found" % location)
861 if not sysrepo.handle.isempty() and os.access('/usr/bin/applydeltarpm', os.X_OK):
863 di = p.repo.Dataiterator(solv.SOLVID_META, solv.DELTA_PACKAGE_NAME, pname, Dataiterator.SEARCH_STRING)
864 di.prepend_keyname(solv.REPOSITORY_DELTAINFO)
867 if dp.lookup_id(solv.DELTA_PACKAGE_EVR) != p.evrid or dp.lookup_id(solv.DELTA_PACKAGE_ARCH) != p.archid:
869 baseevrid = dp.lookup_id(solv.DELTA_BASE_EVR)
871 for installedp in pool.whatprovides(p.nameid):
872 if installedp.isinstalled() and installedp.nameid == p.nameid and installedp.archid == p.archid and installedp.evrid == baseevrid:
873 candidate = installedp
876 seq = dp.lookup_str(solv.DELTA_SEQ_NAME) + '-' + dp.lookup_str(solv.DELTA_SEQ_EVR) + '-' + dp.lookup_str(solv.DELTA_SEQ_NUM)
877 st = subprocess.call(['/usr/bin/applydeltarpm', '-a', p.arch, '-c', '-s', seq])
880 chksum = dp.lookup_checksum(solv.DELTA_CHECKSUM)
883 dloc = dp.lookup_str(solv.DELTA_LOCATION_DIR) + '/' + dp.lookup_str(solv.DELTA_LOCATION_NAME) + '-' + dp.lookup_str(solv.DELTA_LOCATION_EVR) + '.' + dp.lookup_str(solv.DELTA_LOCATION_SUFFIX)
884 f = repo.download(dloc, False, chksum)
887 nf = tempfile.TemporaryFile()
888 nf = os.dup(nf.fileno())
889 st = subprocess.call(['/usr/bin/applydeltarpm', '-a', p.arch, "/dev/fd/%d" % solv.xfileno(f), "/dev/fd/%d" % nf])
891 os.lseek(nf, 0, os.SEEK_SET)
892 newpkgsfp[p.id] = solv.xfopen_fd("", nf)
894 if p.id in newpkgsfp:
895 sys.stdout.write("d")
899 chksum = p.lookup_checksum(solv.SOLVABLE_CHECKSUM)
900 location = repo.packagespath() + location
901 f = repo.download(location, False, chksum)
903 sys.exit("\n%s: %s not found in repository" % (repo.name, location))
905 sys.stdout.write(".")
908 print "Committing transaction:"
910 ts = rpm.TransactionSet('/')
911 ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
913 for p in trans.steps():
914 type = trans.steptype(p, Transaction.SOLVER_TRANSACTION_RPM_ONLY)
915 if type == Transaction.SOLVER_TRANSACTION_ERASE:
916 rpmdbid = p.lookup_num(solv.RPM_RPMDBID)
917 erasenamehelper[p.name] = p
919 sys.exit("\ninternal error: installed package %s has no rpmdbid\n" % p)
921 elif type == Transaction.SOLVER_TRANSACTION_INSTALL:
923 h = ts.hdrFromFdno(solv.xfileno(f))
924 os.lseek(solv.xfileno(f), 0, os.SEEK_SET)
925 ts.addInstall(h, p, 'u')
926 elif type == Transaction.SOLVER_TRANSACTION_MULTIINSTALL:
928 h = ts.hdrFromFdno(solv.xfileno(f))
929 os.lseek(solv.xfileno(f), 0, os.SEEK_SET)
930 ts.addInstall(h, p, 'i')
931 checkproblems = ts.check()
936 def runCallback(reason, amount, total, p, d):
937 if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
938 return solv.xfileno(newpkgsfp[p.id])
939 if reason == rpm.RPMCALLBACK_INST_START:
941 if reason == rpm.RPMCALLBACK_UNINST_START:
942 # argh, p is just the name of the package
943 if p in erasenamehelper:
944 p = erasenamehelper[p]
946 runproblems = ts.run(runCallback, '')
952 print "unknown command", cmd