<commit_before>import os
from buildbot import locks
from buildbot.steps.shell import ShellCommand
from buildbot.steps.shell import SetProperty
from buildbot.steps.transfer import FileDownload
from buildbot.steps.transfer import DirectoryUpload
from buildbot.steps.master import MasterShellCommand
from buildbot.process.properties import WithProperties
from buildbot.process.properties import Property
from ..utils import comma_list_sanitize
from ..utils import bool_opt
from ..utils import BUILD_UTILS_PATH


def install_modules_test_openerp(configurator, options, buildout_slave_path,
                                 environ=()):
    """Return steps to run bin/test_openerp -i MODULES."""

    environ = dict(environ)

    steps = []

    steps.append(ShellCommand(command=['rm', '-f', 'test.log'],
                              name="Log cleanup",
                              descriptionDone=['Cleaned', 'logs'],
                              ))

    steps.append(ShellCommand(command=[
        'bin/test_openerp', '-i',
        comma_list_sanitize(options.get('openerp-addons', 'all')),
        # openerp --logfile does not work with relative paths !
        WithProperties('--logfile=%(workdir)s/build/test.log')],
        name='testing',
        description='testing',
        descriptionDone='tests',
        logfiles=dict(test='test.log'),
        haltOnFailure=True,
        env=environ,
    ))

    steps.append(ShellCommand(
        command=["python", "analyze_oerp_tests.py", "test.log"],
        name='analyze',
        description="analyze",
    ))

    return steps


def update_modules(configurator, options, buildout_slave_path,
                   environ=()):
    """Return steps to update the OpenERP application.

    If the option "update.script" is specified, that script is used, and the
    general module list is ignored.
    Otherwise, a raw ``bin/start_openerp -u`` on the declared module list gets
    issued.

    Options:

    ``update.script``: see above.
    ``update.log_file_option``: name of the option to use for dedicated script
                                if there is one.
    """

    environ = dict(environ)

    steps = []

    steps.append(ShellCommand(command=['rm', '-f', 'update.log'],
                              name="Log cleanup",
                              descriptionDone=['Cleaned', 'logs'],
                              ))
    script = options.get('update.script', 'bin/upgrade_openerp')
    if script is not None:
        command = [script, options.get('update.log_file_option', '--log-file')]
    else:
        command = [
            'bin/start_openerp', '--stop-after-init',
            '-u',
            comma_list_sanitize(options.get('openerp-addons', 'all')),
            '--logfile',
        ]
    # openerp --logfile does not work with relative paths !
    # (dedicated script may, but uniformity is best)
    command.append(WithProperties('%(workdir)s/build/update.log'))

    steps.append(ShellCommand(command=command,
                              name='updating',
                              description='updating application',
                              descriptionDone='updated',
                              logfiles=dict(update='update.log'),
                              haltOnFailure=True,
                              env=environ,
                              ))

    steps.append(ShellCommand(
        command=["python", "analyze_oerp_tests.py", "update.log"],<commit_msg>Uniformization of upgrade script option name<commit_after>import os
from buildbot import locks
from buildbot.steps.shell import ShellCommand
from buildbot.steps.shell import SetProperty
from buildbot.steps.transfer import FileDownload
from buildbot.steps.transfer import DirectoryUpload
from buildbot.steps.master import MasterShellCommand
from buildbot.process.properties import WithProperties
from buildbot.process.properties import Property
from ..utils import comma_list_sanitize
from ..utils import bool_opt
from ..utils import BUILD_UTILS_PATH


def install_modules_test_openerp(configurator, options, buildout_slave_path,
                                 environ=()):
    """Return steps to run bin/test_openerp -i MODULES."""

    environ = dict(environ)

    steps = []

    steps.append(ShellCommand(command=['rm', '-f', 'test.log'],
                              name="Log cleanup",
                              descriptionDone=['Cleaned', 'logs'],
                              ))

    steps.append(ShellCommand(command=[
        'bin/test_openerp', '-i',
        comma_list_sanitize(options.get('openerp-addons', 'all')),
        # openerp --logfile does not work with relative paths !
        WithProperties('--logfile=%(workdir)s/build/test.log')],
        name='testing',
        description='testing',
        descriptionDone='tests',
        logfiles=dict(test='test.log'),
        haltOnFailure=True,
        env=environ,
    ))

    steps.append(ShellCommand(
        command=["python", "analyze_oerp_tests.py", "test.log"],
        name='analyze',
        description="analyze",
    ))

    return steps


def update_modules(configurator, options, buildout_slave_path,
                   environ=()):
    """Return steps to update the OpenERP application.

    If the option "upgrade.script" is specified, that script is used, and the
    general module list is ignored.
    Otherwise, a raw ``bin/start_openerp -u`` on the declared module list gets
    issued.

    Options:

    ``upgrade.script``: see above.
    ``update.log_file_option``: name of the option to use for dedicated script
                                if there is one.
    """

    environ = dict(environ)

    steps = []

    steps.append(ShellCommand(command=['rm', '-f', 'update.log'],
                              name="Log cleanup",
                              descriptionDone=['Cleaned', 'logs'],
                              ))
    script = options.get('upgrade.script', 'bin/upgrade_openerp')
    if script is not None:
        command = [script, options.get('update.log_file_option', '--log-file')]
    else:
        command = [
            'bin/start_openerp', '--stop-after-init',
            '-u',
            comma_list_sanitize(options.get('openerp-addons', 'all')),
            '--logfile',
        ]
    # openerp --logfile does not work with relative paths !
    # (dedicated script may, but uniformity is best)
    command.append(WithProperties('%(workdir)s/build/update.log'))

    steps.append(ShellCommand(command=command,
                              name='updating',
                              description='updating application',
                              descriptionDone='updated',
                              logfiles=dict(update='update.log'),
                              haltOnFailure=True,
                              env=environ,
                              ))

    steps.append(ShellCommand(
        command=["python", "analyze_oerp_tests.py", "update.log"],
{'fraction_non_alphanumeric': 0.11251435132032148, 'fraction_numerical': 0.0, 'mean_word_length': 2.1307277628032346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '8111', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1838, 'n_words': 430}