[zypp-commit] r8873 - in /trunk/sat-solver/bindings/ruby/tests: _patch.rb _solv2patches.rb gen_patches.rb packages.solv patch_updates.rb patches.solv updates.rb updates.solv
Author: kkaempf Date: Fri Feb 22 11:42:21 2008 New Revision: 8873 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8873&view=rev Log: prototype implementation for Code11 patch handling Added: trunk/sat-solver/bindings/ruby/tests/_patch.rb trunk/sat-solver/bindings/ruby/tests/_solv2patches.rb trunk/sat-solver/bindings/ruby/tests/gen_patches.rb trunk/sat-solver/bindings/ruby/tests/packages.solv (with props) trunk/sat-solver/bindings/ruby/tests/patch_updates.rb trunk/sat-solver/bindings/ruby/tests/patches.solv (with props) trunk/sat-solver/bindings/ruby/tests/updates.rb trunk/sat-solver/bindings/ruby/tests/updates.solv (with props) Added: trunk/sat-solver/bindings/ruby/tests/_patch.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/_patch.rb?rev=8873&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/_patch.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/_patch.rb Fri Feb 22 11:42:21 2008 @@ -0,0 +1,52 @@ + +# +# Code11 Patch +# + +class Item + attr_reader :name, :evr, :arch + def initialize name, evr, arch + @name = name + @evr = evr + @arch = arch + end + def to_s + "#{name} #{evr} #{arch}" + end +end + +class Patch + attr_reader :name, :evr + attr_reader :timestamp, :category + attr_reader :summary, :description + attr_reader :contains + + def initialize name, evr, category, timestamp + @name = name + @evr = evr + @category = category + @timestamp = timestamp + @contains = [] + end + + def summary= summary + @summary = summary + end + def description= description + @description = description + end + + def add name,evr,arch + @contains << Item.new( name, evr, arch ) + end + + def to_s + s = "Name: #{@name}-#{@evr}\n" + + " Category: #{@category}\n" + + " Timestamp: #{@timestamp}\n" + + " Summary: #{@summary}\n" + + " Contains[#{@contains.size}]:\n" + @contains.each { |i| s += " #{i}\n" } + s + end +end Added: trunk/sat-solver/bindings/ruby/tests/_solv2patches.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/_solv2patches.rb?rev=8873&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/_solv2patches.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/_solv2patches.rb Fri Feb 22 11:42:21 2008 @@ -0,0 +1,119 @@ +# +# Convert .solv file to Code11 Patches +# + +require 'satsolver' +require '_patch' + +def store_it the_store, name, s + byname = the_store[name] || Hash.new + STDERR.puts "* known #{name}-#{s.evr}" if byname[s.evr] + byname[s.evr] = s + the_store[name] = byname + the_store +end + +def solv2patches name, arch + + pool = SatSolver::Pool.new( arch ) + repo = pool.create_repo( "patches" ) + repo.add_solv( name ) + STDERR.puts "#{repo.size} patches and stuff" + + atoms = Hash.new + patches = Hash.new + + + # + # Iterate through repo + # - ensure that it contains only patches and atoms + # - store all patches in 'patches' + # - store all atoms in 'atoms' + # - both stores are 2-dim hashed, first dim is name, second dim is evr + # + + repo.each { |s| + sp = s.name.split ":" + unless sp.size == 2 + STDERR.puts "** No kind #{s}" + exit + end + kind = sp[0] + case kind + when "atom" + atoms = store_it atoms, sp[1], s + when "patch" + patches = store_it patches, sp[1], s + else + STDERR.puts "** Unknown kind #{kind} of #{s}" + end + } + + # + # Now iterate through all patches + # - ensure that it requires just atoms + # - by equality + # - find the atom + # - ensure that the atom has proper deps + # + + out_patches = [] + + patches.each { |name,store| + store.each { |evr,patch| + + p = Patch.new( name, evr, patch.category, patch.timestamp ) + p.summary = patch.summary + p.description = patch.description + + patch.requires.each { |req| + sp = req.name.split ":" + + unless sp.size == 2 + STDERR.puts "** Patch #{patch} requires #{req}" + exit + end + unless sp[0] == "atom" + STDERR.puts "** Patch #{patch} requires non-atom #{sp[0]}" + exit + end + name = sp[1] + byname = atoms[name] + unless byname + STDERR.puts "** Patch #{patch} requires unknown atom #{name}" + exit + end + unless req.op == SatSolver::REL_EQ + STDERR.puts "** Patch #{patch} requires non-equal atom #{name}" + exit + end + atom = byname[req.evr] + unless atom + STDERR.puts "** Patch #{patch} requires non-existing atom #{req.name}-#{req.evr}" + exit + end + atom.freshens.each { |fre| + unless fre.name == name + STDERR.puts "Atom #{atom} freshens #{fre}" + exit + end + } + atom.requires.each { |areq| + sp = areq.name.split ":" + unless sp.size == 1 + STDERR.puts "Atom #{atom} requires #{areq}" + exit + end + unless areq.op == SatSolver::REL_GE + STDERR.puts "Atom #{atom} requires non-greater-equal #{areq}" + exit + end + p.add( areq.name, areq.evr, atom.arch ) + } + } + out_patches << p + } + } + + out_patches +end Added: trunk/sat-solver/bindings/ruby/tests/gen_patches.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/gen_patches.rb?rev=8873&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/gen_patches.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/gen_patches.rb Fri Feb 22 11:42:21 2008 @@ -0,0 +1,12 @@ +$:.unshift "../../../build/bindings/ruby" + +# +# Generate 'code11 patches' from code10 patch repo +# + +require 'satsolver' +require '_patch' +require '_solv2patches' + +patches = solv2patches "patches.solv", "x86_64" +patches.each { |p| puts p } Added: trunk/sat-solver/bindings/ruby/tests/packages.solv URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/packages.solv?rev=8873&view=auto ============================================================================== Binary file - no diff available. Added: trunk/sat-solver/bindings/ruby/tests/patch_updates.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/patch_updates.rb?rev=8873&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/patch_updates.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/patch_updates.rb Fri Feb 22 11:42:21 2008 @@ -0,0 +1,136 @@ +$:.unshift "../../../build/bindings/ruby" + +# test Patch and Update + +require 'satsolver' +require '_solv2patches' + +pool = SatSolver::Pool.new +pool.arch = "x86_64" + +# load _all_ packages as 'installed' +system = pool.add_solv( "packages.solv" ) + +# now solve, fixing the system +solver = SatSolver::Solver.new( pool, system ) +solver.allow_uninstall = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +removals = [] +solver.each_to_remove { |s| + removals << s +} + +puts "#{removals.size} solvables scheduled for removal" + +# create new 'system' from old, dropping removals + +new_system = pool.create_repo( "new_system" ) +system.each { |s| + new_system << s unless removals.include? s +} + +# +# now check new system +# + +solver = SatSolver::Solver.new( pool, new_system ) +solver.allow_uninstall = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +# these shouldn't print anything + +solver.each_to_install { |s| + puts "Install #{s}" +} +solver.each_to_remove { |s| + puts "Remove #{s}" +} + +# +# Add the repo with updates +# + +updates = pool.add_solv( "updates.solv" ) +updates.name = "updates" + +pool.prepare +solver = SatSolver::Solver.new( pool, new_system ) +solver.allow_uninstall = true +solver.update_system = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +# +# Now match updates to patches +# + +patches = solv2patches "patches.solv", "x86_64" + +# +# Build a lookup hash +# +# Matching N patches to M updates would be a O(NxM) complexity +# hashing patches by package name should reduce this to O(M) +# + +updates = Hash.new +patches.each { |patch| + next if patch.name[0,3] == "lib" + patch.contains.each { |c| + l = updates[c.name] || [] + l << [c,patch] + updates[c.name] = l + } +} + +output = [] + +# +# Now iterate over all computed package updates +# and match them to patches +# If a patch matches, collect it in 'output' +# If no patch matches, create an artificial one (severty 'normal') +# +count = 0 +solver.each_to_update { |o,n| + count += 1 + l = updates[n.name] # any patches known for this update ? + patch = nil + if l + l.each { |cp| # Y: find exact name,evr match + c = cp.first + if n.evr == c.evr + patch = cp[1] + break + end + } + end + unless patch +# puts "Nothing patches #{n}" + buildtime = 0 # should be: n.buildtime + patch = Patch.new( n.name, n.evr, "normal", n.buildtime ) + patch.summary = "Update of #{o.name}-#{o.evr}.#{o.arch}" + patch.add n.name, n.evr, n.arch + end + output << patch +} + +final = output.uniq.sort { |a,b| + res = a.timestamp <=> b.timestamp + res = a.name <=> b.name if res == 0 + res +} +puts "Reduced #{count} updates to #{final.size} patches" + +final.each { |p| + puts "#{p.category}: #{p.name}-#{p.evr} #{p.summary}" +} \ No newline at end of file Added: trunk/sat-solver/bindings/ruby/tests/patches.solv URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/patches.solv?rev=8873&view=auto ============================================================================== Binary file - no diff available. Added: trunk/sat-solver/bindings/ruby/tests/updates.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/updates.rb?rev=8873&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/updates.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/updates.rb Fri Feb 22 11:42:21 2008 @@ -0,0 +1,89 @@ +$:.unshift "../../../build/bindings/ruby" + +# test Updates + +require 'satsolver' + +pool = SatSolver::Pool.new +pool.arch = "x86_64" + +# load _all_ packages as 'installed' +system = pool.add_solv( "packages.solv" ) + +# now solve, fixing the system +solver = SatSolver::Solver.new( pool, system ) +solver.allow_uninstall = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +removals = [] +solver.each_to_remove { |s| + removals << s +} + +puts "#{removals.size} solvables scheduled for removal" + +# create new 'system' from old, dropping removals + +new_system = pool.create_repo( "new_system" ) +system.each { |s| + new_system << s unless removals.include? s +} + +# +# now check new system +# + +solver = SatSolver::Solver.new( pool, new_system ) +solver.allow_uninstall = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +# these shouldn't print anything + +solver.each_to_install { |s| + puts "Install #{s}" +} +solver.each_to_remove { |s| + puts "Remove #{s}" +} + +# +# Add the repo with updates +# + +updates = pool.add_solv( "updates.solv" ) +updates.name = "updates" + +pool.prepare +solver = SatSolver::Solver.new( pool, new_system ) +solver.allow_uninstall = true +solver.update_system = true +solver.fix_system = true + +pool.prepare +solver.solve( pool.create_transaction ) + +count = 0 +solver.each_to_install { |s| + count += 1 +} +puts "#{count} installs" + +count = 0 +solver.each_to_remove { |s| + count += 1 +} +puts "#{count} removals" + + +count = 0 +solver.each_to_update { |o,n| + count += 1 + puts n +} +puts "#{count} updates" Added: trunk/sat-solver/bindings/ruby/tests/updates.solv URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/updates.solv?rev=8873&view=auto ============================================================================== Binary file - no diff available. -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
kkaempf@svn.opensuse.org