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

Add support for percentages

This also truncates the list after generating the unknown files to get a better
chance of hitting the max
parent 90a531b3
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
Generates empty files that have a very high chance of being treated as "unknown"
by Mercurial by shuffling filenames of existing tracked files.
"""
from __future__ import unicode_literals
from __future__ import unicode_literals, print_function
import argparse
import os
......@@ -70,8 +70,9 @@
parser = argparse.ArgumentParser()
parser.add_argument("-R", "--repository", help="path to the repository",
action="store", default=".", type=str)
parser.add_argument("--max", help="maximum of files to create",
action="store", default=0, type=int)
parser.add_argument("--max",
help="maximum number or percentage of files to create",
action="store", default="0", type=str)
parser.add_argument(
"--dry-run",
help="don't actually generate the files, print them to stdout",
......@@ -88,6 +89,13 @@
)
args = parser.parse_args(args)
max = args.max
max_percentage = False
if max and max[-1] == "%":
max = int(max[:-1])
max_percentage = True
else:
max = int(max)
repo_path = args.repository
output_list_path = args.output_list
......@@ -105,4 +113,6 @@
random.shuffle(tracked_paths)
unknown_paths = generate_unknown_paths(tracked_paths=tracked_paths)
if max:
......@@ -108,7 +118,13 @@
if max:
tracked_paths = tracked_paths[:max]
unknown_paths = generate_unknown_paths(tracked_paths=tracked_paths)
if max_percentage:
limit = len(unknown_paths) * max / 100
else:
limit = max
if limit > len(unknown_paths):
criterion = "%s%%" % limit if max_percentage else limit
msg = "warning: generated fewer than %s files" % criterion
print(msg, file=sys.stderr)
unknown_paths = unknown_paths[:limit]
if not unknown_paths:
raise ValueError("No unknown paths were generated")
......
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