Author: mlandres Date: Thu Dec 6 00:45:25 2007 New Revision: 8041 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8041&view=rev Log: callback draft Added: trunk/libzypp-bindings/examples/python/callbacks.py (with props) trunk/libzypp-bindings/swig/python/callbacks.i Modified: trunk/libzypp-bindings/swig/RepoManager.i trunk/libzypp-bindings/swig/zypp.i Added: trunk/libzypp-bindings/examples/python/callbacks.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/examples/python/callbacks.py?rev=8041&view=auto ============================================================================== --- trunk/libzypp-bindings/examples/python/callbacks.py (added) +++ trunk/libzypp-bindings/examples/python/callbacks.py Thu Dec 6 00:45:25 2007 @@ -0,0 +1,44 @@ +#! /usr/bin/python +import zypp + +# --------------------------------------------------------- + +def myProgress( val ): + print "myProgress %d" % val + return True + +rec = zypp.ScanRpmDbReceive() +rec.set_pymethod( myProgress ) + +# --------------------------------------------------------- + +Z = zypp.ZYppFactory_instance().getZYpp() + +if True: + Z.initializeTarget( zypp.Pathname("/Local/ROOT") ) + Z.addResolvables( Z.target().resolvables(), True ); + +if False: + repoManager = zypp.RepoManager() + repos = repoManager.knownRepositories() + for repo in repos: + if not repo.enabled(): + continue + if not repoManager.isCached( repo ): + repoManager.buildCache( repo ) + Z.addResolvables( repoManager.createFromCache( repo ).resolvables() ) + +print "Items: %d" % ( Z.pool().size() ) + +if False: + for item in Z.pool(): + if item.status().isInstalled(): + t = "i" + else: + t = "*" + print "%s %s:%s-%s.%s\t(%s)" % ( t, + item.resolvable().kind(), + item.resolvable().name(), + item.resolvable().edition(), + item.resolvable().arch(), + item.resolvable().repository().info().alias() ) Modified: trunk/libzypp-bindings/swig/RepoManager.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/swig/RepoManager.i?rev=8041&r1=8040&r2=8041&view=diff ============================================================================== --- trunk/libzypp-bindings/swig/RepoManager.i (original) +++ trunk/libzypp-bindings/swig/RepoManager.i Thu Dec 6 00:45:25 2007 @@ -54,6 +54,6 @@ void removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); RepoInfo getRepositoryInfo( const std::string &alias, - const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); + const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); }; Added: trunk/libzypp-bindings/swig/python/callbacks.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/swig/python/callbacks.i?rev=8041&view=auto ============================================================================== --- trunk/libzypp-bindings/swig/python/callbacks.i (added) +++ trunk/libzypp-bindings/swig/python/callbacks.i Thu Dec 6 00:45:25 2007 @@ -0,0 +1,71 @@ + +struct ScanRpmDbReceive +{ + void set_pymethod(PyObject *pyfunc); +}; + +%{ + namespace zypp + { + struct ScanRpmDbReceive : public callback::ReceiveReporttarget::rpm::ScanDBReport + { + typedef target::rpm::ScanDBReport Report; + + ScanRpmDbReceive() + : _pyfunc( 0 ) + { connect(); } + + ~ScanRpmDbReceive() + { disconnect(); } + + virtual void start() + { + std::cerr << "ScanRpmDbReceive start" << std::endl; + _last = -1; + } + + virtual bool progress(int value) + { + if ( value == _last ) + return Report::progress( value ); + _last = value; + + if ( ! _pyfunc ) + return Report::progress( value ); + + bool ret = Report::progress( value ); + PyObject * arglist = Py_BuildValue( "(i)", value ); // Build argument list + PyObject * result = PyEval_CallObject( _pyfunc, arglist ); // Call Python + Py_DECREF( arglist ); // Trash arglist + if ( result ) { // If no errors, return bool + ret = PyLong_AsLong( result ); + } + Py_XDECREF( result ); + return ret; + } + + virtual Action problem( target::rpm::ScanDBReport::Error error, const std::string & description ) + { + //std::cerr << "ScanRpmDbReceive problem" << std::endl; + return Report::problem( error, description ); + } + + virtual void finish( Error error, const std::string & reason ) + { + //std::cerr << "ScanRpmDbReceive finish" << std::endl; + } + + void set_pymethod( PyObject * pyfunc_r ) + { + Py_INCREF( pyfunc_r ); + if ( _pyfunc ) + Py_DECREF( _pyfunc ); + _pyfunc = pyfunc_r; + } + + private: + int _last; + PyObject * _pyfunc; + }; + } +%} Modified: trunk/libzypp-bindings/swig/zypp.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/swig/zypp.i?rev=8041&r1=8040&r2=8041&view=diff ============================================================================== --- trunk/libzypp-bindings/swig/zypp.i (original) +++ trunk/libzypp-bindings/swig/zypp.i Thu Dec 6 00:45:25 2007 @@ -141,6 +141,9 @@ %include "TmpPath.i" %include "ItemCapKind.i" %include "Resolver.i" +#ifdef SWIGPYTHON +%include "python/callbacks.i" +#endif class ZYpp -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org