Merge lp:~bcfg2/bcfg2/yum-tools into lp:bcfg2/stable

Proposed by David Strauss
Status: Needs review
Proposed branch: lp:~bcfg2/bcfg2/yum-tools
Merge into: lp:bcfg2/stable
Diff against target: 130 lines (+64/-10)
1 file modified
tools/pkgmgr_gen.py (+64/-10)
To merge this branch: bzr merge lp:~bcfg2/bcfg2/yum-tools
Reviewer Review Type Date Requested Status
Narayan Desai Pending
VCS imports Pending
Review via email: mp+22006@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

2482. By David Strauss

Add working support for generating a list based on installed modules. Add somewhat-broken support for reading from the Yum metadata cache.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tools/pkgmgr_gen.py'
--- tools/pkgmgr_gen.py 2009-11-17 20:36:04 +0000
+++ tools/pkgmgr_gen.py 2010-03-24 07:39:29 +0000
@@ -20,6 +20,7 @@
20import urllib20import urllib
21import gzip21import gzip
22import urlparse22import urlparse
23import subprocess
23from lxml.etree import parse24from lxml.etree import parse
24import xml.sax25import xml.sax
25from xml.sax.handler import ContentHandler26from xml.sax.handler import ContentHandler
@@ -211,7 +212,42 @@
211 if self.inArch:212 if self.inArch:
212 self.package['subarch'] += content213 self.package['subarch'] += content
213214
214def loadRepos(repolist):215def loadInstalled():
216 packages = {}
217 lines = subprocess.Popen(['rpm', '-qa', '--queryformat', '%{NAME},%{EPOCH},%{VERSION},%{RELEASE},%{ARCH}\n'], stdout = subprocess.PIPE).communicate()[0].split("\n")
218 for line in lines:
219 if len(line) > 0:
220 name, epoch, version, release, subarch = line.split(",")
221 if subarch == '(none)':
222 subarch = 'noarch'
223 if epoch == '(none)':
224 epoch = None
225 file = name + '-' + version + '-' + release + '.' + subarch + '.rpm'
226 new = True
227 if name in packages:
228 for instance in packages[name]:
229 if subarch == instance['arch']:
230 new = False
231 if new and (subarch in subarchs or 'all' in subarchs):
232 # Store what we want in our structure.
233 packages.setdefault(name, []).append({'filename':file, 'mtime':'', 'name':name, \
234 'arch':subarch, 'epoch':epoch, 'version':version, \
235 'release':release})
236 return packages
237
238def loadCache():
239 prefix = '/var/cache/yum'
240 repolist = []
241 for dirname in os.listdir(prefix):
242 if os.path.isdir(prefix + '/' + dirname):
243 repolist.append('file://' + prefix + '/' + dirname + '/')
244
245 if options.verbose:
246 print repolist
247
248 return loadRepos(repolist, True)
249
250def loadRepos(repolist, cache_mode = False):
215 '''251 '''
216 repolist is a list of urls to yum repositories.252 repolist is a list of urls to yum repositories.
217253
@@ -239,16 +275,19 @@
239 '''275 '''
240 packages = {}276 packages = {}
241 for repo in repolist:277 for repo in repolist:
242 url = urlparse.urljoin(repo, './repodata/repomd.xml')278 if cache_mode:
279 url = urlparse.urljoin(repo, './repomd.xml')
280 else:
281 url = urlparse.urljoin(repo, './repodata/repomd.xml')
243282
244 if options.verbose:283 if options.verbose:
245 print 'Loading repo metadata : %s' % url284 print 'Loading repo metadata : %s' % url
246285
247 try:286 #try:
248 opener = pkgmgr_URLopener()287 opener = pkgmgr_URLopener()
249 file, message = opener.retrieve(url)288 file, message = opener.retrieve(url)
250 except:289 #except:
251 sys.exit()290 # sys.exit()
252291
253 try:292 try:
254 tree = parse(file)293 tree = parse(file)
@@ -263,7 +302,10 @@
263 if property.tag.endswith('location'):302 if property.tag.endswith('location'):
264 primaryhref = property.get('href')303 primaryhref = property.get('href')
265304
266 url = urlparse.urljoin(repo, './' + primaryhref)305 if cache_mode:
306 url = urlparse.urljoin(repo, './' + primaryhref.split('/')[-1])
307 else:
308 url = urlparse.urljoin(repo, './' + primaryhref)
267309
268 if options.verbose:310 if options.verbose:
269 print 'Loading : %s' % url311 print 'Loading : %s' % url
@@ -372,6 +414,10 @@
372 package_dict = loadRpms(search_dirs)414 package_dict = loadRpms(search_dirs)
373 elif options.yumrepos:415 elif options.yumrepos:
374 package_dict = loadRepos(repos)416 package_dict = loadRepos(repos)
417 elif options.yumcache:
418 package_dict = loadCache()
419 elif options.installed:
420 package_dict = loadInstalled()
375421
376 if options.verbose:422 if options.verbose:
377 print 'Processing package headers'423 print 'Processing package headers'
@@ -426,6 +472,14 @@
426 help='''Comma separated list of directories to scan for RPMS.472 help='''Comma separated list of directories to scan for RPMS.
427 Wilcards are permitted.473 Wilcards are permitted.
428 ''')474 ''')
475
476 p.add_option('--yumcache', '-c', action='store_true',
477 help='''Use the Yum cache to find packages. This option currently
478 fails for cache items stored with sqlite.
479 ''')
480
481 p.add_option('--installed', '-I', action='store_true',
482 help='Use the installed set of packages.')
429483
430 p.add_option('--enddate', '-e', action='store', \484 p.add_option('--enddate', '-e', action='store', \
431 type='string', \485 type='string', \
@@ -495,8 +549,8 @@
495 print "Option --uri must be specified to produce a PackageList Tag for rpm formatted files."549 print "Option --uri must be specified to produce a PackageList Tag for rpm formatted files."
496 sys.exit(1)550 sys.exit(1)
497551
498 if not options.rpmdirs and not options.yumrepos:552 if not options.rpmdirs and not options.yumrepos and not options.yumcache and not options.installed:
499 print "One of --rpmdirs and --yumrepos must be specified"553 print "One of --rpmdirs, --yumrepos, --installed, or --yumcache must be specified"
500 sys.exit(1)554 sys.exit(1)
501555
502 # Set up list of directories to search556 # Set up list of directories to search

Subscribers

People subscribed via source and target branches

to all changes: