3 # ========================================================================================
5 def poolInstall( Z, capstr ):
6 print "Request: install %s" % capstr
7 Z.resolver().addRequire( zypp.Capability( capstr ) )
9 def poolRemove( Z, capstr ):
10 print "Request: delete %s" % capstr
11 Z.resolver().addConflict( zypp.Capability( capstr ) )
13 def poolPrintTransaction( Z ):
14 todo = Z.pool().getTransaction()
15 for item in todo._toDelete:
16 print '-- %s | %s-%s | %s' % (item.repoInfo().alias(), item.name(), item.edition(), item.status() )
17 for item in todo._toInstall:
18 print '++ %s | %s-%s | %s' % (item.repoInfo().alias(), item.name(), item.edition(), item.status() )
22 while not Z.resolver().resolvePool():
23 # Print _all_ problems and possible solutions:
24 problems = Z.resolver().problems()
26 for problem in problems:
28 print "Problem %d:" % pn
29 print "=============================="
30 print problem.description()
32 print problem.details()
33 print "------------------------------"
35 for solution in problem.solutions():
37 print "Solution %d.%d:" % ( pn, sn )
38 print solution.description()
39 if solution.details():
40 print solution.details()
41 print "=============================="
44 # Faked user interaction: stupidly pick all 1st solutions (don't do this in real life!)
46 # In real life you probably pick just a single solution
47 # and re-solve immedaitely, because one solution may solve
48 # multiple ploblems - or create new ones.
50 pickedSolutions = zypp.ProblemSolutionList()
52 for problem in problems:
55 for solution in problem.solutions():
57 print "Stupidly pick solution %d.%d" % ( pn, sn )
58 pickedSolutions.push_back( solution )
60 # Apply picked solutions:
61 Z.resolver().applySolutions( pickedSolutions )
64 print "Example stops here instead of starting a new iteration..."
66 raise BaseException("Solver Error")
68 poolPrintTransaction( Z )
74 Z.resolver().doUpdate()
75 poolPrintTransaction( Z )
78 # ========================================================================================
79 Z = zypp.ZYppFactory_instance().getZYpp()
81 # Load system rooted at "/"...
83 Z.initializeTarget( zypp.Pathname("/") )
86 # Load all enabled repositories...
88 repoManager = zypp.RepoManager()
89 for repo in repoManager.knownRepositories():
90 if not repo.enabled():
92 if not repoManager.isCached( repo ):
93 repoManager.buildCache( repo )
94 repoManager.loadFromCache( repo );
96 # Now all installed and available items are in the pool:
98 print "Known items: %d" % ( Z.pool().size() )
100 # Iterate the pool to query items. PoolItems are not just packages
101 # but also patterns, patches, products, ...
102 # PoolItem provides the common attributes and status. For specific
103 # attibutes cast the item inot the specific kind.
104 print "Printing just the Products..."
105 for item in Z.pool():
106 if not zypp.isKindProduct( item ):
109 if item.status().isInstalled():
113 print "%s %s:%s-%s.%s\t(%s)" % ( t,
118 item.repoInfo().alias() )
120 # How to access e.g. product specific attributes:
121 if zypp.isKindProduct( item ):
122 prod = zypp.asKindProduct( item )
123 print " %s (%s)" % ( prod.shortName(), prod.flavor() )
126 # Building and resolving a transaction:
130 # Simply try to update all installed packages:
133 # Add jobs to the pools resolver
134 # and finally resolve the jobs.
135 poolInstall( Z, "libzypp = 13.9.0-13.1" )
136 poolInstall( Z, "pattern:unknown" )
137 poolRemove( Z, "xteddy < 1.0" )
140 # finally install (here dryRun)
142 policy = zypp.ZYppCommitPolicy()
143 policy.syncPoolAfterCommit( False )
144 policy.dryRun( True )
146 result = Z.commit( policy )