Mailinglist Archive: zypp-commit (301 mails)

< Previous Next >
[zypp-commit] r7656 - in /trunk/sat-solver/examples: ./ ruby/ ruby/basic.rb ruby/yps.rb
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Fri, 26 Oct 2007 13:57:21 -0000
  • Message-id: <20071026135721.75E9217378@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Fri Oct 26 15:57:21 2007
New Revision: 7656

URL: http://svn.opensuse.org/viewcvs/zypp?rev=7656&view=rev
Log:
examples

Added:
trunk/sat-solver/examples/
trunk/sat-solver/examples/ruby/
trunk/sat-solver/examples/ruby/basic.rb
trunk/sat-solver/examples/ruby/yps.rb

Added: trunk/sat-solver/examples/ruby/basic.rb
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/examples/ruby/basic.rb?rev=7656&view=auto
==============================================================================
--- trunk/sat-solver/examples/ruby/basic.rb (added)
+++ trunk/sat-solver/examples/ruby/basic.rb Fri Oct 26 15:57:21 2007
@@ -0,0 +1,49 @@
+require 'satsolver'
+
+include Satsolver
+
+pool = Pool.new
+#puts pool.methods.sort
+
+#s = pool.add_empty_source
+
+f =
File.open('../../testsuite/data.libzypp/basic-exercises/exercise-20-packages.solv',
'r')
+s = pool.add_source_solv(f, 'foo')
+
+f =
File.open('../../testsuite/data.libzypp/basic-exercises/exercise-20-system.solv',
'r')
+installed = pool.add_source_solv(f, 'system')
+
+pool.each_source do |repo|
+ puts repo.name
+end
+
+s.each_solvable do |r|
+ puts "#{r.name}"
+end
+
+q = Queue.new
+puts q.empty?
+
+r = pool.select_solvable(s, 'gnome-desktop')
+puts r.name
+
+# push one command and one resolvable to the queue
+q.push(SOLVER_INSTALL_SOLVABLE)
+q.push(r)
+
+pool.prepare
+pool.promoteepoch = true
+
+# no packages installed so use add_empty_source
+solv = Solver.new(pool, installed)
+
+solv.fixsystem = 0
+solv.updatesystem = 0
+solv.allowdowngrade = 0
+solv.allowuninstall = 0
+solv.noupdateprovide = 0
+
+# solve the queue
+solv.solve(q)
+
+solv.print_decisions
\ No newline at end of file

Added: trunk/sat-solver/examples/ruby/yps.rb
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/examples/ruby/yps.rb?rev=7656&view=auto
==============================================================================
--- trunk/sat-solver/examples/ruby/yps.rb (added)
+++ trunk/sat-solver/examples/ruby/yps.rb Fri Oct 26 15:57:21 2007
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+require 'satsolver'
+include Satsolver
+
+def select_solvable(pool, source, name)
+ Id id;
+ Queue plist;
+ int i, end;
+ Solvable *s;
+
+ id = str2id(pool, name, 1)
+ queueinit(plist);
+ i = source ? source.start : 1
+ tend = source ? source.start + source.nsolvables : pool.nsolvables
+ for ( i in i..tend)
+ s = pool.solvables + i
+ next if not pool_installable(pool, s)
+ queuepush(plist, i) if (s.name == id)
+ end
+
+ prune_best_version_arch(pool, plist);
+
+ if (plist.count == 0)
+ puts("unknown package '#{name}'")
+ exit(1);
+ end
+
+ id = plist.elements[0];
+ queuefree(&plist);
+
+ return pool.solvables + id;
+end
+
+
+//-----------------------------------------------
+
+int
+main(int argc, char **argv)
+{
+ Pool *pool; // available packages (multiple repos)
+ FILE *fp;
+ Source *system; // installed packages (single repo, aka 'Source')
+ Solvable *xs;
+ Solver *solv;
+ Source *channel;
+ Queue job;
+ Id id;
+ int erase = 0;
+
+ pool = pool_create();
+ pool_setarch(pool, "i686");
+ pool->verbose = 1;
+ queueinit(&job);
+
+ if (argc < 3)
+ {
+ fprintf(stderr, "Usage:\n yps <system> <source> [ ... <source>]
<name>\n");
+ fprintf(stderr, " to install a package <name>\n");
+ fprintf(stderr, "\n yps -e <system> <name>\n");
+ fprintf(stderr, " to erase a package <name>\n");
+ exit(0);
+ }
+
+ // '-e' ?
+
+ if (argc > 1 && !strcmp(argv[1], "-e"))
+ {
+ erase = 1;
+ argc--;
+ argv++;
+ }
+
+ // Load system file (installed packages)
+
+ if ((fp = fopen(argv[1], "r")) == NULL)
+ {
+ perror(argv[1]);
+ exit(1);
+ }
+ system = pool_addsource_solv(pool, fp, "system");
+ channel = 0;
+ fclose(fp);
+
+ // Load further repo files (available packages)
+
+ argc--;
+ argv++;
+ while (argc > 2) /* all but last arg are sources */
+ {
+ if ((fp = fopen(argv[1], "r")) == 0)
+ {
+ perror(argv[1]);
+ exit(1);
+ }
+ channel = pool_addsource_solv(pool, fp, argv[1]);
+ fclose(fp);
+ argv++;
+ argc--;
+ }
+
+ // setup job queue
+ if (!argv[1][0])
+ ;
+ else if (!erase)
+ {
+ xs = select_solvable(pool, channel, argv[1]);
+ queuepush(&job, SOLVER_INSTALL_SOLVABLE);
+ queuepush(&job, xs - pool->solvables);
+ }
+ else
+ {
+ id = str2id(pool, argv[1], 1);
+ queuepush(&job, SOLVER_ERASE_SOLVABLE_NAME);
+ queuepush(&job, id);
+ }
+
+ pool_prepare(pool);
+
+ pool->promoteepoch = 1;
+
+ // start solving
+
+ solv = solver_create(pool, system);
+
+ solv->fixsystem = 0;
+ solv->updatesystem = 0;
+ solv->allowdowngrade = 0;
+ solv->allowuninstall = 0;
+ solv->noupdateprovide = 0;
+
+ // Solve !
+
+ solve(solv, &job);
+
+ // clean up
+
+ queuefree(&job);
+ solver_free(solv);
+ pool_free(pool);
+
+ exit(0);
+}
+
+// EOF

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages