Skip to content

Commit 65b9f3a

Browse files
committed
extract_utils: sort only groups of blobs
This prevents sorting lines within comments. Change-Id: I14c85edd1691dd5aae13ae9f094e5e31ef7a6e28
1 parent 050cbd9 commit 65b9f3a

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

sort-blobs-list.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
#!/usr/bin/env python3
22
#
3-
# SPDX-FileCopyrightText: 2021-2024 The LineageOS Project
3+
# SPDX-FileCopyrightText: 2021-2025 The LineageOS Project
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

77
import re
88
from argparse import ArgumentParser
99
from functools import cmp_to_key
10+
from itertools import groupby
1011
from locale import LC_ALL, setlocale, strcoll
1112
from pathlib import Path
1213

1314

15+
def is_blob(line: str) -> bool:
16+
line = line.strip()
17+
return line and not line.startswith('#')
18+
19+
1420
def get_source_file_name(line: str) -> str:
1521
# Remove '-' from strings if there,
1622
# it is used to indicate a build target
@@ -88,13 +94,14 @@ def strcoll_extract_utils(
8894
continue
8995

9096
with open(file, 'r', encoding='utf-8') as f:
91-
sections = f.read().split('\n\n')
97+
sections = groupby(f.readlines(), is_blob)
9298

9399
ordered_sections = []
94-
for section in sections:
95-
section_list = [line.strip() for line in section.splitlines()]
96-
section_list.sort(key=sort_key)
97-
ordered_sections.append('\n'.join(section_list))
100+
for sort, section in sections:
101+
if sort:
102+
ordered_sections.append(''.join(sorted(section, key=sort_key)))
103+
else:
104+
ordered_sections.append(''.join(section))
98105

99106
with open(file, 'w', encoding='utf-8') as f:
100-
f.write('\n\n'.join(ordered_sections).strip() + '\n')
107+
f.write(''.join(ordered_sections))

0 commit comments

Comments
 (0)