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
104 def load_ext(self, repodata):
107 def setfromurls(self, urls):
111 print "[using mirror %s]" % re.sub(r'^(.*?/...*?)/.*$', r'\1', url)
112 self['baseurl'] = url
114 def setfrommetalink(self, metalink):
115 f = self.download(metalink, False, None)
118 f = os.fdopen(f.dup(), 'r')
121 for l in f.readlines():
123 m = re.match(r'^<hash type="sha256">([0-9a-fA-F]{64})</hash>', l)
125 chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256, m.group(1))
126 m = re.match(r'^<url.*>(https?://.+)repodata/repomd.xml</url>', l)
128 urls.append(m.group(1))
130 chksum = None # in case the metalink is about a different file
132 self.setfromurls(urls)
135 def setfrommirrorlist(self, mirrorlist):
136 f = self.download(mirrorlist, False, None)
139 f = os.fdopen(f.dup(), 'r')
141 for l in f.readline():
143 if l[0:6] == 'http://' or l[0:7] == 'https://':
145 self.setfromurls(urls)
148 def download(self, file, uncompress, chksum, markincomplete=False):
150 if 'baseurl' not in self:
151 if 'metalink' in self:
152 if file != self['metalink']:
153 metalinkchksum = self.setfrommetalink(self['metalink'])
154 if file == 'repodata/repomd.xml' and metalinkchksum and not chksum:
155 chksum = metalinkchksum
158 elif 'mirrorlist' in self:
159 if file != self['mirrorlist']:
160 self.setfrommirrorlist(self['mirrorlist'])
164 if 'baseurl' not in self:
165 print "%s: no baseurl" % self.name
167 url = re.sub(r'/$', '', self['baseurl']) + '/' + file
168 f = tempfile.TemporaryFile()
169 st = subprocess.call(['curl', '-f', '-s', '-L', url], stdout=f.fileno())
170 if os.lseek(f.fileno(), 0, os.SEEK_CUR) == 0 and (st == 0 or not chksum):
172 os.lseek(f.fileno(), 0, os.SEEK_SET)
174 print "%s: download error %d" % (file, st)
176 self['incomplete'] = True
179 fchksum = solv.Chksum(chksum.type)
181 print "%s: unknown checksum type" % file
183 self['incomplete'] = True
185 fchksum.add_fd(f.fileno())
186 if fchksum != chksum:
187 print "%s: checksum mismatch" % file
189 self['incomplete'] = True
192 return solv.xfopen_fd(file, f.fileno())
193 return solv.xfopen_fd(None, f.fileno())
195 def usecachedrepo(self, ext, mark=False):
197 repopath = self.cachepath(ext)
198 f = open(repopath, 'r')
199 f.seek(-32, os.SEEK_END)
201 if len(fcookie) != 32:
204 cookie = self['cookie']
206 cookie = self['extcookie']
207 if cookie and fcookie != cookie:
209 if self.type != 'system' and not ext:
210 f.seek(-32 * 2, os.SEEK_END)
211 fextcookie = f.read(32)
212 if len(fextcookie) != 32:
217 flags = Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES
219 flags |= Repo.REPO_LOCALPOOL
220 if not self.handle.add_solv(f, flags):
222 if self.type != 'system' and not ext:
223 self['cookie'] = fcookie
224 self['extcookie'] = fextcookie
226 # no futimes in python?
228 os.utime(repopath, None)
235 def writecachedrepo(self, ext, info=None):
236 if 'incomplete' in self:
239 if not os.path.isdir("/var/cache/solv"):
240 os.mkdir("/var/cache/solv", 0755)
241 (fd, tmpname) = tempfile.mkstemp(prefix='.newsolv-', dir='/var/cache/solv')
243 f = os.fdopen(fd, 'w+')
248 else: # rewrite_repos case
249 self.handle.write_first_repodata(f)
250 if self.type != 'system' and not ext:
251 if 'extcookie' not in self:
252 self['extcookie'] = self.calc_cookie_ext(f, self['cookie'])
253 f.write(self['extcookie'])
255 f.write(self['cookie'])
257 f.write(self['extcookie'])
259 if self.handle.iscontiguous():
260 # switch to saved repo to activate paging and save memory
261 nf = solv.xfopen(tmpname)
265 if not self.handle.add_solv(nf, Repo.SOLV_ADD_NO_STUBS):
266 sys.exit("internal error, cannot reload solv file")
269 # need to extend to repo boundaries, as this is how
270 # info.write() has written the data
271 info.extend_to_repo()
272 flags = Repo.REPO_EXTEND_SOLVABLES
274 flags |= Repo.REPO_LOCALPOOL
275 info.add_solv(nf, flags)
276 os.rename(tmpname, self.cachepath(ext))
281 def updateaddedprovides(self, addedprovides):
282 if 'incomplete' in self:
284 if not hasattr(self, 'handle'):
286 if self.handle.isempty():
288 # make sure there's just one real repodata with extensions
289 repodata = self.handle.first_repodata()
292 oldaddedprovides = repodata.lookup_idarray(solv.SOLVID_META, solv.REPOSITORY_ADDEDFILEPROVIDES)
293 if not set(addedprovides) <= set(oldaddedprovides):
294 for id in addedprovides:
295 repodata.add_idarray(solv.SOLVID_META, solv.REPOSITORY_ADDEDFILEPROVIDES, id)
296 repodata.internalize()
297 self.writecachedrepo(None, repodata)
299 def packagespath(self):
302 class repo_repomd(repo_generic):
303 def load(self, pool):
304 if super(repo_repomd, self).load(pool):
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):
318 self.handle.add_repomdxml(f, 0)
320 (filename, filechksum) = self.find('primary')
322 f = self.download(filename, True, filechksum, True)
324 self.handle.add_rpmmd(f, None, 0)
325 if 'incomplete' in self:
326 return False # hopeless, need good primary
327 (filename, filechksum) = self.find('updateinfo')
329 f = self.download(filename, True, filechksum, True)
331 self.handle.add_updateinfoxml(f, 0)
333 self.writecachedrepo(None)
334 # must be called after writing the repo
335 self.handle.create_stubs()
338 def find(self, what):
339 di = self.handle.Dataiterator(solv.SOLVID_META, solv.REPOSITORY_REPOMD_TYPE, what, Dataiterator.SEARCH_STRING)
340 di.prepend_keyname(solv.REPOSITORY_REPOMD)
343 filename = dp.lookup_str(solv.REPOSITORY_REPOMD_LOCATION)
344 chksum = dp.lookup_checksum(solv.REPOSITORY_REPOMD_CHECKSUM)
345 if filename and not chksum:
346 print "no %s file checksum!" % filename
350 return (filename, chksum)
353 def add_ext(self, repodata, what, ext):
354 filename, chksum = self.find(what)
355 if not filename and what == 'deltainfo':
356 filename, chksum = self.find('prestodelta')
359 handle = repodata.new_handle()
360 repodata.set_poolstr(handle, solv.REPOSITORY_REPOMD_TYPE, what)
361 repodata.set_str(handle, solv.REPOSITORY_REPOMD_LOCATION, filename)
362 repodata.set_checksum(handle, solv.REPOSITORY_REPOMD_CHECKSUM, chksum)
364 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOSITORY_DELTAINFO)
365 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_FLEXARRAY)
367 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
368 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
369 repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
372 repodata = self.handle.add_repodata(0)
373 self.add_ext(repodata, 'deltainfo', 'DL')
374 self.add_ext(repodata, 'filelists', 'FL')
375 repodata.internalize()
377 def load_ext(self, repodata):
378 repomdtype = repodata.lookup_str(solv.SOLVID_META, solv.REPOSITORY_REPOMD_TYPE)
379 if repomdtype == 'filelists':
381 elif repomdtype == 'deltainfo':
385 sys.stdout.write("[%s:%s: " % (self.name, ext))
386 if self.usecachedrepo(ext):
387 sys.stdout.write("cached]\n")
390 sys.stdout.write("fetching]\n")
392 filename = repodata.lookup_str(solv.SOLVID_META, solv.REPOSITORY_REPOMD_LOCATION)
393 filechksum = repodata.lookup_checksum(solv.SOLVID_META, solv.REPOSITORY_REPOMD_CHECKSUM)
394 f = self.download(filename, True, filechksum)
398 self.handle.add_rpmmd(f, 'FL', Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES|Repo.REPO_LOCALPOOL)
400 self.handle.add_deltainfoxml(f, Repo.REPO_USE_LOADING)
401 self.writecachedrepo(ext, repodata)
404 class repo_susetags(repo_generic):
405 def load(self, pool):
406 if super(repo_susetags, self).load(pool):
408 print "susetags repo '%s':" % self.name,
410 f = self.download("content", False, None, None)
412 print "no content file, skipped"
413 self.handle.free(True)
416 self['cookie'] = self.calc_cookie_fp(f)
417 if self.usecachedrepo(None, True):
420 self.handle.add_content(f, 0)
422 defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
423 descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
425 descrdir = "suse/setup/descr"
426 (filename, filechksum) = self.find('packages.gz')
428 (filename, filechksum) = self.find('packages')
430 f = self.download(descrdir + '/' + filename, True, filechksum, True)
432 self.handle.add_susetags(f, defvendorid, None, Repo.REPO_NO_INTERNALIZE|Repo.SUSETAGS_RECORD_SHARES)
433 (filename, filechksum) = self.find('packages.en.gz')
435 (filename, filechksum) = self.find('packages.en')
437 f = self.download(descrdir + '/' + filename, True, filechksum, True)
439 self.handle.add_susetags(f, defvendorid, None, Repo.REPO_NO_INTERNALIZE|Repo.REPO_REUSE_REPODATA|Repo.REPO_EXTEND_SOLVABLES)
440 self.handle.internalize()
442 self.writecachedrepo(None)
443 # must be called after writing the repo
444 self.handle.create_stubs()
447 def find(self, what):
448 di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, what, Dataiterator.SEARCH_STRING)
449 di.prepend_keyname(solv.SUSETAGS_FILE)
452 chksum = dp.lookup_checksum(solv.SUSETAGS_FILE_CHECKSUM)
453 return (what, chksum)
456 def add_ext(self, repodata, what, ext):
457 (filename, chksum) = self.find(what)
460 handle = repodata.new_handle()
461 repodata.set_str(handle, solv.SUSETAGS_FILE_NAME, filename)
463 repodata.set_checksum(handle, solv.SUSETAGS_FILE_CHECKSUM, chksum)
465 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_DISKUSAGE)
466 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRNUMNUMARRAY)
468 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.SOLVABLE_FILELIST)
469 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, solv.REPOKEY_TYPE_DIRSTRARRAY)
471 for langtag, langtagtype in [
472 (solv.SOLVABLE_SUMMARY, solv.REPOKEY_TYPE_STR),
473 (solv.SOLVABLE_DESCRIPTION, solv.REPOKEY_TYPE_STR),
474 (solv.SOLVABLE_EULA, solv.REPOKEY_TYPE_STR),
475 (solv.SOLVABLE_MESSAGEINS, solv.REPOKEY_TYPE_STR),
476 (solv.SOLVABLE_MESSAGEDEL, solv.REPOKEY_TYPE_STR),
477 (solv.SOLVABLE_CATEGORY, solv.REPOKEY_TYPE_ID)
479 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, self.handle.pool.id2langid(langtag, ext, 1))
480 repodata.add_idarray(handle, solv.REPOSITORY_KEYS, langtagtype)
481 repodata.add_flexarray(solv.SOLVID_META, solv.REPOSITORY_EXTERNAL, handle)
484 repodata = self.handle.add_repodata(0)
485 di = self.handle.Dataiterator(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME, None, 0)
486 di.prepend_keyname(solv.SUSETAGS_FILE)
491 if filename[0:9] != "packages.":
493 if len(filename) == 11 and filename != "packages.gz":
495 elif filename[11:12] == ".":
501 self.add_ext(repodata, filename, ext)
502 repodata.internalize()
504 def load_ext(self, repodata):
505 filename = repodata.lookup_str(solv.SOLVID_META, solv.SUSETAGS_FILE_NAME)
507 sys.stdout.write("[%s:%s: " % (self.name, ext))
508 if self.usecachedrepo(ext):
509 sys.stdout.write("cached]\n")
512 sys.stdout.write("fetching]\n")
514 defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
515 descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
517 descrdir = "suse/setup/descr"
518 filechksum = repodata.lookup_checksum(solv.SOLVID_META, solv.SUSETAGS_FILE_CHECKSUM)
519 f = self.download(descrdir + '/' + filename, True, filechksum)
522 flags = Repo.REPO_USE_LOADING|Repo.REPO_EXTEND_SOLVABLES
524 flags |= Repo.REPO_LOCALPOOL
525 self.handle.add_susetags(f, defvendorid, ext, flags)
526 self.writecachedrepo(ext, repodata)
529 def packagespath(self):
530 datadir = repo.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DATADIR)
535 class repo_unknown(repo_generic):
536 def load(self, pool):
537 print "unsupported repo '%s': skipped" % self.name
540 class repo_system(repo_generic):
541 def load(self, pool):
542 self.handle = pool.add_repo(self.name)
543 self.handle.appdata = self
544 pool.installed = self.handle
545 print "rpm database:",
546 self['cookie'] = self.calc_cookie_file("/var/lib/rpm/Packages")
547 if self.usecachedrepo(None):
551 if hasattr(self.handle.__class__, 'add_products'):
552 self.handle.add_products("/etc/products.d", Repo.REPO_NO_INTERNALIZE)
553 self.handle.add_rpmdb(None, Repo.REPO_REUSE_REPODATA)
554 self.writecachedrepo(None)
557 class repo_cmdline(repo_generic):
558 def load(self, pool):
559 self.handle = pool.add_repo(self.name)
560 self.handle.appdata = self
563 def load_stub(repodata):
564 repo = repodata.repo.appdata
566 return repo.load_ext(repodata)
570 parser = OptionParser(usage="usage: solv.py [options] COMMAND")
571 parser.add_option('-r', '--repo', action="append", type="string", dest="repos", help="limit to specified repositories")
572 parser.add_option('--best', action="store_true", dest="best", help="force installation/update to best packages")
573 parser.add_option('--clean', action="store_true", dest="clean", help="delete no longer needed packages")
574 (options, args) = parser.parse_args()
576 parser.print_help(sys.stderr)
582 cmdabbrev = {'li': 'list', 'in': 'install', 'rm': 'erase', 've': 'verify', 'se': 'search'}
587 'install': Job.SOLVER_INSTALL,
588 'erase': Job.SOLVER_ERASE,
589 'up': Job.SOLVER_UPDATE,
590 'dup': Job.SOLVER_DISTUPGRADE,
591 'verify': Job.SOLVER_VERIFY,
596 # read all repo configs
599 if os.path.isdir("/etc/zypp/repos.d"):
600 reposdirs = [ "/etc/zypp/repos.d" ]
602 reposdirs = [ "/etc/yum/repos.d" ]
604 for reposdir in reposdirs:
605 if not os.path.isdir(reposdir):
607 for reponame in sorted(glob.glob('%s/*.repo' % reposdir)):
608 cfg = INIConfig(open(reponame))
610 repoattr = {'enabled': 0, 'priority': 99, 'autorefresh': 1, 'type': 'rpm-md', 'metadata_expire': 900}
612 repoattr[k] = cfg[alias][k]
613 if 'mirrorlist' in repoattr and 'metalink' not in repoattr:
614 if repoattr['mirrorlist'].find('/metalink'):
615 repoattr['metalink'] = repoattr['mirrorlist']
616 del repoattr['mirrorlist']
617 if repoattr['type'] == 'rpm-md':
618 repo = repo_repomd(alias, 'repomd', repoattr)
619 elif repoattr['type'] == 'yast2':
620 repo = repo_susetags(alias, 'susetags', repoattr)
622 repo = repo_unknown(alias, 'unknown', repoattr)
627 pool.set_loadcallback(load_stub)
629 # now load all enabled repos into the pool
630 sysrepo = repo_system('@System', 'system')
633 if int(repo['enabled']):
638 for reponame in options.repos:
639 mrepos = [ repo for repo in repos if repo.name == reponame ]
641 print "no repository matches '%s'" % reponame
644 if hasattr(repo, 'handle'):
646 repofilter = pool.Selection()
647 repofilter.add_raw(Job.SOLVER_SOLVABLE_REPO|Job.SOLVER_SETREPO|Job.SOLVER_SETVENDOR, repo.handle.id)
650 pool.createwhatprovides()
651 sel = pool.Selection()
652 di = pool.Dataiterator(0, solv.SOLVABLE_NAME, args[0], Dataiterator.SEARCH_SUBSTRING|Dataiterator.SEARCH_NOCASE)
654 sel.add_raw(Job.SOLVER_SOLVABLE, d.solvid)
656 sel.filter(repofilter)
657 for s in sel.solvables():
658 print " - %s [%s]: %s" % (s, s.repo.name, s.lookup_str(solv.SOLVABLE_SUMMARY))
661 if cmd not in cmdactionmap:
662 print "unknown command", cmd
666 if cmd == 'list' or cmd == 'info' or cmd == 'install':
668 if arg.endswith(".rpm") and os.access(arg, os.R_OK):
670 cmdlinerepo = repo_cmdline('@commandline', 'cmdline')
671 cmdlinerepo.load(pool)
672 cmdlinerepo['packages'] = {}
673 cmdlinerepo['packages'][arg] = cmdlinerepo.handle.add_rpm(arg, Repo.REPO_REUSE_REPODATA|Repo.REPO_NO_INTERNALIZE)
675 cmdlinerepo.handle.internalize()
677 addedprovides = pool.addfileprovides_queue()
679 sysrepo.updateaddedprovides(addedprovides)
681 repo.updateaddedprovides(addedprovides)
683 pool.createwhatprovides()
685 # convert arguments into jobs
688 if cmdlinerepo and arg in cmdlinerepo['packages']:
689 jobs.append(pool.Job(Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg]))
691 flags = Selection.SELECTION_NAME|Selection.SELECTION_PROVIDES|Selection.SELECTION_GLOB
692 flags |= Selection.SELECTION_CANON|Selection.SELECTION_DOTARCH|Selection.SELECTION_REL
693 if len(arg) and arg[0] == '/':
694 flags |= Selection.SELECTION_FILELIST
696 flags |= Selection.SELECTION_INSTALLED_ONLY
697 sel = pool.select(arg, flags)
699 sel.filter(repofilter)
701 sel = pool.select(arg, flags | Selection.SELECTION_NOCASE)
703 sel.filter(repofilter)
704 if not sel.isempty():
705 print "[ignoring case for '%s']" % arg
707 print "nothing matches '%s'" % arg
709 if sel.flags() & Selection.SELECTION_FILELIST:
710 print "[using file list match for '%s']" % arg
711 if sel.flags() & Selection.SELECTION_PROVIDES:
712 print "[using capability match for '%s']" % arg
713 jobs += sel.jobs(cmdactionmap[cmd])
715 if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repofilter):
716 sel = pool.Selection()
717 sel.add_raw(Job.SOLVER_SOLVABLE_ALL, 0)
719 sel.filter(repofilter)
720 jobs += sel.jobs(cmdactionmap[cmd])
723 print "no package matched."
726 if cmd == 'list' or cmd == 'info':
728 for s in job.solvables():
731 print "Repo: %s" % s.repo
732 print "Summary: %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
733 str = s.lookup_str(solv.SOLVABLE_URL)
735 print "Url: %s" % str
736 str = s.lookup_str(solv.SOLVABLE_LICENSE)
738 print "License: %s" % str
739 print "Description:\n%s" % s.lookup_str(solv.SOLVABLE_DESCRIPTION)
742 print " - %s [%s]" % (s, s.repo)
743 print " %s" % s.lookup_str(solv.SOLVABLE_SUMMARY)
746 # up magic: use install instead of update if no installed package matches
748 if cmd == 'up' and job.isemptyupdate():
749 job.how ^= Job.SOLVER_UPDATE ^ Job.SOLVER_INSTALL
751 job.how |= Job.SOLVER_FORCEBEST
753 job.how |= Job.SOLVER_CLEANDEPS
755 #pool.set_debuglevel(2)
758 solver = pool.Solver()
759 solver.set_flag(Solver.SOLVER_FLAG_SPLITPROVIDES, 1);
761 solver.set_flag(Solver.SOLVER_FLAG_ALLOW_UNINSTALL, 1);
762 problems = solver.solve(jobs)
765 for problem in problems:
766 print "Problem %d:" % problem.id
767 r = problem.findproblemrule()
769 print ri.problemstr()
770 solutions = problem.solutions()
771 for solution in solutions:
772 print " Solution %d:" % solution.id
773 elements = solution.elements(True)
774 for element in elements:
775 print " - %s" % element.str()
778 while not (sol == 's' or sol == 'q' or (sol.isdigit() and int(sol) >= 1 and int(sol) <= len(solutions))):
779 sys.stdout.write("Please choose a solution: ")
781 sol = sys.stdin.readline().strip()
783 continue # skip problem
786 solution = solutions[int(sol) - 1]
787 for element in solution.elements():
788 newjob = element.Job()
789 if element.type == Solver.SOLVER_SOLUTION_JOB:
790 jobs[element.jobidx] = newjob
792 if newjob and newjob not in jobs:
795 # no problems, show transaction
796 trans = solver.transaction()
799 print "Nothing to do."
802 print "Transaction summary:"
804 for cl in trans.classify():
805 if cl.type == Transaction.SOLVER_TRANSACTION_ERASE:
806 print "%d erased packages:" % cl.count
807 elif cl.type == Transaction.SOLVER_TRANSACTION_INSTALL:
808 print "%d installed packages:" % cl.count
809 elif cl.type == Transaction.SOLVER_TRANSACTION_REINSTALLED:
810 print "%d reinstalled packages:" % cl.count
811 elif cl.type == Transaction.SOLVER_TRANSACTION_DOWNGRADED:
812 print "%d downgraded packages:" % cl.count
813 elif cl.type == Transaction.SOLVER_TRANSACTION_CHANGED:
814 print "%d changed packages:" % cl.count
815 elif cl.type == Transaction.SOLVER_TRANSACTION_UPGRADED:
816 print "%d upgraded packages:" % cl.count
817 elif cl.type == Transaction.SOLVER_TRANSACTION_VENDORCHANGE:
818 print "%d vendor changes from '%s' to '%s':" % (cl.count, cl.fromdep(), cl.todep())
819 elif cl.type == Transaction.SOLVER_TRANSACTION_ARCHCHANGE:
820 print "%d arch changes from '%s' to '%s':" % (cl.count, cl.fromdep(), cl.todep())
823 for p in cl.solvables():
824 if cl.type == Transaction.SOLVER_TRANSACTION_UPGRADED or cl.type == Transaction.SOLVER_TRANSACTION_DOWNGRADED:
825 op = trans.othersolvable(p)
826 print " - %s -> %s" % (p, op)
830 print "install size change: %d K" % trans.calc_installsizechange()
834 sys.stdout.write("OK to continue (y/n)? ")
836 yn = sys.stdin.readline().strip()
838 if yn == 'n': sys.exit(1)
839 newpkgs = trans.newpackages()
844 downloadsize += p.lookup_num(solv.SOLVABLE_DOWNLOADSIZE)
845 print "Downloading %d packages, %d K" % (len(newpkgs), downloadsize)
847 repo = p.repo.appdata
848 location, medianr = p.lookup_location()
851 if repo.type == 'commandline':
852 f = solv.xfopen(location)
854 sys.exit("\n%s: %s not found" % location)
857 if not sysrepo.handle.isempty() and os.access('/usr/bin/applydeltarpm', os.X_OK):
859 di = p.repo.Dataiterator(solv.SOLVID_META, solv.DELTA_PACKAGE_NAME, pname, Dataiterator.SEARCH_STRING)
860 di.prepend_keyname(solv.REPOSITORY_DELTAINFO)
863 if dp.lookup_id(solv.DELTA_PACKAGE_EVR) != p.evrid or dp.lookup_id(solv.DELTA_PACKAGE_ARCH) != p.archid:
865 baseevrid = dp.lookup_id(solv.DELTA_BASE_EVR)
867 for installedp in pool.whatprovides(p.nameid):
868 if installedp.isinstalled() and installedp.nameid == p.nameid and installedp.archid == p.archid and installedp.evrid == baseevrid:
869 candidate = installedp
872 seq = dp.lookup_deltaseq()
873 st = subprocess.call(['/usr/bin/applydeltarpm', '-a', p.arch, '-c', '-s', seq])
876 chksum = dp.lookup_checksum(solv.DELTA_CHECKSUM)
879 dloc, dmedianr = dp.lookup_deltalocation()
880 dloc = repo.packagespath() + dloc
881 f = repo.download(dloc, False, chksum)
884 nf = tempfile.TemporaryFile()
885 nf = os.dup(nf.fileno()) # get rid of CLOEXEC
886 st = subprocess.call(['/usr/bin/applydeltarpm', '-a', p.arch, "/dev/fd/%d" % f.fileno(), "/dev/fd/%d" % nf])
887 os.lseek(nf, 0, os.SEEK_SET)
888 newpkgsfp[p.id] = solv.xfopen_fd("", nf)
891 if p.id in newpkgsfp:
892 sys.stdout.write("d")
896 chksum = p.lookup_checksum(solv.SOLVABLE_CHECKSUM)
897 location = repo.packagespath() + location
898 f = repo.download(location, False, chksum)
900 sys.exit("\n%s: %s not found in repository" % (repo.name, location))
902 sys.stdout.write(".")
905 print "Committing transaction:"
907 ts = rpm.TransactionSet('/')
908 ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
910 for p in trans.steps():
911 type = trans.steptype(p, Transaction.SOLVER_TRANSACTION_RPM_ONLY)
912 if type == Transaction.SOLVER_TRANSACTION_ERASE:
913 rpmdbid = p.lookup_num(solv.RPM_RPMDBID)
914 erasenamehelper[p.name] = p
916 sys.exit("\ninternal error: installed package %s has no rpmdbid\n" % p)
918 elif type == Transaction.SOLVER_TRANSACTION_INSTALL:
920 h = ts.hdrFromFdno(f.fileno())
921 os.lseek(f.fileno(), 0, os.SEEK_SET)
922 ts.addInstall(h, p, 'u')
923 elif type == Transaction.SOLVER_TRANSACTION_MULTIINSTALL:
925 h = ts.hdrFromFdno(f.fileno())
926 os.lseek(f.fileno(), 0, os.SEEK_SET)
927 ts.addInstall(h, p, 'i')
928 checkproblems = ts.check()
933 def runCallback(reason, amount, total, p, d):
934 if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
935 return newpkgsfp[p.id].fileno()
936 if reason == rpm.RPMCALLBACK_INST_START:
938 if reason == rpm.RPMCALLBACK_UNINST_START:
939 # argh, p is just the name of the package
940 if p in erasenamehelper:
941 p = erasenamehelper[p]
943 runproblems = ts.run(runCallback, '')