def register_rule_types():
    LOG.debug('Start : register default RuleTypes.')

    for rule_type in RULE_TYPES:
        rule_type = copy.deepcopy(rule_type)

        try:
            rule_type_db = RuleType.get_by_name(rule_type['name'])
            update = True
        except __HOLE__:
            rule_type_db = None
            update = False

        rule_type_api = RuleTypeAPI(**rule_type)
        rule_type_api.validate()
        rule_type_model = RuleTypeAPI.to_model(rule_type_api)

        if rule_type_db:
            rule_type_model.id = rule_type_db.id

        try:
            rule_type_db = RuleType.add_or_update(rule_type_model)

            extra = {'rule_type_db': rule_type_db}
            if update:
                LOG.audit('RuleType updated. RuleType %s', rule_type_db, extra=extra)
            else:
                LOG.audit('RuleType created. RuleType %s', rule_type_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register RuleType %s.', rule_type['name'])

    LOG.debug('End : register default RuleTypes.')
dataset/ETHPy150Open StackStorm/st2/st2common/st2common/bootstrap/ruletypesregistrar.py/register_rule_types