<commit_before>#
# Copyright (c) 2004-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.
#
"""
Implements troves (packages, components, etc.) for the repository
"""

import changelog
import copy
import files
from lib import sha1helper
from lib.openpgpkey import getKeyCache
from lib.openpgpfile import KeyNotFound
import streams
import struct
import versions
from deps import deps
from changelog import ChangeLog
from streams import FrozenVersionStream
from streams import StringVersionStream
from streams import DependenciesStream
from streams import ByteStream

class TroveTuple(streams.StreamSet):
    _SINGLE_TROVE_TUP_NAME    = 0
    _SINGLE_TROVE_TUP_VERSION = 1
    _SINGLE_TROVE_TUP_FLAVOR  = 2

    ignoreUnknown = True
    streamDict = {
        _SINGLE_TROVE_TUP_NAME    : (streams.StringStream,        'name'    ),
        _SINGLE_TROVE_TUP_VERSION : (streams.StringVersionStream, 'version' ),
        _SINGLE_TROVE_TUP_FLAVOR  : (streams.DependenciesStream,  'flavor'  )
    }
    _streamDict = streams.StreamSetDef(streamDict)

    def __hash__(self):
        return hash((self.name(), self.version(), self.flavor()))

class TroveTupleList(streams.StreamCollection):
    streamDict = { 1 : TroveTuple }

    def add(self, name, version, flavor):
        dep = TroveTuple()
        dep.name.set(name)
        dep.version.set(version)
        dep.flavor.set(flavor)
        self.addStream(1, dep)

    def iter(self):
        return self.iterAll()

class BuildDependencies(TroveTupleList):
    pass

class LoadedTroves(TroveTupleList):
    pass

class InstallBucketItem(streams.StreamSet):
    _INSTALL_BIN_KEY  = 0
    _INSTALL_BIN_VALUE = 1

    ignoreUnknown = True
    streamDict = {
        _INSTALL_BIN_KEY    : (streams.StringStream,        'key'    ),
        _INSTALL_BIN_VALUE  : (streams.StringStream,        'value'  ),
    }
    _streamDict = streams.StreamSetDef(streamDict)


class InstallBucket(streams.StreamCollection):
    streamDict = { 1 : InstallBucketItem }

    # XXX these aren't particularly efficient; they imitate a dict with a list

    def add(self, key, value):
        item = InstallBucketItem()
        item.key.set(key)
        item.value.set(value)
        self.addStream(1, item)

    def keys(self):
        return [ x for x in self.iterkeys() ]

    def __iter__(self):
        return self.iterkeys()

    def iterkeys(self):
        for bucket in self.getStreams(1):
            yield bucket.key()

    def values(self):
        return [ x for x in self.itervalues() ]

    def itervalues(self):
        for bucket in self.getStreams(1):
            yield bucket.value()

    def items(self):
        return [ x for x in self.iteritems() ]

    def iteritems(self):
        for bucket in self.getStreams(1):
            yield bucket.key(), bucket.value()

    def __getitem__(self, key):
        for bucket in self.getStreams(1):
            if bucket.key() == key:
                return bucket.value()

        raise KeyError

    def __setitem__(self, key, value):
        for bucket in self.getStreams(1):
            if bucket.key() == key:
                bucket.value.set(value)
                return

        self.add(key, value)

    def compatibleWith(self, other):
        if not other.keys() or not self.keys():
            return False

        otherDict = dict(other)

        for key, value in self.iteritems():
            if otherDict.get(key, value) == value:
                return False
            del otherDict[key]

        if otherDict:
            return False

        return True

_DIGSIG_FINGERPRINT   = 0
_DIGSIG_SIGNATURE     = 1
_DIGSIG_TIMESTAMP     = 2

class DigitalSignature(streams.StreamSet):
    streamDict = {
        _DIGSIG_FINGERPRINT     : ( streams.StringStream,    'fingerprint' ),
        _DIGSIG_SIGNATURE       : ( streams.StringStream,    'signature'   ),
        _DIGSIG_TIMESTAMP       : ( streams.IntStream,       'timestamp'   ),
    }
    _streamDict = streams.StreamSetDef(streamDict)

    def _mpiToLong(self, data):<commit_msg>added InstallBucket.intersect()<commit_after>#
# Copyright (c) 2004-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.
#
"""
Implements troves (packages, components, etc.) for the repository
"""

