import pprint
import re
VERSION_PATTERN = r"\d+\.\d+"
def version_to_int(version: str) -> int:
i = version.index(".")
major_version = int(version[:i])
minor_version = int(version[i + 1:])
return major_version * 1000 + minor_version
def squash_file_paths(file_paths: set[str]) -> list[str]:
squashed_file_paths: list[str] = []
clean_file_path_to_versions: dict[str, set[str]] = {}
for file_path in file_paths:
clean_file_path = re.sub(VERSION_PATTERN, "{versions}", file_path)
versions = set(re.findall(VERSION_PATTERN, file_path))
if len(versions) == 0:
squashed_file_paths.append(file_path)
continue
if len(versions) > 1:
raise Exception(f">1 versions found in {file_path}: {versions}")
version = list(versions)[0]
if clean_file_path in clean_file_path_to_versions:
clean_file_path_to_versions[clean_file_path].add(version)
else:
clean_file_path_to_versions[clean_file_path] = set([version])
for clean_file_path in clean_file_path_to_versions:
versions = f"{{{','.join(sorted(list(clean_file_path_to_versions[clean_file_path]), key=version_to_int))}}}"
squashed_file_path = clean_file_path.replace("{versions}", versions)
squashed_file_paths.append(squashed_file_path)
return sorted(squashed_file_paths)
def main():
file_paths = set([
'macska\\füle\\3szög',
#'kisKutya\\XY\\1.100\\Specifications\\DB-Spec_kisKutya_1.200.adoc',
'kisKutya\\XY\\1.4\\Specifications\\DB-Spec_kisKutya_1.4.adoc',
'kisKutya\\ABC\\2.0\\Module Design\\kisKutya_2.0.adoc',
'kisKutya\\ABC\\2.3\\Module Design\\kisKutya_2.3.adoc',
'kisKutya\\ABC\\2.4\\Module Design\\kisKutya_2.4.adoc',
'kisKutya\\ABC\\1.4\\Module Design\\ABC-Design_kisKutya_1.4.adoc',
'kisKutya\\XY\\1.10\\Specifications\\DB-Spec_kisKutya_1.10.adoc',
'kisKutya\\XY\\1.9\\Specifications\\DB-Spec_kisKutya_1.9.adoc',
'kisKutya\\ABC\\1.4\\SPML Interface Snippet\\SPML-Snippet_kisKutya_1.4.adoc',
'kisKutya\\ABC\\1.3\\Module Design\\ABC-Design_kisKutya_1.3.adoc',
'kisKutya\\ABC\\2.1\\Module Design\\kisKutya_2.1.adoc',
'kisKutya\\XY\\1.6\\Specifications\\DB-Spec_kisKutya_1.6.adoc',
'kisKutya\\XY\\1.5\\Specifications\\DB-Spec_kisKutya_1.5.adoc',
'kisKutya\\ABC\\2.2\\Module Design\\kisKutya_2.2.adoc',
'kisKutya\\XY\\1.7\\Specifications\\DB-Spec_kisKutya_1.7.adoc',
'kisKutya\\ABC\\1.5\\Module Design\\kisKutya_1.5.adoc',
'kisKutya\\ABC\\1.3\\SPML Interface Snippet\\SPML-Snippet_kisKutya_1.3.adoc'
])
squashed_file_paths = squash_file_paths(file_paths)
for squashed_file_path in squashed_file_paths:
print(squashed_file_path)
main()
To embed this program on your website, copy the following code and paste it into your website's HTML: