diff options
author | Klaus Kämpf <kkaempf@suse.de> | 2012-02-13 10:48:08 +0100 |
---|---|---|
committer | Klaus Kämpf <kkaempf@suse.de> | 2012-02-13 10:48:08 +0100 |
commit | 953f0f14cc1140a3e8827853a08dca316f8363eb (patch) | |
tree | 2a4f770034567181b12c172d3af0d5abebf77dab | |
parent | 7ca0edb323a930a1c2dd8f27a4d0eec4368d5c74 (diff) | |
download | libzypp-bindings-953f0f14cc1140a3e8827853a08dca316f8363eb.tar.gz libzypp-bindings-953f0f14cc1140a3e8827853a08dca316f8363eb.tar.bz2 libzypp-bindings-953f0f14cc1140a3e8827853a08dca316f8363eb.zip |
Example and tests for callbacks in Python
-rw-r--r-- | swig/python/tests/callbacks.py | 54 |
1 files changed, 54 insertions, 0 deletions
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" |