forked from TrueCloudLab/s3-tests
adding max_amount to realistic.names generator
Set max_amount to limit the number of names yeilded by the generator.
This commit is contained in:
parent
a775f5da04
commit
b465596063
1 changed files with 7 additions and 1 deletions
|
@ -137,12 +137,13 @@ def files(mean, stddev, seed=None):
|
||||||
break
|
break
|
||||||
yield RandomContentFile(size=size, seed=rand.getrandbits(32))
|
yield RandomContentFile(size=size, seed=rand.getrandbits(32))
|
||||||
|
|
||||||
def names(mean, stddev, charset=None, seed=None):
|
def names(mean, stddev, charset=None, seed=None, max_amount=None):
|
||||||
"""
|
"""
|
||||||
Yields strings that are somewhat plausible as file names, where
|
Yields strings that are somewhat plausible as file names, where
|
||||||
the lenght of each filename follows the normal distribution with
|
the lenght of each filename follows the normal distribution with
|
||||||
`mean` and `stddev`.
|
`mean` and `stddev`.
|
||||||
"""
|
"""
|
||||||
|
count = 0
|
||||||
if charset is None:
|
if charset is None:
|
||||||
charset = string.ascii_lowercase
|
charset = string.ascii_lowercase
|
||||||
rand = random.Random(seed)
|
rand = random.Random(seed)
|
||||||
|
@ -154,6 +155,11 @@ def names(mean, stddev, charset=None, seed=None):
|
||||||
name = ''.join(rand.choice(charset) for _ in xrange(length))
|
name = ''.join(rand.choice(charset) for _ in xrange(length))
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
if count == max_amount:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def files_varied(groups, unlimited=False):
|
def files_varied(groups, unlimited=False):
|
||||||
""" Yields a weighted-random selection of file-like objects. """
|
""" Yields a weighted-random selection of file-like objects. """
|
||||||
# Quick data type sanity.
|
# Quick data type sanity.
|
||||||
|
|
Loading…
Reference in a new issue