<commit_before>#
# Copyright (c) 2006-2007 rPath, Inc.  All Rights Reserved.
#
import sys
import time

from conary.build import recipe
from conary.conaryclient import cmdline
from conary.deps import deps
from conary.repository import changeset
from conary import trove

from rmake import failure
from rmake.build import publisher
from rmake.lib import apiutils
from rmake.lib.apiutils import freeze, thaw
from rmake.lib import flavorutil

troveStates = {
    'TROVE_STATE_INIT'        : 0,
    'TROVE_STATE_FAILED'      : 1,
    'TROVE_STATE_RESOLVING'   : 2,
    'TROVE_STATE_BUILDABLE'   : 3,
    'TROVE_STATE_WAITING'     : 4,
    'TROVE_STATE_PREPARING'   : 5,
    'TROVE_STATE_BUILDING'    : 6,
    'TROVE_STATE_BUILT'       : 7,
    'TROVE_STATE_UNBUILDABLE' : 8,
    'TROVE_STATE_PREBUILT'    : 9,
}

recipeTypes = {
    'RECIPE_TYPE_UNKNOWN'      : 0,
    'RECIPE_TYPE_PACKAGE'      : 1,
    'RECIPE_TYPE_FILESET'      : 2,
    'RECIPE_TYPE_GROUP'        : 3,
    'RECIPE_TYPE_INFO'         : 4,
    'RECIPE_TYPE_REDIRECT'     : 5,
}


# assign troveStates to this module's dict so that they can be referenced with
# module 'getattribute' notation (eg; buildtrove.TROVE_STATE_INIT)
sys.modules[__name__].__dict__.update(troveStates)
sys.modules[__name__].__dict__.update(recipeTypes)

stateNames = dict([(x[1], x[0].rsplit('_', 1)[-1].capitalize()) \
                   for x in troveStates.iteritems()])
recipeTypeNames = dict([(x[1], x[0].rsplit('_', 1)[-1].capitalize()) \
                       for x in recipeTypes.iteritems()])


stateNames.update({
    TROVE_STATE_INIT      : 'Initialized',
    TROVE_STATE_PREPARING : 'Creating Chroot',
    TROVE_STATE_WAITING   : 'Queued',
})

def _getStateName(state):
    return stateNames[state]

def _getRecipeTypeName(recipeType):
    return recipeTypeNames[recipeType]

def getRecipeType(recipeClass):
    if recipe.isPackageRecipe(recipeClass):
        return RECIPE_TYPE_PACKAGE
    if recipe.isGroupRecipe(recipeClass):
        return RECIPE_TYPE_GROUP
    if recipe.isInfoRecipe(recipeClass):
        return RECIPE_TYPE_INFO
    if recipe.isRedirectRecipe(recipeClass):
        return RECIPE_TYPE_REDIRECT
    if recipe.isFilesetRecipe(recipeClass):
        return RECIPE_TYPE_FILESET
    return RECIPE_TYPE_UNKNOWN

TROVE_STATE_LIST = sorted(troveStates.values())


class _AbstractBuildTrove:
    """
        Base class for the trove object.
    """

    def __init__(self, jobId, name, version, flavor,
                 state=TROVE_STATE_INIT, status='',
                 failureReason=None, logPath='', start=0, finish=0,
                 pid=0, recipeType=RECIPE_TYPE_PACKAGE,
                 chrootHost='', chrootPath='', 
                 preBuiltRequirements=None, preBuiltBinaries=None,
                 context='', flavorList=None):
        assert(name.endswith(':source'))
        self.jobId = jobId
        self.name = name
        self.version = version
        self.flavor = flavor
        assert(isinstance(flavor, deps.Flavor))
        self.buildRequirements = set()
        self.delayedRequirements = set()
        self.crossRequirements = set()
        self.builtTroves = set()
        self.loadedSpecsList = [{}]
        self.packages = set([name.split(':')[0]])
        self.state = state
        self.status = status
        self.logPath = logPath
        self.start = start
        self.finish = finish
        self.failureReason = failureReason
        self.pid = pid
        self.chrootHost = chrootHost
        self.chrootPath = chrootPath
        self.recipeType = recipeType
        self.preBuiltRequirements = None
        self.preBuiltBinaries = preBuiltBinaries
        self.context = context
        if flavorList is None:
            self.flavorList = [flavor]

    def __repr__(self):
        if self.getContext():
            context = '{%s}' % self.getContext()
        else:
            context = ''
        return "<BuildTrove('%s=%s[%s]%s')>" % (self.getName(),
                                          self.getVersion().trailingLabel(),
                                          self.getFlavor(), context)

    def getName(self):
        return self.name

    def getVersion(self):
        return self.version

    def getFlavor(self):
        return self.flavor

    def getFullFlavor(self):
        return deps.overrideFlavor(self.flavor, self.cfg.buildFlavor)

    def getFlavorList(self):<commit_msg>fix reversed argument orders in getFullFlavor<commit_after>#
