zephyr/tests/kernel
Lingao Meng 302422ad9d everywhere: replace double words
import os
import re

common_words = set([
    'about', 'after', 'all', 'also', 'an', 'and',
     'any', 'are', 'as', 'at',
    'be', 'because', 'but', 'by', 'can', 'come',
    'could', 'day', 'do', 'even',
    'first', 'for', 'get', 'give', 'go', 'has',
    'have', 'he', 'her',
    'him', 'his', 'how', 'I', 'in', 'into', 'it',
    'its', 'just',
    'know', 'like', 'look', 'make', 'man', 'many',
    'me', 'more', 'my', 'new',
    'no', 'not', 'now', 'of', 'one', 'only', 'or',
    'other', 'our', 'out',
    'over', 'people', 'say', 'see', 'she', 'so',
    'some', 'take', 'tell', 'than',
    'their', 'them', 'then', 'there', 'these',
    'they', 'think',
    'this', 'time', 'two', 'up', 'use', 'very',
    'want', 'was', 'way',
    'we', 'well', 'what', 'when', 'which', 'who',
    'will', 'with', 'would',
    'year', 'you', 'your'
])

valid_extensions = set([
    'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
    'rst', 'dtsi',
    'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
    'soc', 'cfg'
])

def filter_repeated_words(text):
    # Split the text into lines
    lines = text.split('\n')

    # Combine lines into a single string with unique separator
    combined_text = '/*sep*/'.join(lines)

    # Replace repeated words within a line
    def replace_within_line(match):
        return match.group(1)

    # Regex for matching repeated words within a line
    within_line_pattern =
	re.compile(r'\b(' +
		'|'.join(map(re.escape, common_words)) +
		r')\b\s+\b\1\b')
    combined_text = within_line_pattern.
		sub(replace_within_line, combined_text)

    # Replace repeated words across line boundaries
    def replace_across_lines(match):
        return match.group(1) + match.group(2)

    # Regex for matching repeated words across line boundaries
    across_lines_pattern = re.
		compile(r'\b(' + '|'.join(
			map(re.escape, common_words)) +
			r')\b(\s*[*\/\n\s]*)\b\1\b')
    combined_text = across_lines_pattern.
		sub(replace_across_lines, combined_text)

    # Split the text back into lines
    filtered_text = combined_text.split('/*sep*/')

    return '\n'.join(filtered_text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()

    new_text = filter_repeated_words(text)

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_text)

def process_directory(directory_path):
    for root, dirs, files in os.walk(directory_path):
        dirs[:] = [d for d in dirs if not d.startswith('.')]
        for file in files:
            # Filter out hidden files
            if file.startswith('.'):
                continue
            file_extension = file.split('.')[-1]
            if
	file_extension in valid_extensions:  # 只处理指定后缀的文件
                file_path = os.path.join(root, file)
                print(f"Processed file: {file_path}")
                process_file(file_path)

directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2024-06-25 06:05:35 -04:00
..
cache tests: kernel: cache: Remove adp_xc7k/ae350 from the blacklist 2024-04-22 09:19:27 -04:00
common everywhere: replace double words 2024-06-25 06:05:35 -04:00
condvar/condvar_api
context tests/kernel/context: Detect spurious wakes during timeout check 2024-05-07 17:56:50 -04:00
device coding guidelines: comply with MISRA Rule 11.8 2024-06-03 16:09:51 -04:00
early_sleep
events
fatal samples: tests: bluetooth: Add support for frdm_rw612 2024-06-10 07:02:06 -07:00
fifo everywhere: replace double words 2024-06-25 06:05:35 -04:00
fpu_sharing twister: s/riscv(32|64)/riscv 2024-02-26 12:49:06 +01:00
gen_isr_table tests: kernel: gen_isr_table: add support for nRF54L15 FLPR 2024-05-27 08:15:46 -07:00
interrupt tests: kernel: interrupt: account for table offset 2024-05-29 11:58:44 +02:00
ipi_cascade tests: Add test for IPI cascades 2024-06-21 20:49:11 -04:00
ipi_optimize tests: Add IPI_OPTIMIZE tests 2024-06-04 22:35:54 -04:00
lifo
mbox hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
mem_heap/k_heap_api
mem_protect tests: demand_paging: extend memory access patterns 2024-06-14 18:58:02 -04:00
mem_slab hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
mp arch: rename arch_start_cpu() to arch_cpu_start() 2024-03-25 09:58:35 +00:00
msgq
mutex tests: mutex/sys_mutex: config overlay for intel_adsp/ace30_ptl 2024-06-06 20:06:11 -04:00
obj_core everywhere: replace double words 2024-06-22 05:40:22 -04:00
obj_tracking
pending
pipe arch: define struct arch_esf and deprecate z_arch_esf_t 2024-06-04 14:02:51 -05:00
poll tests: poll: fix misconstructed k_poll_event test 2024-06-12 10:24:21 +02:00
profiling/profiling_api tests: kernel: remove pm from profiling test 2024-04-25 09:55:08 +00:00
queue tests: kernel/queue: config overlay for intel_adsp/ace30_ptl 2024-06-06 20:06:11 -04:00
sched everywhere: replace double words 2024-06-25 06:05:35 -04:00
semaphore tests/kernel: Bump kobj thread bitmask size for a few tests 2024-05-02 13:55:03 -04:00
sleep
smp arch: riscv: stacktrace: implement arch_stack_walk() 2024-06-13 16:46:48 -04:00
smp_abort arch/x86: Make irq_offload SMP-safe on x86_64 2024-06-04 07:57:06 +02:00
smp_boot_delay hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
smp_suspend
spinlock arch: rename arch_start_cpu() to arch_cpu_start() 2024-03-25 09:58:35 +00:00
stack/stack everywhere: replace double words 2024-06-25 06:05:35 -04:00
threads test: Apply semantic patch file ztest_strcmp.cocci 2024-06-14 19:25:42 +02:00
tickless/tickless_concept tests: tickless: do not enable PM 2024-04-25 09:55:08 +00:00
timer tests: kernel: timer_behavior_external: Fix a typo 2024-06-14 09:41:52 -04:00
usage/thread_runtime_stats tests: kernel: thread_runtime_stats: Relax precision test for QEMU 2024-03-06 16:42:33 -05:00
workq everywhere: replace double words 2024-06-22 05:40:22 -04:00
xip everywhere: replace double words 2024-06-25 06:05:35 -04:00