Skip to content

Commit 9be6d40

Browse files
authored
Merge pull request #15 from zodb/argparse
Argparse
2 parents d1b1d4d + 007da67 commit 9be6d40

File tree

4 files changed

+50
-28
lines changed

4 files changed

+50
-28
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ notifications:
2727
email: false
2828

2929
install:
30-
- pip install -U pip
30+
- pip install -U pip setuptools
3131
- pip install -U tox coveralls zope.testing mock coverage
3232
- pip install -U -e .
3333
- .travis/setup-$ENV.sh

CHANGES.rst

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
=========
2+
Changes
3+
=========
4+
15
0.6 (Unreleased)
2-
----------------
6+
================
37

48
- Add support for Python 3 and PyPy.
9+
- To specify multiple concurrency levels, specify the ``-c`` option
10+
multiple times. Similarly, to specify multiple object counts,
11+
specify the ``-n`` option multiple times. (For example, ``-c 1 -c 2 -n 100
12+
-n 200`` would run four comparisons). The old way of separating numbers with
13+
commas is no longer supported.
14+
515

616
0.5 (2012-09-08)
7-
----------------
17+
================
818

919
- Updated to MySQL 5.1.65, PostgreSQL 9.1.5, memcached 1.4.15,
1020
and libmemcached 1.0.10.
1121

1222
- Moved development to github.
1323

1424
0.4 (2011-02-01)
15-
----------------
25+
================
1626

1727
- Added the --object-size parameter.
1828

1929
0.3 (2010-06-19)
20-
----------------
30+
================
2131

2232
- Updated to memcached 1.4.5, libmemcached 0.40, and pylibmc 1.1+.
2333

@@ -26,11 +36,11 @@
2636
- Updated to MySQL 5.1.47 and a new download url - the old was giving 401's.
2737

2838
0.2 (2009-11-17)
29-
----------------
39+
================
3040

3141
- Buildout now depends on a released version of RelStorage.
3242

3343
0.1 (2009-11-17)
34-
----------------
44+
================
3545

3646
- Initial release.

src/zodbshootout/main.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from zodbshootout.fork import distribute
2828
from zodbshootout.fork import run_in_child
2929
from ZODB._compat import dumps
30-
import optparse
30+
import argparse
3131
import os
3232
import sys
3333
import time
@@ -275,40 +275,42 @@ def main(argv=None):
275275
if argv is None:
276276
argv = sys.argv[1:]
277277

278-
parser = optparse.OptionParser(usage='%prog [options] config_file')
279-
parser.add_option(
280-
"-n", "--object-counts", dest="counts", default="1000",
281-
help="Object counts to use, separated by commas (default 1000)",
278+
parser = argparse.ArgumentParser()
279+
parser.add_argument(
280+
"-n", "--object-counts", dest="counts",
281+
type=int,
282+
action="append",
283+
help="Object counts to use (default 1000). Use this option as many times as you want.",
282284
)
283-
parser.add_option(
284-
"-s", "--object-size", dest="object_size", default="115",
285+
parser.add_argument(
286+
"-s", "--object-size", dest="object_size", default=115,
287+
type=int,
285288
help="Size of each object in bytes (estimated, default approx. 115)",
286289
)
287-
parser.add_option(
288-
"-c", "--concurrency", dest="concurrency", default="2",
289-
help="Concurrency levels to use, separated by commas (default 2)",
290+
parser.add_argument(
291+
"-c", "--concurrency", dest="concurrency",
292+
type=int,
293+
action="append",
294+
help="Concurrency levels to use. Default is 2. Use this option as many times as you want."
290295
)
291-
parser.add_option(
296+
parser.add_argument(
292297
"-p", "--profile", dest="profile_dir", default="",
293298
help="Profile all tests and output results to the specified directory",
294299
)
300+
parser.add_argument("config_file", type=argparse.FileType())
295301

296-
options, args = parser.parse_args(argv)
297-
if len(args) != 1:
298-
parser.error("exactly one database configuration file is required")
299-
conf_fn = args[0]
302+
options = parser.parse_args(argv)
303+
conf_fn = options.config_file
300304

301-
object_counts = [int(x.strip())
302-
for x in options.counts.split(',')]
303-
object_size = max(int(options.object_size), pobject_base_size)
304-
concurrency_levels = [int(x.strip())
305-
for x in options.concurrency.split(',')]
305+
object_counts = options.counts or [1000]
306+
object_size = max(options.object_size, pobject_base_size)
307+
concurrency_levels = options.concurrency or [2]
306308
profile_dir = options.profile_dir
307309
if profile_dir and not os.path.exists(profile_dir):
308310
os.makedirs(profile_dir)
309311

310312
schema = ZConfig.loadSchemaFile(StringIO(schema_xml))
311-
config, _handler = ZConfig.loadConfig(schema, conf_fn)
313+
config, _handler = ZConfig.loadConfigFile(schema, conf_fn)
312314
contenders = [(db.name, db) for db in config.databases]
313315

314316
txn_descs = (

tox.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tox]
2+
envlist = py27,py34,pypy
3+
4+
[testenv]
5+
deps =
6+
coverage
7+
mock
8+
zope.testing
9+
commands =
10+
coverage run -m zodbshootout.main -c 1 -n 100 .travis/file.conf

0 commit comments

Comments
 (0)