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