<commit_before>#
# Copyright (c) 2005 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.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import itertools

from conary import files
from conary import trove
from conary.deps import deps
from conary.local import deptable
from conary.repository import changeset, errors, findtrove

class AbstractTroveSource:
    """ Provides the interface necessary for performing
        findTrove operations on arbitrary sets of troves.
        As long as the subclass provides the following methods,
        findTrove will be able to search it.  You can set the 
        type of searching findTrove will default to here as 
        well.
    """

    def __init__(self):
        self._allowNoLabel = True
        self._bestFlavor = False
        self._getLeavesOnly = False

    def requiresLabelPath(self):
        return not self._allowNoLabel

    def getTroveLeavesByLabel(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionsByLabel(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveLeavesByBranch(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionsByBranch(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionFlavors(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroves(self, troveList, withFiles = True):
        raise NotImplementedError

    def resolveDependencies(self, label, depList):
        return {}

    def hasTroves(self, troveList):
        return NotImplementedError

    def getTrove(self, name, version, flavor, withFiles = True):
        trv = self.getTroves([(name, version, flavor)], withFiles)[0]
        if trv is None:
            raise errors.TroveMissing(name, version)
        else:
            return trv
            
    def getTroveVersionList(self, name, withFlavors=False):
        raise NotImplementedError

    def findTroves(self, labelPath, troves, defaultFlavor=None, 
                   acrossLabels=True, acrossFlavors=True, 
                   affinityDatabase=None, allowMissing=False):
        troveFinder = findtrove.TroveFinder(self, labelPath, 
                                            defaultFlavor, acrossLabels,
                                            acrossFlavors, affinityDatabase,
                                            allowNoLabel=self._allowNoLabel,
                                            bestFlavor=self._bestFlavor,
                                            getLeaves=self._getLeavesOnly)<commit_msg>raise NotImplementedError, don't return it<commit_after>#
# Copyright (c) 2005 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.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import itertools

from conary import files
from conary import trove
from conary.deps import deps
from conary.local import deptable
from conary.repository import changeset, errors, findtrove

class AbstractTroveSource:
    """ Provides the interface necessary for performing
        findTrove operations on arbitrary sets of troves.
        As long as the subclass provides the following methods,
        findTrove will be able to search it.  You can set the 
        type of searching findTrove will default to here as 
        well.
    """

    def __init__(self):
        self._allowNoLabel = True
        self._bestFlavor = False
        self._getLeavesOnly = False

    def requiresLabelPath(self):
        return not self._allowNoLabel

    def getTroveLeavesByLabel(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionsByLabel(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveLeavesByBranch(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionsByBranch(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroveVersionFlavors(self, query, bestFlavor=True):
        raise NotImplementedError

    def getTroves(self, troveList, withFiles = True):
        raise NotImplementedError

    def resolveDependencies(self, label, depList):
        return {}

    def hasTroves(self, troveList):
        raise NotImplementedError

    def getTrove(self, name, version, flavor, withFiles = True):
        trv = self.getTroves([(name, version, flavor)], withFiles)[0]
        if trv is None:
            raise errors.TroveMissing(name, version)
        else:
            return trv
            
    def getTroveVersionList(self, name, withFlavors=False):
        raise NotImplementedError

    def findTroves(self, labelPath, troves, defaultFlavor=None, 
                   acrossLabels=True, acrossFlavors=True, 
                   affinityDatabase=None, allowMissing=False):
        troveFinder = findtrove.TroveFinder(self, labelPath, 
                                            defaultFlavor, acrossLabels,
                                            acrossFlavors, affinityDatabase,
                                            allowNoLabel=self._allowNoLabel,
                                            bestFlavor=self._bestFlavor,
                                            getLeaves=self._getLeavesOnly)
{'fraction_non_alphanumeric': 0.05924713584288052, 'fraction_numerical': 0.0022913256955810145, 'mean_word_length': 2.518134715025907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '341532', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1550, 'n_words': 529}