blob: 5f516a56d1c8b33a4a1041d2dfa5d1cc927f6097 [file] [log] [blame]
Kuang-che Wu88875db2017-07-20 10:47:53 +08001#!/usr/bin/env python2
2# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""A simple bisector to bisect a list of arbitrary strings.
6
7The strings to bisect are read from stdin, one item at a line.
8
9Example:
10 Let's play the number guessing game. You choice a number in your mind
11 in range 1..99. You can lie within 20% probability. Let bisect-kit
12 guess.
13
14 Assume numbers less than your answer are considered as "old" and greater or
15 equals to your answer are "new".
16 $ seq 1 99 | ./bisect-list.py init --old 1 --new 99 --noisy=old=1/5,new=4/5
17 $ ./bisect-list.py config switch /bin/true
18 $ ./bisect-list.py config eval ./eval-manually.sh
19 $ ./bisect-list.py run
20
21 If you don't lie, just omit --noisy argument.
22
23 p.s. seq(1) prints a sequence of numbers, one at a line.
24"""
25
26from __future__ import print_function
27import logging
28import sys
29
30from bisect_kit import cli
31from bisect_kit import core
32
33logger = logging.getLogger(__name__)
34
35
36class ListDomain(core.BisectDomain):
37 """Enumerate list of string for bisection."""
38 revtype = staticmethod(cli.argtype_notempty)
39
40 @staticmethod
41 def add_init_arguments(parser):
42 # Do nothing because no additional arguments required for this bisector.
43 pass
44
45 @staticmethod
46 def init(opts):
47 config = {}
48 revlist = map(str.strip, sys.stdin.readlines())
49 return config, revlist
50
51 def __init__(self, config):
52 self.config = config
53
54 def setenv(self, env, rev):
55 pass
56
57 def view(self, old, new):
58 logger.info('[%s] is old', old)
59 logger.info('[%s] is new', new)
60
61
62if __name__ == '__main__':
63 cli.BisectorCommandLineInterface(ListDomain).main()