Skip to content
Snippets Groups Projects
Commit f53460bb authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

Make generation more robust

parent d9e0dd2d
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@
=> ["path/to/repo/hoggrnie"]
"""
cleaner_regex = re.compile('[\W_]+', flags=re.UNICODE)
all_numbers_regex = re.compile('\d+')
new_paths = []
for path in tracked_paths:
......@@ -36,5 +37,5 @@
# That way we don't easily create problematic filenames (on Linux...)
filename = cleaner_regex.sub("", filename)
if len(filename) < 3:
if len(filename) < 5 or all_numbers_regex.match(filename):
# skip files that are too small to prevent easy conflict
......@@ -40,7 +41,8 @@
# skip files that are too small to prevent easy conflict
# or purely made up of numbers.
continue
l = list(filename)
random.shuffle(l)
new_name = ''.join(l) + ext
......@@ -41,9 +43,12 @@
continue
l = list(filename)
random.shuffle(l)
new_name = ''.join(l) + ext
if new_name == basename:
# we generated the same name
continue
new_paths.append(path[0:-len(basename)] + new_name)
return new_paths
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment