Esempio n. 1
0
def extract_terms(fn, data_src):
    data_src_nocomments = remove_comments(data_src)
    for m in re_words.finditer(data_src_nocomments):
        words_len = len(words)
        m_text = m.group()
        words.add(m_text)
        if words_len == len(words):
            words_multi.add(m_text)

    for m in re_defines.finditer(data_src_nocomments):
        defines[m.group(1)] = fn

    # Don't edit the file.
    return None


run(
    directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
    is_text=lambda fn: fn.endswith(SOURCE_EXT),
    text_operation=extract_terms,
    # Can't be used if we want to accumulate in a global variable.
    use_multiprocess=False,
)

print("Found", len(defines), "defines, searching", len(words_multi),
      "terms...")
for fn, define in sorted([(fn, define) for define, fn in defines.items()]):
    if define not in words_multi:
        print(define, "->", fn)
        b = b.split("/")
        if len(a) == 1 and len(b) == 1:
            return True
        return a[:-1] == b[:-1]

    i = 0
    while i < len(lines):
        if can_sort(lines[i]):
            j = i
            while j + 1 < len(lines):
                if not can_sort(lines[j + 1]):
                    break
                if not can_sort_compat(lines[i], lines[j + 1]):
                    break
                j = j + 1
            if i != j:
                lines[i:j + 1] = list(sorted(lines[i:j + 1]))
            i = j
        i = i + 1

    data_dst = "".join(lines)
    if data_src != data_dst:
        return data_dst


run(
    directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
    is_text=lambda fn: fn.endswith("CMakeLists.txt"),
    text_operation=sort_cmake_file_lists,
)
Esempio n. 3
0
        # Disable for now.
        # if re_match_datatoc.match(l):
        #     return 5
        return None

    i = 0
    while i < len(lines):
        i_type = can_sort(lines[i])
        if i_type is not None:
            j = i
            while j + 1 < len(lines):
                if can_sort(lines[j + 1]) != i_type:
                    break
                j = j + 1
            if i != j:
                lines[i:j + 1] = list(sorted(lines[i:j + 1]))
            i = j
        i = i + 1

    data_dst = "".join(lines)
    if data_src != data_dst:
        return data_dst


run(
    directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
    is_text=lambda fn: fn.endswith(SOURCE_EXT),
    text_operation=sort_struct_lists,
    use_multiprocess=True,
)