<commit_before>#
# Copyright (c) 2008-2009 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

"""
Advisory module for SLES.
"""

import logging

from updatebot.advisories.common import BaseAdvisor

log = logging.getLogger('updatebot.advisories')

class Advisor(BaseAdvisor):
    """
    Class for processing SLES advisory information.
    """

    allowExtraPackages = True

    def load(self):
        """
        Parse the required data to generate a mapping of binary package
        object to patch object for a given platform into self._pkgMap.
        """

        for path, client in self._pkgSource.getClients().iteritems():
            log.info('loading patch information %s' % path)
            for patch in client.getPatchDetail():
                self._loadOne(patch, path)

    def _loadOne(self, patch, path):
        """
        Load one patch into mappings.
        @param patch: repomd patch object
        @type patch: repomd.patchxml._Patch
        @param path: base path to repository
        @type path: string
        """

        if self._filterPatch(patch):
            return

        for package in patch.packages:
            package.location = path + '/' + package.location
            if package not in self._pkgMap:
                self._pkgMap[package] = set()
            self._pkgMap[package].add(patch)

    def _hasException(self, binPkg):
        """
        Check the config for repositories with exceptions for sending
        advisories. (io. repositories that we generated metadata for.)
        @param binPkg: binary package object
        @type binPkg: repomd.packagexml._Package
        """

        shortPath = binPkg.location.split('/')[0]

        for advisoryException in self._cfg.advisoryException:
            path = advisoryException[0].split('/')[0]
            if path == shortPath:
                return True
        return False

    def _isUpdatesRepo(self, binPkg):
        """
        Check the repository name. If this package didn't come from a updates
        repository it is probably not security related.
        @param binPkg: binary package object
        @type binPkg: repomd.packagexml._Package
        """

        # msw agrees that this seems to be a sane check.

        shortPath = binPkg.location.split('/')[0]

        if shortPath.endswith('Updates'):
            return True
        else:
            return False

    def _checkForDuplicates(self, patchSet):
        """
        Check a set of "patch" objects for duplicates. If there are duplicates
        combine any required information into the first object in the set and
        return True, otherwise return False.
        """

        # W0613 - Unused argument patchSet
        # pylint: disable-msg=W0613
        
        # Don't have dups on sles 
        # Now we do have duplicates in sles
        patchObjNames = list(patchSet)

        patchObjNames.sort()

        tempPatchObjNames = {}

        tempPatchObjNames = dict(('-'.join(x.split('-')[:-1]), x) 
                                 for x in patchObjNames)

        newpatchObjNames = list(tempPatchObjNames.values())

        if newpatchObjNames != patchObjNames:
            return True

        return False<commit_msg>Changing the sles _checkForDuplicates routine<commit_after>#
# Copyright (c) 2008-2009 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

"""
Advisory module for SLES.
"""

import logging

from updatebot.advisories.common import BaseAdvisor

log = logging.getLogger('updatebot.advisories')

class Advisor(BaseAdvisor):
    """
    Class for processing SLES advisory information.
    """

    allowExtraPackages = True

    def load(self):
        """
        Parse the required data to generate a mapping of binary package
        object to patch object for a given platform into self._pkgMap.
        """

        for path, client in self._pkgSource.getClients().iteritems():
            log.info('loading patch information %s' % path)
            for patch in client.getPatchDetail():
                self._loadOne(patch, path)

    def _loadOne(self, patch, path):
        """
        Load one patch into mappings.
        @param patch: repomd patch object
        @type patch: repomd.patchxml._Patch
        @param path: base path to repository
        @type path: string
        """

        if self._filterPatch(patch):
            return

        for package in patch.packages:
            package.location = path + '/' + package.location
            if package not in self._pkgMap:
                self._pkgMap[package] = set()
            self._pkgMap[package].add(patch)

    def _hasException(self, binPkg):
        """
        Check the config for repositories with exceptions for sending
        advisories. (io. repositories that we generated metadata for.)
        @param binPkg: binary package object
        @type binPkg: repomd.packagexml._Package
        """

        shortPath = binPkg.location.split('/')[0]

        for advisoryException in self._cfg.advisoryException:
            path = advisoryException[0].split('/')[0]
            if path == shortPath:
                return True
        return False

    def _isUpdatesRepo(self, binPkg):
        """
        Check the repository name. If this package didn't come from a updates
        repository it is probably not security related.
        @param binPkg: binary package object
        @type binPkg: repomd.packagexml._Package
        """

        # msw agrees that this seems to be a sane check.

        shortPath = binPkg.location.split('/')[0]

        if shortPath.endswith('Updates'):
            return True
        else:
            return False

    def _checkForDuplicates(self, patchSet):
        """
        Check a set of "patch" objects for duplicates. If there are duplicates
        combine any required information into the first object in the set and
        return True, otherwise return False.
        """

        # W0613 - Unused argument patchSet
        # pylint: disable-msg=W0613
        
        # Don't have dups on sles 
        # Now we do have duplicates in sles
        # Testing code from centos

        if not len(patchSet):
            return False

        primary = list(patchSet)[0]
        for patch in patchSet:
            if patch is primary:
                continue

            # These are the same if they use the same advisory.
            if primary.upstreamAdvisoryUrl != patch.upstreamAdvisoryUrl:
                return False

            # Copy pkg data into the primary
            primary.pkgs.update(patch.pkgs)
            primary.packages.update(patch.packages)
        return True
{'fraction_non_alphanumeric': 0.07775744903293257, 'fraction_numerical': 0.006534239414532148, 'mean_word_length': 2.195407098121086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5873527', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1948, 'n_words': 736}