Commit 001e3295 authored by Matt Traudt's avatar Matt Traudt
Browse files

Add config option for v3bw file location

Can be overridden by --output option to sbws generate

GH: closes #91
parent 8ee187b5
[paths]
datadir = ${sbws_home}/datadir
v3bw_fname = ${sbws_home}/v3bw.txt
[scanner]
nickname = IDidntEditTheSBWSConfig
......@@ -76,8 +76,9 @@ def gen_parser(sub):
'bandwidth votes on.'
p = sub.add_parser('generate', description=d,
formatter_class=ArgumentDefaultsHelpFormatter)
p.add_argument('--output', default='/dev/stdout', type=str,
help='Where to write v3bw file')
p.add_argument('--output', default=None, type=str,
help='If specified, write the v3bw here instead of what is'
'specified in the configuration')
# The reason for --scale-constant defaulting to 7500 is because at one
# time, torflow happened to generate output that averaged to 7500 bw units
# per relay. We wanted the ability to try to be like torflow. See
......@@ -122,8 +123,11 @@ def main(args, conf):
data_lines = scale_lines(args, data_lines)
header = V3BwHeader()
log_stats(data_lines)
log.info('Writing v3bw file to %s', args.output)
with open(args.output, 'wt') as fd:
output = conf['paths']['v3bw_fname']
if args.output:
output = args.output
log.info('Writing v3bw file to %s', output)
with open(output, 'wt') as fd:
fd.write(str(header))
for line in data_lines:
fd.write('{}\n'.format(str(line)))
......@@ -137,7 +137,7 @@ def _validate_paths(conf):
errors = []
sec = 'paths'
err_tmpl = Template('$sec/$key ($val): $e')
unvalidated_keys = ['passwords', 'datadir', 'sbws_home']
unvalidated_keys = ['datadir', 'sbws_home', 'v3bw_fname']
all_valid_keys = unvalidated_keys
errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl))
return errors
......
......@@ -28,7 +28,8 @@ def test_generate_no_dotsbws(tmpdir, caplog, parser):
def test_generate_no_datadir(empty_dotsbws, caplog, parser):
dotsbws = empty_dotsbws
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
try:
sbws.core.generate.main(args, conf)
......@@ -43,8 +44,8 @@ def test_generate_no_datadir(empty_dotsbws, caplog, parser):
def test_generate_bad_scale_constant(empty_dotsbws_datadir, caplog, parser):
dotsbws = empty_dotsbws_datadir
args = parser.parse_args(
'-d {} --log-level DEBUG generate --scale-constant -1'
.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --scale-constant -1 '
'--output /dev/stdout'.format(dotsbws.name).split())
conf = get_config(args)
try:
sbws.core.generate.main(args, conf)
......@@ -59,7 +60,8 @@ def test_generate_bad_scale_constant(empty_dotsbws_datadir, caplog, parser):
def test_generate_empty_datadir(empty_dotsbws_datadir, caplog, parser):
dotsbws = empty_dotsbws_datadir
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
assert 'No recent results' in caplog.records[-1].getMessage()
......@@ -69,7 +71,8 @@ def test_generate_single_error(dotsbws_error_result, caplog, parser):
caplog.set_level(logging.DEBUG)
dotsbws = dotsbws_error_result
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......@@ -86,7 +89,8 @@ def test_generate_single_success_noscale(dotsbws_success_result, caplog,
parser, capfd):
dotsbws = dotsbws_success_result
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......@@ -111,8 +115,8 @@ def test_generate_single_success_scale(dotsbws_success_result, parser,
capfd):
dotsbws = dotsbws_success_result
args = parser.parse_args(
'-d {} --log-level DEBUG generate --scale'.format(dotsbws.name)
.split())
'-d {} --log-level DEBUG generate --scale --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......@@ -136,7 +140,8 @@ def test_generate_single_relay_success_noscale(
dotsbws_success_result_one_relay, parser, capfd):
dotsbws = dotsbws_success_result_one_relay
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......@@ -162,8 +167,8 @@ def test_generate_single_relay_success_scale(
dotsbws_success_result_one_relay, parser, capfd):
dotsbws = dotsbws_success_result_one_relay
args = parser.parse_args(
'-d {} --log-level DEBUG generate --scale'.format(dotsbws.name)
.split())
'-d {} --log-level DEBUG generate --scale --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......@@ -187,7 +192,8 @@ def test_generate_two_relays_success_noscale(
dotsbws_success_result_two_relays, parser, capfd):
dotsbws = dotsbws_success_result_two_relays
args = parser.parse_args(
'-d {} --log-level DEBUG generate'.format(dotsbws.name).split())
'-d {} --log-level DEBUG generate --output /dev/stdout'
.format(dotsbws.name).split())
conf = get_config(args)
sbws.core.generate.main(args, conf)
dd = conf['paths']['datadir']
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment