[#299] Add fuse to prevent similar names generation

Signed-off-by: a.berezin <a.berezin@yadro.com>
This commit is contained in:
Andrey Berezin 2024-10-07 15:59:00 +03:00
parent 24b8ca73d7
commit 2976e30b75

View file

@ -1,3 +1,4 @@
import itertools
import random import random
import re import re
import string import string
@ -7,6 +8,8 @@ ONLY_ASCII_LETTERS = string.ascii_letters
DIGITS_AND_ASCII_LETTERS = string.ascii_letters + string.digits DIGITS_AND_ASCII_LETTERS = string.ascii_letters + string.digits
NON_DIGITS_AND_LETTERS = string.punctuation NON_DIGITS_AND_LETTERS = string.punctuation
FUSE = itertools.cycle(range(5))
def unique_name(prefix: str = "", postfix: str = ""): def unique_name(prefix: str = "", postfix: str = ""):
""" """
@ -18,7 +21,7 @@ def unique_name(prefix: str = "", postfix: str = ""):
Returns: Returns:
unique name string unique name string
""" """
return f"{prefix}{hex(int(datetime.now().timestamp() * 1000000))}{postfix}" return f"{prefix}{hex(int(datetime.now().timestamp() * 1000000))}{next(FUSE)}{postfix}"
def random_string(length: int = 5, source: str = ONLY_ASCII_LETTERS): def random_string(length: int = 5, source: str = ONLY_ASCII_LETTERS):