Changes from Version 1 of YumCodeSnippets

Show
Ignore:
Author:
skvidal (IP: 24.211.246.61)
Timestamp:
10/21/08 20:52:21 (9 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • YumCodeSnippets

    v0 v1  
     1== Yum Code Snippets == 
     2 
     3This is just snippets of code using the yum modules for common/simple tasks. Add/edit/comment as you'd like. 
     4 
     5Open a local package as a yum package object w/o all the rest of the yum stuff: 
     6 
     7{{{ 
     8import yum.packages 
     9import rpmUtils.transaction 
     10ts = rpmUtils.transaction.initReadOnlyTransaction() 
     11lp = yum.packages.YumLocalPackage(ts, '/home/skvidal/yum-3.2.8-1.noarch.rpm') 
     12}}} 
     13 
     14replace '/home/skvidal/yum-3.2.8-1.noarch.rpm' with the full path to the package 
     15 
     16 
     17Return the gpg signature info from a package: 
     18{{{ 
     19import yum.packages 
     20import rpmUtils.transaction 
     21from rpmUtils.miscutils import getSigInfo 
     22ts = rpmUtils.transaction.initReadOnlyTransaction() 
     23lp = yum.packages.YumLocalPackage(ts, '/home/skvidal/yum-3.2.8-1.noarch.rpm') 
     24 
     25print getSigInfo(lp.hdr) 
     26 
     27}}} 
     28 
     29Given a filename of an rpm parse out the major information that's available: 
     30 
     31{{{ 
     32from rpmUtils.miscutils import splitFilename 
     33 
     34myfn = 'a2ps-4.13b-57.1.el5.src.rpm' 
     35 
     36(name, ver, rel, epoch, arch) = splitFilename(myfn) 
     37 
     38}}} 
     39 
     40 
     41Simplest transaction you can have (yum 3.2.7 and above): 
     42 
     43{{{ 
     44 
     45import yum 
     46my = yum.YumBase() 
     47my.install(name='somepackage') 
     48my.remove(name='someotherpackage') 
     49my.resolveDeps() 
     50my.processTransaction() 
     51}}} 
     52 
     53This helps you setup a repo at an arbitrary location, as a user and play with the object. Paste this into a file then run it with ipython for maximum usefulness like: 
     54 
     55{{{ ipython ./thisfile.py url://to/my/repo }}} 
     56 
     57{{{ 
     58 
     59import yum, os, sys 
     60my = yum.YumBase() 
     61my.conf.basecachedir = '/tmp/whereever' 
     62if not os.path.exists(my.conf.basecachedir): 
     63os.makedirs(my.conf.basecachedir) 
     64my.conf.cache = 0 
     65url = sys.argv[1]  
     66 
     67my.repos.disableRepo('*') 
     68 
     69newrepo = yum.yumRepo.YumRepository('myrepo') 
     70newrepo.name = 'myrepo - %s' % url 
     71newrepo.baseurl = [url]  
     72newrepo.basecachedir = my.conf.basecachedir 
     73newrepo.enablegroups = True 
     74my.repos.add(newrepo) 
     75my.repos.enableRepo(newrepo.id) 
     76my.doRepoSetup(thisrepo=newrepo.id) 
     77 
     78}}} 
     79 
     80 
     81Search for which package(s) own a file on the system 
     82{{{ 
     83import yum 
     84my = yum.YumBase() 
     85pkgs = my.rpmdb.whatProvides('/boot/vmlinuz-2.6.23.9-85.fc8', None, (None, None,None)) 
     86for pkg in pkgs: 
     87print pkg 
     88}}} 
     89 
     90more?