openSUSE Lizards

Authors
Adrian Schröter (2)
Agustin Chavarria (1)
Akhil Laddha
Alexander Naumov
Alexander Orlovskyy (3)
Alexey Eromenko
Alin M Elena (2)
Andrea Florio (5)
Andreas Jaeger (26)
Andreas van dem Helge
Andrej Semen
Andrew Wafaa (24)
Arvin Schnell (4)
Bharath Acharya
Brian G. Merrell
Carl Fletcher
Casual Programmer
Christoph Thiel
Christopher Hobbs (15)
Ciaran Farrell (2)
Coly Li
Cristian Rodríguez
Daniel Bornkessel
David C. Rankin
Dean Hilkewich
Dinar Valeev (5)
Dirk Müller (1)
Dmitry Serpokryl (4)
Duncan Mac-Vicar
Eugene Pivnev
Fabio Mucciante
Gabriele Mohr
Gerrit Beine
Helman Rene Taleno Martinez
Helmut Schaa
Henne (5)
Herbert Graeber
Holgi
Hubert Mantel (1)
J. Daniel Schmidt (1)
James Tremblay (5)
Jan Blunck (4)
Jan Madsen (1)
Jan Nieuwenhuizen
Jan-Christoph Bornschlegel (3)
Jan-Simon Möller (18)
Javier Llorente
Jigish Gohil (10)
Jiri Srain (1)
Jiří Suchomel (1)
Johan Kotze (5)
John Terpstra
Joop Boonen
Josef Reidinger (7)
Juergen Weigert (1)
Julio Vannini (7)
Justin Haygood
Kálmán Kéménczy
Kevin Yeaux (9)
Klaas Freitag (14)
Klara Cihlarova
Klaus Kämpf
Klaus Singvogel
kl_eisbaer (10)
Lars Marowsky-Bree
Ludwig Nussel (3)
M. Edwin Zakaria
Manuel Trujillo
Marcus Hüwe (6)
Marcus Meissner (1)
Marcus Moeller (1)
Marcus Schaefer (1)
Martin Lasarsch (8)
Martin Mohring (8)
Martin Schmidkunz
Masim "Vavai" Sugianto (20)
Matt Sealey
Mauro Parra-Miranda
Michael Andres (1)
Michael Skiba
Michal Marek (3)
Michal Vyskocil (6)
Michal Zugec
mrdocs
Nikanth Karthikesan
Oswin Zulu
Peter Nixon
Peter Pöml (3)
Petr Mladek (23)
Petr Uzel
Philipp Thomas
Pragnesh Radadiya
Ray Chen
Ray Wang (1)
Ricardo Varas Santana (3)
Richard Bos (3)
Robert Lihm
Roman Drahtmueller
Rossana Motta (1)
Rupert Horstkötter (7)
Sascha Manns (33)
Sebastian Schöbinger (3)
Stanislav Visnovsky (7)
Stefan Haas (1)
Stefan Hundhammer (5)
Stefan Schubert (3)
Steffen Winterfeldt (4)
Stephan Kulow (8)
Suman Manjunath
Susanne Oberhauser (2)
Syamsul Qamar Ngabito
Thomas Göttlicher (4)
Thomas Schraitle (11)
Thruth Wang
Tuukka (11)
Ulrich Hecht
Wilken Gottwalt
Xin Wei Hu





 

Developing with libyui/libzypp & python - part3

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...
Friday, October 3rd, 2008 by Jan-Simon Möller Digg!

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:


Comments

No comments yet.

Sorry, the comment form is closed at this time.