From b6e0287810bcf136cd99c641ef70b3756c52dd7c Mon Sep 17 00:00:00 2001 From: Wesley Spikes Date: Fri, 15 Jul 2011 11:45:38 -0700 Subject: [PATCH] Add context, get_next_key, and fill_pools to s3tests.common context is a generic Bunch that we can store items in to be shared across modules, without invoking the wrath of the globals -- yuck! get_next_key will generate a sequentially numbered key for us to use fill_pools will take a variable list of gevent.pool.Pool objects and top them all off --- s3tests/common/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/s3tests/common/__init__.py b/s3tests/common/__init__.py index 373d191..7039d43 100644 --- a/s3tests/common/__init__.py +++ b/s3tests/common/__init__.py @@ -10,7 +10,13 @@ s3 = bunch.Bunch() config = bunch.Bunch() prefix = '' +# For those scripts that use a context, these are pretty univerally needed. +context = bunch.Bunch( + bucket = None, +) + bucket_counter = itertools.count(1) +key_counter = itertools.count(1) def choose_bucket_prefix(template, max_len=30): """ @@ -156,3 +162,12 @@ def get_new_bucket(connection=None): def teardown(): nuke_prefixed_buckets() + +def fill_pools(*args): + for pool in args: + while not pool.full(): + pool.spawn() + +def get_next_key(bucket=None): + return bucket.new_key("seqkey-{num}".format(num=next(key_counter))) +