<commit_before>#
# Copyright (c) 2004-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.
#

import os
import itertools

from conary import files, metadata, trove, versions, changelog, callbacks
from conary.deps import deps
from conary.lib import util, tracelog
from conary.local import deptable
from conary.local.sqldb import VersionCache, FlavorCache
from conary.local import versiontable
from conary.repository import errors
from conary.repository.netrepos import instances, items, keytable, flavors,\
     troveinfo, versionops, cltable, accessmap
from conary.server import schema


class LocalRepVersionTable(versiontable.VersionTable):

    def getId(self, theId, itemId):
        cu = self.db.cursor()
        cu.execute("""
        SELECT Versions.version, Nodes.timeStamps
        FROM Nodes
        JOIN Versions USING (versionId)
        WHERE Nodes.versionId=? AND Nodes.itemId=?
        """, theId, itemId)
	try:
	    (s, t) = cu.next()
	    v = self._makeVersion(s, t)
	    return v
	except StopIteration:
            raise KeyError, theId

    def getTimeStamps(self, version, itemId):
        cu = self.db.cursor()
        cu.execute("""
        SELECT timeStamps
        FROM Nodes
        WHERE versionId = (SELECT versionId from Versions WHERE version=?)
          AND itemId=?""", version.asString(), itemId)
	try:
	    (t,) = cu.next()
	    return [ float(x) for x in t.split(":") ]
	except StopIteration:
            raise KeyError, itemId

class TroveAdder:

    def addStream(self, fileId, fileStream = None, withContents = True):
        existing = self.newStreamsByFileId.get(fileId)
        if existing and existing[1]:
            # we have the stream for this fileId already. we don't need
            # it again
            return

        if fileStream and withContents:
            sha1 = None

            if (not files.frozenFileFlags(fileStream).isPayload() and
                        files.frozenFileHasContents(fileStream)):
                cont = files.frozenFileContentInfo(fileStream)
                sha1 = cont.sha1()
        else:
            sha1 = None

        if fileId == '7\xe7\x99\x07\xbc1\xc4\x04Ju\xc1Zj\xd7\x86\x18\x9dz\xaf\xb6':
            import epdb;epdb.st()

        self.newStreamsByFileId[fileId] = (self.cu.binary(fileId),
                                           self.cu.binary(fileStream),
                                           self.cu.binary(sha1))

    def addFile(self, pathId, path, fileId, fileVersion,
                fileStream = None, withContents = True):
        dirname, basename = os.path.split(path)

        pathChanged = 1

        versionId = self.troveStore.getVersionId(fileVersion)

        self.newFilesInsertList.append((self.cu.binary(pathId), versionId,
                                        self.cu.binary(fileId),
                                        self.dirMap[dirname],
                                        self.baseMap[basename],
                                        pathChanged))

        changeInfo = self.changeMap.get(pathId, None)
        if changeInfo:
            if not changeInfo[1]:
                pathChanged = 0
            if not changeInfo[3]:
                versionChanged = False
            else:
                versionChanged = True
        else:<commit_msg>Removing epdb break point<commit_after>#
# Copyright (c) 2004-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.
#

import os
import itertools

from conary import files, metadata, trove, versions, changelog, callbacks
from conary.deps import deps
from conary.lib import util, tracelog
from conary.local import deptable
from conary.local.sqldb import VersionCache, FlavorCache
from conary.local import versiontable
from conary.repository import errors
from conary.repository.netrepos import instances, items, keytable, flavors,\
     troveinfo, versionops, cltable, accessmap
from conary.server import schema


class LocalRepVersionTable(versiontable.VersionTable):

    def getId(self, theId, itemId):
        cu = self.db.cursor()
        cu.execute("""
        SELECT Versions.version, Nodes.timeStamps
        FROM Nodes
        JOIN Versions USING (versionId)
        WHERE Nodes.versionId=? AND Nodes.itemId=?
        """, theId, itemId)
	try:
	    (s, t) = cu.next()
	    v = self._makeVersion(s, t)
	    return v
	except StopIteration:
            raise KeyError, theId

    def getTimeStamps(self, version, itemId):
        cu = self.db.cursor()
        cu.execute("""
        SELECT timeStamps
        FROM Nodes
        WHERE versionId = (SELECT versionId from Versions WHERE version=?)
          AND itemId=?""", version.asString(), itemId)
	try:
	    (t,) = cu.next()
	    return [ float(x) for x in t.split(":") ]
	except StopIteration:
            raise KeyError, itemId

class TroveAdder:

    def addStream(self, fileId, fileStream = None, withContents = True):
        existing = self.newStreamsByFileId.get(fileId)
        if existing and existing[1]:
            # we have the stream for this fileId already. we don't need
            # it again
            return

        if fileStream and withContents:
            sha1 = None

            if (not files.frozenFileFlags(fileStream).isPayload() and
                        files.frozenFileHasContents(fileStream)):
                cont = files.frozenFileContentInfo(fileStream)
                sha1 = cont.sha1()
        else:
            sha1 = None

        self.newStreamsByFileId[fileId] = (self.cu.binary(fileId),
                                           self.cu.binary(fileStream),
                                           self.cu.binary(sha1))

    def addFile(self, pathId, path, fileId, fileVersion,
                fileStream = None, withContents = True):
        dirname, basename = os.path.split(path)

        pathChanged = 1

        versionId = self.troveStore.getVersionId(fileVersion)

        self.newFilesInsertList.append((self.cu.binary(pathId), versionId,
                                        self.cu.binary(fileId),
                                        self.dirMap[dirname],
                                        self.baseMap[basename],
                                        pathChanged))

        changeInfo = self.changeMap.get(pathId, None)
        if changeInfo:
            if not changeInfo[1]:
                pathChanged = 0
            if not changeInfo[3]:
                versionChanged = False
            else:
                versionChanged = True
        else:
{'fraction_non_alphanumeric': 0.08281020435421398, 'fraction_numerical': 0.008281020435421397, 'mean_word_length': 2.0954940057875153, 'pattern_counts': {'":': 2, '<': 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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '118352', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2011, 'n_words': 625}