import changelog
import copy
import files
from lib import sha1helper
from lib.openpgpkey import getKeyCache
from lib.openpgpfile import KeyNotFound
import streams
import struct
import versions
from deps import deps
from changelog import ChangeLog
from streams import FrozenVersionStream
from streams import StringVersionStream
from streams import DependenciesStream
from streams import ByteStream

class TroveTuple(streams.StreamSet):
    _SINGLE_TROVE_TUP_NAME    = 0
    _SINGLE_TROVE_TUP_VERSION = 1
    _SINGLE_TROVE_TUP_FLAVOR  = 2

    ignoreUnknown = True
    streamDict = {
        _SINGLE_TROVE_TUP_NAME    : (streams.StringStream,        'name'    ),
        _SINGLE_TROVE_TUP_VERSION : (streams.StringVersionStream, 'version' ),
        _SINGLE_TROVE_TUP_FLAVOR  : (streams.DependenciesStream,  'flavor'  )
    }
    _streamDict = streams.StreamSetDef(streamDict)

    def __hash__(self):
        return hash((self.name(), self.version(), self.flavor()))

class TroveTupleList(streams.StreamCollection):
    streamDict = { 1 : TroveTuple }

    def add(self, name, version, flavor):
        dep = TroveTuple()
        dep.name.set(name)
        dep.version.set(version)
        dep.flavor.set(flavor)
        self.addStream(1, dep)

    def iter(self):
        return self.iterAll()

class BuildDependencies(TroveTupleList):
    pass

class LoadedTroves(TroveTupleList):
    pass

class InstallBucketItem(streams.StreamSet):
    _INSTALL_BIN_KEY  = 0
    _INSTALL_BIN_VALUE = 1

    ignoreUnknown = True
    streamDict = {
        _INSTALL_BIN_KEY    : (streams.StringStream,        'key'    ),
        _INSTALL_BIN_VALUE  : (streams.StringStream,        'value'  ),
    }
    _streamDict = streams.StreamSetDef(streamDict)


class InstallBucket(streams.StreamCollection):
    streamDict = { 1 : InstallBucketItem }

    # XXX these aren't particularly efficient; they imitate a dict with a list

    def add(self, key, value):
        item = InstallBucketItem()
        item.key.set(key)
        item.value.set(value)
        self.addStream(1, item)

    def keys(self):
        return [ x for x in self.iterkeys() ]

    def __iter__(self):
        return self.iterkeys()

    def iterkeys(self):
        for bucket in self.getStreams(1):
            yield bucket.key()

    def values(self):
        return [ x for x in self.itervalues() ]

    def itervalues(self):
        for bucket in self.getStreams(1):
            yield bucket.value()

    def items(self):
        return [ x for x in self.iteritems() ]

    def iteritems(self):
        for bucket in self.getStreams(1):
            yield bucket.key(), bucket.value()

    def __getitem__(self, key):
        for bucket in self.getStreams(1):
            if bucket.key() == key:
                return bucket.value()

        raise KeyError

    def __setitem__(self, key, value):
        for bucket in self.getStreams(1):
            if bucket.key() == key:
                bucket.value.set(value)
                return

        self.add(key, value)

    def compatibleWith(self, other):
        if not other.keys() or not self.keys():
            return False

        otherDict = dict(other)

        for key, value in self.iteritems():
            if otherDict.get(key, value) == value:
                return False
            del otherDict[key]

        if otherDict:
            return False

        return True

    def intersect(self, other):
        new = InstallBucket()
        otherDict = dict(other)

        for key, value in self.iteritems():
            if otherDict.get(key, value) == value:
                new.add(key, value)

        return new

    def __str__(self):
        return ', '.join('='.join(x) for x in self.iteritems())

_DIGSIG_FINGERPRINT   = 0
_DIGSIG_SIGNATURE     = 1
_DIGSIG_TIMESTAMP     = 2

class DigitalSignature(streams.StreamSet):
    streamDict = {
        _DIGSIG_FINGERPRINT     : ( streams.StringStream,    'fingerprint' ),
        _DIGSIG_SIGNATURE       : ( streams.StringStream,    'signature'   ),
        _DIGSIG_TIMESTAMP       : ( streams.IntStream,       'timestamp'   ),
    }
    _streamDict = streams.StreamSetDef(streamDict)

    def _mpiToLong(self, data):
{'fraction_non_alphanumeric': 0.08751458576429405, 'fraction_numerical': 0.005940384003394505, 'mean_word_length': 2.6191938579654512, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '151889', 'n_tokens_mistral': 2888, 'n_tokens_neox': 2759, 'n_words': 786}