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
1=== modified file 'tools/pkgmgr_gen.py'
2--- tools/pkgmgr_gen.py 2009-11-17 20:36:04 +0000
3+++ tools/pkgmgr_gen.py 2010-03-24 07:39:29 +0000
4@@ -20,6 +20,7 @@
5 import urllib
6 import gzip
7 import urlparse
8+import subprocess
9 from lxml.etree import parse
10 import xml.sax
11 from xml.sax.handler import ContentHandler
12@@ -211,7 +212,42 @@
13 if self.inArch:
14 self.package['subarch'] += content
15
16-def loadRepos(repolist):
17+def loadInstalled():
18+ packages = {}
19+ lines = subprocess.Popen(['rpm', '-qa', '--queryformat', '%{NAME},%{EPOCH},%{VERSION},%{RELEASE},%{ARCH}\n'], stdout = subprocess.PIPE).communicate()[0].split("\n")
20+ for line in lines:
21+ if len(line) > 0:
22+ name, epoch, version, release, subarch = line.split(",")
23+ if subarch == '(none)':
24+ subarch = 'noarch'
25+ if epoch == '(none)':
26+ epoch = None
27+ file = name + '-' + version + '-' + release + '.' + subarch + '.rpm'
28+ new = True
29+ if name in packages:
30+ for instance in packages[name]:
31+ if subarch == instance['arch']:
32+ new = False
33+ if new and (subarch in subarchs or 'all' in subarchs):
34+ # Store what we want in our structure.
35+ packages.setdefault(name, []).append({'filename':file, 'mtime':'', 'name':name, \
36+ 'arch':subarch, 'epoch':epoch, 'version':version, \
37+ 'release':release})
38+ return packages
39+
40+def loadCache():
41+ prefix = '/var/cache/yum'
42+ repolist = []
43+ for dirname in os.listdir(prefix):
44+ if os.path.isdir(prefix + '/' + dirname):
45+ repolist.append('file://' + prefix + '/' + dirname + '/')
46+
47+ if options.verbose:
48+ print repolist
49+
50+ return loadRepos(repolist, True)
51+
52+def loadRepos(repolist, cache_mode = False):
53 '''
54 repolist is a list of urls to yum repositories.
55
56@@ -239,16 +275,19 @@
57 '''
58 packages = {}
59 for repo in repolist:
60- url = urlparse.urljoin(repo, './repodata/repomd.xml')
61+ if cache_mode:
62+ url = urlparse.urljoin(repo, './repomd.xml')
63+ else:
64+ url = urlparse.urljoin(repo, './repodata/repomd.xml')
65
66 if options.verbose:
67 print 'Loading repo metadata : %s' % url
68
69- try:
70- opener = pkgmgr_URLopener()
71- file, message = opener.retrieve(url)
72- except:
73- sys.exit()
74+ #try:
75+ opener = pkgmgr_URLopener()
76+ file, message = opener.retrieve(url)
77+ #except:
78+ # sys.exit()
79
80 try:
81 tree = parse(file)
82@@ -263,7 +302,10 @@
83 if property.tag.endswith('location'):
84 primaryhref = property.get('href')
85
86- url = urlparse.urljoin(repo, './' + primaryhref)
87+ if cache_mode:
88+ url = urlparse.urljoin(repo, './' + primaryhref.split('/')[-1])
89+ else:
90+ url = urlparse.urljoin(repo, './' + primaryhref)
91
92 if options.verbose:
93 print 'Loading : %s' % url
94@@ -372,6 +414,10 @@
95 package_dict = loadRpms(search_dirs)
96 elif options.yumrepos:
97 package_dict = loadRepos(repos)
98+ elif options.yumcache:
99+ package_dict = loadCache()
100+ elif options.installed:
101+ package_dict = loadInstalled()
102
103 if options.verbose:
104 print 'Processing package headers'
105@@ -426,6 +472,14 @@
106 help='''Comma separated list of directories to scan for RPMS.
107 Wilcards are permitted.
108 ''')
109+
110+ p.add_option('--yumcache', '-c', action='store_true',
111+ help='''Use the Yum cache to find packages. This option currently
112+ fails for cache items stored with sqlite.
113+ ''')
114+
115+ p.add_option('--installed', '-I', action='store_true',
116+ help='Use the installed set of packages.')
117
118 p.add_option('--enddate', '-e', action='store', \
119 type='string', \
120@@ -495,8 +549,8 @@
121 print "Option --uri must be specified to produce a PackageList Tag for rpm formatted files."
122 sys.exit(1)
123
124- if not options.rpmdirs and not options.yumrepos:
125- print "One of --rpmdirs and --yumrepos must be specified"
126+ if not options.rpmdirs and not options.yumrepos and not options.yumcache and not options.installed:
127+ print "One of --rpmdirs, --yumrepos, --installed, or --yumcache must be specified"
128 sys.exit(1)
129
130 # Set up list of directories to search

Subscribers

People subscribed via source and target branches

to all changes: