<commit_before># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import sys

from oslo.config import cfg

import st2reactor.bootstrap.sensorsregistrar as sensors_registrar
import st2actions.bootstrap.actionsregistrar as actions_registrar
import st2actions.bootstrap.runnersregistrar as runners_registrar
import st2common.config as config
from st2common.models.db import db_setup
from st2common.models.db import db_teardown
import st2reactor.bootstrap.rulesregistrar as rules_registrar


LOG = logging.getLogger('st2common.content.bootstrap')


def register_opts():
    content_opts = [
        cfg.BoolOpt('all', default=False, help='Register sensors, actions and rules.'),
        cfg.BoolOpt('sensors', default=True, help='Register sensors.'),
        cfg.BoolOpt('actions', default=True, help='Register actions.'),
        cfg.BoolOpt('rules', default=False, help='Register rules.')
    ]
    try:
        cfg.CONF.register_cli_opts(content_opts, group='register')
    except:
        sys.stderr.write('Failed registering opts.\n')
register_opts()


def register_sensors():
    try:
        sensors_registrar.register_sensors()
    except Exception as e:
        LOG.warning('Failed to register sensors: %s', e, exc_info=True)


def register_actions():
    # Register runnertypes and actions. The order is important because actions require action
    # types to be present in the system.
    try:
        runners_registrar.register_runner_types()
    except Exception as e:
        LOG.warning('Failed to register action types: %s', e, exc_info=True)
        LOG.warning('Not registering stock actions.')
    else:
        try:
            actions_registrar.register_actions()
        except Exception as e:
            LOG.warning('Failed to register actions: %s', e, exc_info=True)


def register_rules():
    # 6. register rules
    try:
        rules_registrar.register_rules()
    except Exception as e:
        LOG.warning('Failed to register rules: %s', e, exc_info=True)


def register_content():
    if cfg.CONF.register.all:
        register_sensors()
        register_actions()
        register_rules()
        return

    if cfg.CONF.register.sensors:
        register_sensors()
        return

    if cfg.CONF.register.actions:
        register_actions()
        return

    if cfg.CONF.register.rules:
        register_rules()
        return
<commit_msg>By default both actions and sensors must be registered<commit_after># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import sys

from oslo.config import cfg

import st2reactor.bootstrap.sensorsregistrar as sensors_registrar
import st2actions.bootstrap.actionsregistrar as actions_registrar
import st2actions.bootstrap.runnersregistrar as runners_registrar
import st2common.config as config
from st2common.models.db import db_setup
from st2common.models.db import db_teardown
import st2reactor.bootstrap.rulesregistrar as rules_registrar


LOG = logging.getLogger('st2common.content.bootstrap')


def register_opts():
    content_opts = [
        cfg.BoolOpt('all', default=False, help='Register sensors, actions and rules.'),
        cfg.BoolOpt('sensors', default=True, help='Register sensors.'),
        cfg.BoolOpt('actions', default=True, help='Register actions.'),
        cfg.BoolOpt('rules', default=False, help='Register rules.')
    ]
    try:
        cfg.CONF.register_cli_opts(content_opts, group='register')
    except:
        sys.stderr.write('Failed registering opts.\n')
register_opts()


def register_sensors():
    try:
        LOG.info('=========================================================')
        LOG.info('############## Registering sensors ######################')
        LOG.info('=========================================================')
        sensors_registrar.register_sensors()
    except Exception as e:
        LOG.warning('Failed to register sensors: %s', e, exc_info=True)


def register_actions():
    # Register runnertypes and actions. The order is important because actions require action
    # types to be present in the system.
    try:
        LOG.info('=========================================================')
        LOG.info('############## Registering actions ######################')
        LOG.info('=========================================================')
        runners_registrar.register_runner_types()
    except Exception as e:
        LOG.warning('Failed to register action types: %s', e, exc_info=True)
        LOG.warning('Not registering stock actions.')
    else:
        try:
            actions_registrar.register_actions()
        except Exception as e:
            LOG.warning('Failed to register actions: %s', e, exc_info=True)


def register_rules():
    # Register rules.
    try:
        LOG.info('=========================================================')
        LOG.info('############## Registering rules ######################')
        LOG.info('=========================================================')
        rules_registrar.register_rules()
    except Exception as e:
        LOG.warning('Failed to register rules: %s', e, exc_info=True)


def register_content():
    if cfg.CONF.register.all:
        register_sensors()
        register_actions()
        register_rules()
        return

    if cfg.CONF.register.sensors:
        register_sensors()

    if cfg.CONF.register.actions:
        register_actions()

    if cfg.CONF.register.rules:
        register_rules()

{'fraction_non_alphanumeric': 0.14683800173260178, 'fraction_numerical': 0.0036095870632399654, 'mean_word_length': 3.7058423913043477, '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': '919708', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1763, 'n_words': 591}