# Copyright (c) 2006-2007 rPath, Inc.  All Rights Reserved.
#
import sys
import time

from conary.build import recipe
from conary.conaryclient import cmdline
from conary.deps import deps
from conary.repository import changeset
from conary import trove

from rmake import failure
from rmake.build import publisher
from rmake.lib import apiutils
from rmake.lib.apiutils import freeze, thaw
from rmake.lib import flavorutil

troveStates = {
    'TROVE_STATE_INIT'        : 0,
    'TROVE_STATE_FAILED'      : 1,
    'TROVE_STATE_RESOLVING'   : 2,
    'TROVE_STATE_BUILDABLE'   : 3,
    'TROVE_STATE_WAITING'     : 4,
    'TROVE_STATE_PREPARING'   : 5,
    'TROVE_STATE_BUILDING'    : 6,
    'TROVE_STATE_BUILT'       : 7,
    'TROVE_STATE_UNBUILDABLE' : 8,
    'TROVE_STATE_PREBUILT'    : 9,
}

recipeTypes = {
    'RECIPE_TYPE_UNKNOWN'      : 0,
    'RECIPE_TYPE_PACKAGE'      : 1,
    'RECIPE_TYPE_FILESET'      : 2,
    'RECIPE_TYPE_GROUP'        : 3,
    'RECIPE_TYPE_INFO'         : 4,
    'RECIPE_TYPE_REDIRECT'     : 5,
}


# assign troveStates to this module's dict so that they can be referenced with
# module 'getattribute' notation (eg; buildtrove.TROVE_STATE_INIT)
sys.modules[__name__].__dict__.update(troveStates)
sys.modules[__name__].__dict__.update(recipeTypes)

stateNames = dict([(x[1], x[0].rsplit('_', 1)[-1].capitalize()) \
                   for x in troveStates.iteritems()])
recipeTypeNames = dict([(x[1], x[0].rsplit('_', 1)[-1].capitalize()) \
                       for x in recipeTypes.iteritems()])


stateNames.update({
    TROVE_STATE_INIT      : 'Initialized',
    TROVE_STATE_PREPARING : 'Creating Chroot',
    TROVE_STATE_WAITING   : 'Queued',
})

def _getStateName(state):
    return stateNames[state]

def _getRecipeTypeName(recipeType):
    return recipeTypeNames[recipeType]

def getRecipeType(recipeClass):
    if recipe.isPackageRecipe(recipeClass):
        return RECIPE_TYPE_PACKAGE
    if recipe.isGroupRecipe(recipeClass):
        return RECIPE_TYPE_GROUP
    if recipe.isInfoRecipe(recipeClass):
        return RECIPE_TYPE_INFO
    if recipe.isRedirectRecipe(recipeClass):
        return RECIPE_TYPE_REDIRECT
    if recipe.isFilesetRecipe(recipeClass):
        return RECIPE_TYPE_FILESET
    return RECIPE_TYPE_UNKNOWN

TROVE_STATE_LIST = sorted(troveStates.values())


class _AbstractBuildTrove:
    """
        Base class for the trove object.
    """

    def __init__(self, jobId, name, version, flavor,
                 state=TROVE_STATE_INIT, status='',
                 failureReason=None, logPath='', start=0, finish=0,
                 pid=0, recipeType=RECIPE_TYPE_PACKAGE,
                 chrootHost='', chrootPath='', 
                 preBuiltRequirements=None, preBuiltBinaries=None,
                 context='', flavorList=None):
        assert(name.endswith(':source'))
        self.jobId = jobId
        self.name = name
        self.version = version
        self.flavor = flavor
        assert(isinstance(flavor, deps.Flavor))
        self.buildRequirements = set()
        self.delayedRequirements = set()
        self.crossRequirements = set()
        self.builtTroves = set()
        self.loadedSpecsList = [{}]
        self.packages = set([name.split(':')[0]])
        self.state = state
        self.status = status
        self.logPath = logPath
        self.start = start
        self.finish = finish
        self.failureReason = failureReason
        self.pid = pid
        self.chrootHost = chrootHost
        self.chrootPath = chrootPath
        self.recipeType = recipeType
        self.preBuiltRequirements = None
        self.preBuiltBinaries = preBuiltBinaries
        self.context = context
        if flavorList is None:
            self.flavorList = [flavor]

    def __repr__(self):
        if self.getContext():
            context = '{%s}' % self.getContext()
        else:
            context = ''
        return "<BuildTrove('%s=%s[%s]%s')>" % (self.getName(),
                                          self.getVersion().trailingLabel(),
                                          self.getFlavor(), context)

    def getName(self):
        return self.name

    def getVersion(self):
        return self.version

    def getFlavor(self):
        return self.flavor

    def getFullFlavor(self):
        return deps.overrideFlavor(self.cfg.buildFlavor, self.flavor)

    def getFlavorList(self):
{'fraction_non_alphanumeric': 0.1013116236996834, 'fraction_numerical': 0.008141112618724558, 'mean_word_length': 2.546511627906977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089128', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2762, 'n_words': 568}