Home Home > 2008 > 10 > 03 > Developing with libyui/libzypp & python – part3
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

Developing with libyui/libzypp & python – part3

October 3rd, 2008 by

In part 1 we installed and tested libyui and its python binding and part 2 was about constructing the GUI. Now its time for the libzypp-bindings – of course for python ;). So far the GUI looks like:


We will import a repository’s metadata and list its content. But let’s move on …
I assume you have already installed the software from part 1. Then we’ll just donwload the missing parts.
zypper in prefix-opt-python-zypp prefix-opt-libzypp

First of all, we need to initialize zypp. This looks like this:
import zypp # import the module
repoTmpPath = "/tmp/repoTmpPath" # temporary Path
myZypp = zypp.ZYppFactory_instance().getZYpp() # create the instance
myTarget = myZypp.initializeTarget(zypp.Pathname(repoTmpPath)) # target (aka "root")
repoManagerOptions = zypp.RepoManagerOptions(zypp.Pathname(repoTmpPath)) # where to store the metadata
repoManager = zypp.RepoManager(repoManagerOptions) # manages multiple repositories
pool = myZypp.pool() # pool of packages
(Notice the usage if repoTmpPath twice. This is done to make sure we don’t interfere with the installed system.)

Then we need to create a RepoInfo. RepoInfo stores data of the repository like URL and name.
myRepoInfo = zypp.RepoInfo() # constructor
myRepoInfo.addBaseUrl(zypp.Url(myRepoString)) # add URL
myRepoInfo.setAlias("default") # add alias
myRepoInfo.setName("default") # add name
myRepoInfo.setEnabled(True) # enable
myRepoInfo.setType(zypp.RepoType.RPMMD) # for only RPMMD - notice the checkbox ;)
myRepoInfo.setGpgCheck(False) # don't check for now

After this we can add the repository to the manager and load the metadata into the pool:
repoManager.addRepository(myRepoInfo) # add the repoInfo
repoManager.refreshMetadata(myRepoInfo) # fetch metadata
repoManager.buildCache(myRepoInfo) # build cache
repoManager.loadFromCache(myRepoInfo) # load cache

Now we’re ready and have a bunch of packages/metadata in the pool. Let’s print them:
for item in pool: # iterate over the pool
#
# only packages, no sources/patches
if zypp.isKindPackage(item):
msg += "Name: "
msg += str(item.name())
msg += " - "
msg += "Version: "
msg += str(zypp.asKindPackage(item).edition())
msg += " - "
msg += "Summary: "
msg += str(zypp.asKindPackage(item).summary())
msg += "\n"
lowerLog.appendLines(str(msg))

Tada, we’re done. The complete code can be downloaded HERE. Don’t forget to install the software from part 1.

Howto start the program:
i586:
ZYPP_KEYRING_DEFAULT_ACCEPT_ALL=1 PATH=/opt/yuitest/bin/:$PATH LD_LIBRARY_PATH=/opt/yuitest/lib PYTHONPATH=/opt/yuitest/lib/python2.5/site-packages/ python repoviewer.py
#
x86_64:
ZYPP_KEYRING_DEFAULT_ACCEPT_ALL=1 PATH=/opt/yuitest/bin/:$PATH LD_LIBRARY_PATH=/opt/yuitest/lib64 PYTHONPATH=/opt/yuitest/lib64/python2.5/site-packages/ python repoviewer.py

And here is the screenshot:

Both comments and pings are currently closed.

Comments are closed.