<commit_before>import os
import sys
import shutil
import re
import logging
from collections import defaultdict
from StringIO import StringIO
from subprocess import Popen
from subprocess import PIPE
from cloudfoundry import CloudFoundryUtil
from cloudfoundry import CloudFoundryInstaller
from detecter import TextFileSearch
from detecter import ComposerJsonSearch
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
from detecter import ContainsFileSearch
from runner import BuildPack
from utils import rewrite_cfgs
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
from detecter import ContainsFileSearch
from runner import BuildPack
from utils import rewrite_cfgs
from utils import process_extension
from utils import process_extensions


_log = logging.getLogger('builder')


def log_output(cmd, retcode, stdout, stderr):
    _log.info('Comand %s completed with [%d]', str(cmd), retcode)
    if stdout:
        _log.debug('STDOUT: %s', stdout)
    if stderr:
        _log.error('STDERR: %s', stderr)
    if retcode != 0:
        raise RuntimeError('Script Failure')


class Configurer(object):
    def __init__(self, builder):
        self.builder = builder

    def default_config(self):
        self._merge(
            CloudFoundryUtil.load_json_config_file_from(
                self.builder._ctx['BP_DIR'],
                'defaults/options.json'))
        return self

    def stack_config(self):
        stack = os.environ.get('CF_STACK', None)
        if stack:
            self._merge(
                CloudFoundryUtil.load_json_config_file_from(
                    self.builder._ctx['BP_DIR'],
                    'defaults/%s/options.json' % stack))
        return self

    def user_config(self, path=None, step=None):
        if path is None:
            path = os.path.join('.bp-config', 'options.json')
        dict = CloudFoundryUtil.load_json_config_file_from(self.builder._ctx['BUILD_DIR'], path, step)
        if len(dict.get('PHP_EXTENSIONS', [])) > 0:
            self._merge({'OPTIONS_JSON_HAS_PHP_EXTENSIONS': True})
        self._merge(dict)
        return self

    def validate(self):
        web_server = self.builder._ctx['WEB_SERVER']
        if web_server != 'none' and web_server != 'nginx' and web_server != 'httpd':
            sys.stderr.write("{0} isn't a supported web server. Supported web servers are 'httpd' & 'nginx'\n".format(web_server))
            sys.exit(1)
        return self

    def done(self):
        return self.builder

    def _merge(self, ctx):
        self.builder._ctx.update(ctx)
<commit_msg>Look for V3 sentinal file in stager construction and panic if found<commit_after>import os
import sys
import shutil
import re
import logging
from collections import defaultdict
from StringIO import StringIO
from subprocess import Popen
from subprocess import PIPE
from cloudfoundry import CloudFoundryUtil
from cloudfoundry import CloudFoundryInstaller
from detecter import TextFileSearch
from detecter import ComposerJsonSearch
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
from detecter import ContainsFileSearch
from runner import BuildPack
from utils import rewrite_cfgs
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
from detecter import ContainsFileSearch
from runner import BuildPack
from utils import rewrite_cfgs
from utils import process_extension
from utils import process_extensions


_log = logging.getLogger('builder')


def log_output(cmd, retcode, stdout, stderr):
    _log.info('Comand %s completed with [%d]', str(cmd), retcode)
    if stdout:
        _log.debug('STDOUT: %s', stdout)
    if stderr:
        _log.error('STDERR: %s', stderr)
    if retcode != 0:
        raise RuntimeError('Script Failure')


class Configurer(object):
    def __init__(self, builder):
        self.builder = builder

    def default_config(self):
        self._merge(
            CloudFoundryUtil.load_json_config_file_from(
                self.builder._ctx['BP_DIR'],
                'defaults/options.json'))
        return self

    def stack_config(self):
        stack = os.environ.get('CF_STACK', None)
        if stack:
            self._merge(
                CloudFoundryUtil.load_json_config_file_from(
                    self.builder._ctx['BP_DIR'],
                    'defaults/%s/options.json' % stack))
        return self

    def user_config(self, path=None, step=None):
        if path is None:
            path = os.path.join('.bp-config', 'options.json')
        dict = CloudFoundryUtil.load_json_config_file_from(self.builder._ctx['BUILD_DIR'], path, step)
        if len(dict.get('PHP_EXTENSIONS', [])) > 0:
            self._merge({'OPTIONS_JSON_HAS_PHP_EXTENSIONS': True})
        self._merge(dict)
        return self

    def validate(self):
        if os.path.isfile((os.path.join(self.builder._ctx['BUILD_DIR'], '.cloudfoundry', 'sentinal'))):
            raise Exception('ERROR: You are running a V2 buildpack after a V3 buildpack. This is unsupported.')

        web_server = self.builder._ctx['WEB_SERVER']
        if web_server != 'none' and web_server != 'nginx' and web_server != 'httpd':
            sys.stderr.write("{0} isn't a supported web server. Supported web servers are 'httpd' & 'nginx'\n".format(web_server))
            sys.exit(1)
        return self

    def done(self):
        return self.builder

    def _merge(self, ctx):
        self.builder._ctx.update(ctx)

{'fraction_non_alphanumeric': 0.08617943726774022, 'fraction_numerical': 0.001946558131304194, 'mean_word_length': 3.208488458674609, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3722104', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1613, 'n_words': 462}