Skip to content

Commit 907b001

Browse files
committed
Fix the mask generator script
1 parent 38b9e5a commit 907b001

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

scripts/prepare-metadata/__main__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@
1313

1414

1515
def update_mask(mask, length):
16-
length_without_cc = len(re.findall(r"[\d.]", re.sub(r"\+\d+\s", "", mask)))
16+
length_without_cc = re.sub(r"^[^)]+\)\s", "", mask).count(".")
1717
if length_without_cc != length:
18-
cc_mask = re.match(r"(\+\d+)\s", mask).group(1)
19-
ac_mask = re.match(r"\+\d+\s(?:(\S+)\s)?", mask).group(1) or ""
20-
ac_mask_length = len(re.findall(r"[\d.]", ac_mask))
21-
pn_mask_expected_length = length - ac_mask_length
22-
pn_mask_prefix = re.sub(r"\+\d+\s(?:\S+\s)?", "", mask).split()[0]
18+
cc_mask = re.match(r"(\+[^(]+)\s", mask).group(1)
19+
ac_mask = re.match(r"\+[^(]+(?:(\S+)\s)?", mask).group(1) or ""
20+
pn_mask_prefix = re.sub(r"\+[^(]+(?:\S+\s)?", "", mask).split()[0]
21+
pn_mask_expected_length = length - len(re.findall(r"[\d.]", ac_mask)) - len(re.findall(r"\d", pn_mask_prefix))
2322
pn_mask_parts = [pn_mask_prefix]
2423
while len("".join(pn_mask_parts)) < pn_mask_expected_length:
2524
pn_mask_parts.append("." * len(pn_mask_prefix))
2625
pn_mask = " ".join(pn_mask_parts)
27-
while len(pn_mask.replace(" ", "")) > pn_mask_expected_length:
26+
while pn_mask.count(".") > pn_mask_expected_length:
2827
pn_mask = pn_mask[:-1]
2928
mask = f"{cc_mask} {ac_mask} {pn_mask}" if ac_mask else f"{cc_mask} {pn_mask}"
30-
return re.sub(r"\s(\.)$", r"\1", mask)
29+
return re.sub(r"\s(\.{1,2})$", r"\1", mask)
3130

3231

3332
with open(patterns_path) as fp:

0 commit comments

Comments
 (0)