Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
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 | |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 31 | from bisect_kit import bisector_cli |
Kuang-che Wu | 88875db | 2017-07-20 10:47:53 +0800 | [diff] [blame] | 32 | from bisect_kit import cli |
| 33 | from bisect_kit import core |
| 34 | |
| 35 | logger = logging.getLogger(__name__) |
| 36 | |
| 37 | |
| 38 | class ListDomain(core.BisectDomain): |
| 39 | """Enumerate list of string for bisection.""" |
| 40 | revtype = staticmethod(cli.argtype_notempty) |
| 41 | |
| 42 | @staticmethod |
| 43 | def add_init_arguments(parser): |
| 44 | # Do nothing because no additional arguments required for this bisector. |
| 45 | pass |
| 46 | |
| 47 | @staticmethod |
| 48 | def init(opts): |
| 49 | config = {} |
Kuang-che Wu | c89f2a2 | 2019-11-26 15:30:50 +0800 | [diff] [blame] | 50 | revlist = [line.strip() for line in sys.stdin.readlines()] |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 51 | return config, {'revlist': revlist} |
Kuang-che Wu | 88875db | 2017-07-20 10:47:53 +0800 | [diff] [blame] | 52 | |
| 53 | def __init__(self, config): |
| 54 | self.config = config |
| 55 | |
| 56 | def setenv(self, env, rev): |
| 57 | pass |
| 58 | |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 59 | def fill_candidate_summary(self, summary): |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 60 | # Do nothing. |
| 61 | return |
Kuang-che Wu | 88875db | 2017-07-20 10:47:53 +0800 | [diff] [blame] | 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 65 | bisector_cli.BisectorCommandLine(ListDomain).main() |