<commit_before>#
# Copyright (c) 2004-2005 Specifix, 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 datastore
from callbacks import UpdateCallback
from repository import changeset
import errno
from repository import filecontents
from repository import filecontainer
from lib import log
import localrep
import os
from repository import repository
import shutil
import sqldb
import trove
import update
from lib import util
import versions
from build import tags
from deps import deps

OldDatabaseSchema = sqldb.OldDatabaseSchema

class Rollback:

    reposName = "%s/repos.%d"
    localName = "%s/local.%d"

    def addRollback(self, repos, local):
        repos.writeToFile(self.reposName % (self.dir, self.count))
        local.writeToFile(self.localName % (self.dir, self.count))
        self.count += 1
        open("%s/count" % self.dir, "w").write("%d\n" % self.count)

    def _getChangeSets(self, item):
        repos = changeset.ChangeSetFromFile(self.reposName % (self.dir, item))
        local = changeset.ChangeSetFromFile(self.localName % (self.dir, item))
        return (repos, local)

    def getLast(self):
        if not self.count:
            return (None, None)
        return self._getChangeSets(self.count - 1)

    def removeLast(self):
        os.unlink(self.reposName % (self.dir, self.count - 1))
        os.unlink(self.localName % (self.dir, self.count - 1))
        self.count -= 1
        open("%s/count" % self.dir, "w").write("%d\n" % self.count)

    def iterChangeSets(self):
        for i in range(self.count):
            csList = self._getChangeSets(i)
            yield csList[0]
            yield csList[1]

    def __init__(self, dir, load = False):
        self.dir = dir

        if load:
            self.stored = True
            self.count = int(open("%s/count" % self.dir).readline()[:-1])
        else:
            self.stored = False
            self.count = 0

class UpdateJob:

    def addChangeSet(self, cs):
        self.csList.append(cs)

    def getChangeSets(self):
        return self.csList

    def addLockMapping(self, name, lockedVersion, neededVersion):
        self.lockMapping.add((name, lockedVersion, neededVersion))
    
    def getLockMaps(self):
        return self.lockMapping

    def getRollback(self):
        return self.rollback

    def setRollback(self, rollback):
        self.rollback = rollback

    def __init__(self):
        self.csList = []
        self.lockMapping = set()
        self.rollback = None

class SqlDbRepository(datastore.DataStoreRepository,
		      repository.AbstractRepository):

    def iterAllTroveNames(self):
	return self.db.iterAllTroveNames()

    def findByNames(self, nameList):
        return self.db.nameList

    def getTroveContainers(self, l):
        return self.db.getTroveContainers(l)

    def findTroveContainers(self, names):
        return self.db.findTroveContainers(names)

    def getTrove(self, name, version, flavor, pristine = True):
	l = [ x for x in self.db.iterFindByName(name, pristine = pristine)
		 if version == x.getVersion() and flavor == x.getFlavor()]
	if not l:
	    raise repository.TroveMissing(name, version)
	assert(len(l) == 1)
	return l[0]

    def getTroves(self, troveList, pristine = True):
        return self.db.getTroves(troveList, pristine)<commit_msg>fixed findByNames to do somethign<commit_after>#
# Copyright (c) 2004-2005 Specifix, 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 datastore
from callbacks import UpdateCallback
from repository import changeset
import errno
from repository import filecontents
from repository import filecontainer
from lib import log
import localrep
import os
from repository import repository
import shutil
import sqldb
import trove
import update
from lib import util
import versions
from build import tags
from deps import deps

OldDatabaseSchema = sqldb.OldDatabaseSchema

class Rollback:

    reposName = "%s/repos.%d"
    localName = "%s/local.%d"

    def addRollback(self, repos, local):
        repos.writeToFile(self.reposName % (self.dir, self.count))
        local.writeToFile(self.localName % (self.dir, self.count))
        self.count += 1
        open("%s/count" % self.dir, "w").write("%d\n" % self.count)

    def _getChangeSets(self, item):
        repos = changeset.ChangeSetFromFile(self.reposName % (self.dir, item))
        local = changeset.ChangeSetFromFile(self.localName % (self.dir, item))
        return (repos, local)

    def getLast(self):
        if not self.count:
            return (None, None)
        return self._getChangeSets(self.count - 1)

    def removeLast(self):
        os.unlink(self.reposName % (self.dir, self.count - 1))
        os.unlink(self.localName % (self.dir, self.count - 1))
        self.count -= 1
        open("%s/count" % self.dir, "w").write("%d\n" % self.count)

    def iterChangeSets(self):
        for i in range(self.count):
            csList = self._getChangeSets(i)
            yield csList[0]
            yield csList[1]

    def __init__(self, dir, load = False):
        self.dir = dir

        if load:
            self.stored = True
            self.count = int(open("%s/count" % self.dir).readline()[:-1])
        else:
            self.stored = False
            self.count = 0

class UpdateJob:

    def addChangeSet(self, cs):
        self.csList.append(cs)

    def getChangeSets(self):
        return self.csList

    def addLockMapping(self, name, lockedVersion, neededVersion):
        self.lockMapping.add((name, lockedVersion, neededVersion))
    
    def getLockMaps(self):
        return self.lockMapping

    def getRollback(self):
        return self.rollback

    def setRollback(self, rollback):
        self.rollback = rollback

    def __init__(self):
        self.csList = []
        self.lockMapping = set()
        self.rollback = None

class SqlDbRepository(datastore.DataStoreRepository,
		      repository.AbstractRepository):

    def iterAllTroveNames(self):
	return self.db.iterAllTroveNames()

    def findByNames(self, nameList):
        return self.db.findByNames(nameList)

    def getTroveContainers(self, l):
        return self.db.getTroveContainers(l)

    def findTroveContainers(self, names):
        return self.db.findTroveContainers(names)

    def getTrove(self, name, version, flavor, pristine = True):
	l = [ x for x in self.db.iterFindByName(name, pristine = pristine)
		 if version == x.getVersion() and flavor == x.getFlavor()]
	if not l:
	    raise repository.TroveMissing(name, version)
	assert(len(l) == 1)
	return l[0]

    def getTroves(self, troveList, pristine = True):
        return self.db.getTroves(troveList, pristine)
{'fraction_non_alphanumeric': 0.10022242574905142, 'fraction_numerical': 0.00549522438832919, 'mean_word_length': 2.9750390015600625, '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': '870200', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2260, 'n_words': 675}