Return a new, unique and non-existing base location in ``rules_directory`` with a file name but without an extension suitable to create a new rule without overwriting any existing rule. Use the ``name_prefix`` string as a prefix for this name.
(name_prefix, rules_directory=rules_data_dir)
| 3013 | |
| 3014 | |
| 3015 | def find_rule_base_location(name_prefix, rules_directory=rules_data_dir): |
| 3016 | """ |
| 3017 | Return a new, unique and non-existing base location in ``rules_directory`` |
| 3018 | with a file name but without an extension suitable to create a new rule |
| 3019 | without overwriting any existing rule. Use the ``name_prefix`` string as a |
| 3020 | prefix for this name. |
| 3021 | """ |
| 3022 | |
| 3023 | cleaned = ( |
| 3024 | name_prefix |
| 3025 | .lower() |
| 3026 | .strip() |
| 3027 | .replace(' ', '_') |
| 3028 | .replace('(', '') |
| 3029 | .replace(')', '') |
| 3030 | .strip('_-') |
| 3031 | ) |
| 3032 | template = cleaned + '_{idx}' |
| 3033 | |
| 3034 | idx = 1 |
| 3035 | while True: |
| 3036 | base_name = template.format(idx=idx) |
| 3037 | base_loc = join(rules_directory, base_name) |
| 3038 | if not exists(f'{base_loc}.RULE'): |
| 3039 | return base_loc |
| 3040 | idx += 1 |
| 3041 | |
| 3042 | |
| 3043 | def get_rules_by_identifier(rules_data_dir=rules_data_dir): |
no test coverage detected