From 953f0f14cc1140a3e8827853a08dca316f8363eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Mon, 13 Feb 2012 10:48:08 +0100 Subject: Example and tests for callbacks in Python --- swig/python/tests/callbacks.py | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 swig/python/tests/callbacks.py diff --git a/swig/python/tests/callbacks.py b/swig/python/tests/callbacks.py new file mode 100644 index 0000000..4f446b7 --- /dev/null +++ b/swig/python/tests/callbacks.py @@ -0,0 +1,54 @@ +import os +cwd = os.path.abspath(os.path.dirname(__file__)) + +import sys +sys.path.insert(0, cwd + "/../../../build/swig/python") +import zypp + +class CommitReceiver: + def removal_start(self, resolvable): + print "Starting to remove ", resolvable.name() + + def removal_progress(self, resolvable, percentage): + print "Remove of ", resolvable.name(), " at ", percentage, "%" + return True + + def removal_finish(self, resolvable, error, reason): + print "Remove of ", resolvable.name(), " finished with problem ", error, ": ", reason + + def removal_problem(self, resolvable, error, description): + print "Remove of ", resolvable.name(), " has problem ", error, ": ", description + return "ignore" + +Z = zypp.ZYppFactory_instance().getZYpp() +Z.initializeTarget( zypp.Pathname("/") ) +Z.target().load(); + +commit_callbacks = zypp.CommitCallbacks() +commit_receiver = CommitReceiver() +commit_callbacks.connect(commit_receiver) + +for item in Z.pool(): + if item.resolvable().name() == "gedit": + print "Emitting removal of ", item.resolvable().name() + item.status().setToBeUninstalled(zypp.ResStatus.USER) + resolvable = item.resolvable() + if not Z.resolver().resolvePool(): + print "Problem count: %d" % Z.resolver().problems().size() + policy = zypp.ZYppCommitPolicy() + policy.downloadMode(zypp.DownloadInAdvance) + policy.dryRun( False ) + policy.syncPoolAfterCommit( False ) + print "Committing" + try: + result = Z.commit( policy ) + print "Done:", result + except: + print "Oops" + break + +# raise + +print "disconnecting" +commit_callbacks.disconnect() +print "disconnected" -- cgit v1.2.3