<commit_before>#
# Copyright (c) 2008 rPath, Inc.
#
# All Rights Reserved
#

import os

from mint import helperfuncs
from mint import shimclient
from mint import mint_error

from conary.lib import util

def setupRmake(cfg, rmakeConfigFilePath, restartRmake=False):
    # Create a product (as the admin user) for use by the internal rmake.
    adminClient = shimclient.ShimMintClient(cfg,
        [cfg.authUser, cfg.authPass])

    shortName = 'rmake-repository'

    # ensure the rMake repository doesn't exist by attempting to reference it
    try:
        adminClient.getProjectByHostname('rmake-repository')
    except mint_error.ItemNotFound:
        pass
    else:
        raise mint_error.RmakeRepositoryExistsError()

    projectId = adminClient.newProject(name="rMake Repository",
        hostname=shortName,
        domainname=str(cfg.projectDomainName),
        projecturl="",
        desc="Please consider the contents of this product's repository to be for REFERENCE PURPOSES ONLY.\nThis product's repository is used by the rMake server running on this rBuilder for building packages and groups with Package Creator and Appliance Creator. This product is for the internal use of the rBuilder server. Do not attempt to manipulate the contents of this repository. Do not shadow, clone or otherwise reference any packages or components from this repository. This product can be reset at any time, which would lead to errors in anything that references the contents of this product's repository.",
        appliance="no",
        shortname=shortName,
        namespace="rpath",
        prodtype="Component",
        version="1",
        commitEmail="",
        isPrivate=True,
        projectLabel="")

    rmakeUser = "%s-user" % shortName
    rmakePassword = helperfuncs.genPassword(32)
    adminClient.addProjectRepositoryUser(projectId, rmakeUser,
        rmakePassword)

    _writeRmakeConfig(rmakeConfigFilePath, rmakeUser, rmakePassword,
        "https://%s" % cfg.siteHost,
        "%s.%s" % (shortName, cfg.projectDomainName),
        "https://%s/repos/%s" % (cfg.siteHost, shortName))

    if restartRmake:
        if os.getenv('RBUILDER_NOSUDO'):
            sudo = ''
        else:
            sudo = 'sudo '

        os.system("%s/sbin/service rmake restart" % sudo)
        os.system("%s/sbin/service rmake-node restart" % sudo)


def _writeRmakeConfig(path, user, password, rBuilderUrl, reposName, reposUrl):
    util.mkdirChain(os.path.dirname(path))
    f = file(path, 'w')<commit_msg>Configure rMake to use localhost for repository/auth. (RBL-4899)<commit_after>#
# Copyright (c) 2008 rPath, Inc.
#
# All Rights Reserved
#

import os

from mint import helperfuncs
from mint import shimclient
from mint import mint_error

from conary.lib import util

def setupRmake(cfg, rmakeConfigFilePath, restartRmake=False):
    # Create a product (as the admin user) for use by the internal rmake.
    adminClient = shimclient.ShimMintClient(cfg,
        [cfg.authUser, cfg.authPass])

    shortName = 'rmake-repository'

    # ensure the rMake repository doesn't exist by attempting to reference it
    try:
        adminClient.getProjectByHostname('rmake-repository')
    except mint_error.ItemNotFound:
        pass
    else:
        raise mint_error.RmakeRepositoryExistsError()

    projectId = adminClient.newProject(name="rMake Repository",
        hostname=shortName,
        domainname=str(cfg.projectDomainName),
        projecturl="",
        desc="Please consider the contents of this product's repository to be for REFERENCE PURPOSES ONLY.\nThis product's repository is used by the rMake server running on this rBuilder for building packages and groups with Package Creator and Appliance Creator. This product is for the internal use of the rBuilder server. Do not attempt to manipulate the contents of this repository. Do not shadow, clone or otherwise reference any packages or components from this repository. This product can be reset at any time, which would lead to errors in anything that references the contents of this product's repository.",
        appliance="no",
        shortname=shortName,
        namespace="rpath",
        prodtype="Component",
        version="1",
        commitEmail="",
        isPrivate=True,
        projectLabel="")

    rmakeUser = "%s-user" % shortName
    rmakePassword = helperfuncs.genPassword(32)
    adminClient.addProjectRepositoryUser(projectId, rmakeUser,
        rmakePassword)

    _writeRmakeConfig(rmakeConfigFilePath, rmakeUser, rmakePassword,
        "https://localhost",
        "%s.%s" % (shortName, cfg.projectDomainName),
        "https://localhost/repos/%s" % (shortName,))

    if restartRmake:
        if os.getenv('RBUILDER_NOSUDO'):
            sudo = ''
        else:
            sudo = 'sudo '

        os.system("%s/sbin/service rmake restart" % sudo)
        os.system("%s/sbin/service rmake-node restart" % sudo)


def _writeRmakeConfig(path, user, password, rBuilderUrl, reposName, reposUrl):
    util.mkdirChain(os.path.dirname(path))
    f = file(path, 'w')
{'fraction_non_alphanumeric': 0.08779909036978446, 'fraction_numerical': 0.0035594225825588293, 'mean_word_length': 3.3528399311531842, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '875658', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1385, 'n_words': 452}