From 657ec65e4a3d788f42af8b5511789f0ead101e93 Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 6 Feb 2024 12:19:11 -0500 Subject: [PATCH] handle alphabetic suffixes --- dlibrary/dlibrary.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index cf5d4fc..deaf3ee 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -264,7 +264,7 @@ def unique_hierarchical_prefix_numbering(entries, start_point=0): if len(numbering[idx]) > 1: ents_idx = numbering.pop(idx) next_layer_start = pos + NUMBER_REGEX.match(ents_idx[0].name[pos:]).end() - sub_numbering = unique_hierarchical_prefix_numbering(ents_idx, start_point=next_layer_start) + sub_numbering = unique_hierarchical_prefix_numbering(ents_idx, start_point=next_layer_start) or alphabetic_numbering(ents_idx, next_layer_start) if not sub_numbering: return None for sub_idx in sub_numbering: @@ -274,6 +274,22 @@ def unique_hierarchical_prefix_numbering(entries, start_point=0): return None +def alphabetic_numbering(entries, start_point): + alphabetized = {} + for entry in entries: + ending = entry.stem[start_point:] + if len(ending) > 1: + return None + index = 0 if ending == '' else ord(ending.lower()) - ord('a') + if index in alphabetized: + return None + alphabetized[(index,)] = [entry] + indices = list(alphabetized.keys()) + indices.sort() + if indices != [(i,) for i in range(len(indices))]: + return None + return alphabetized + def link_ordered_files(ordering, dest, start_index): dest.mkdir(parents=True, exist_ok=True)