summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Lint/Pkgmgr.py
blob: 39c6016177e6f4654e577fe72a11e706d0216333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Bcfg2.Server.Lint

class Pkgmgr(Bcfg2.Server.Lint.ServerPlugin):
    """ find duplicate Pkgmgr entries with the same priority """

    @Bcfg2.Server.Lint.returnErrors
    def Run(self):
        if 'Pkgmgr' not in self.core.plugins:
            self.logger.info("Pkgmgr server plugin is not enabled, skipping Pkgmgr lint checks")
            return
        
        pset = set()
        for plist in self.core.plugins['Pkgmgr'].entries.values():
            if self.HandlesFile(plist.name):
                xdata = plist.data
                # get priority, type, group
                priority = xdata.getroot().get('priority')
                ptype = xdata.getroot().get('type')
                for pkg in xdata.findall("//Package"):
                    if pkg.getparent().tag == 'Group':
                        grp = pkg.getparent().get('name')
                        if (type(grp) is not str and
                            grp.getparent().tag == 'Group'):
                            pgrp = grp.getparent().get('name')
                        else:
                            pgrp = 'none'
                    else:
                        grp = 'none'
                        pgrp = 'none'
                    ptuple = (pkg.get('name'), priority, ptype, grp, pgrp)
                    # check if package is already listed with same
                    # priority, type, grp
                    if ptuple in pset:
                        self.LintError("duplicate-package",
                                       "Duplicate Package %s, priority:%s, type:%s" %
                                         (pkg.get('name'), priority, ptype))
                    else:
                        pset.add(ptuple)