Kuang-che Wu | 88875db | 2017-07-20 10:47:53 +0800 | [diff] [blame^] | 1 | #!/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 | |
| 7 | The strings to bisect are read from stdin, one item at a line. |
| 8 | |
| 9 | Example: |
| 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 | |
| 26 | from __future__ import print_function |
| 27 | import logging |
| 28 | import sys |
| 29 | |
| 30 | from bisect_kit import cli |
| 31 | from bisect_kit import core |
| 32 | |
| 33 | logger = logging.getLogger(__name__) |
| 34 | |
| 35 | |
| 36 | class 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 | |
| 62 | if __name__ == '__main__': |
| 63 | cli.BisectorCommandLineInterface(ListDomain).main() |