f95237213b738c75ff9f892fe2e0d865fadac4cd
[certmaster.git] / certmaster / minion / modules / yumcmd.py
1 # Copyright 2007, Red Hat, Inc
2 # James Bowes <jbowes@redhat.com>
3 #
4 # This software may be freely redistributed under the terms of the GNU
5 # general public license.
6 #
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10
11 import func_module
12
13 import yum
14
15 # XXX Use internal yum callback or write a useful one.
16 class DummyCallback(object):
17
18 def event(self, state, data=None):
19 pass
20
21 class Yum(func_module.FuncModule):
22
23 version = "0.0.1"
24 api_version = "0.0.1"
25 description = "Package updates through yum."
26
27 def update(self):
28 # XXX support updating specific rpms
29 ayum = yum.YumBase()
30 ayum.doGenericSetup()
31 ayum.doRepoSetup()
32 try:
33 ayum.doLock()
34 ayum.update()
35 ayum.buildTransaction()
36 ayum.processTransaction(
37 callback=DummyCallback())
38 finally:
39 ayum.closeRpmDB()
40 ayum.doUnlock()
41 return True
42
43 def check_update(self, repo=None):
44 """Returns a list of packages due to be updated"""
45 ayum = yum.YumBase()
46 ayum.doConfigSetup()
47 ayum.doTsSetup()
48 if repo is not None:
49 ayum.repos.enableRepo(repo)
50 return map(str, ayum.doPackageLists('updates').updates)