blob: 53784eb39ff4d4c510efe93e440cd159ae7bc39f [file] [log] [blame]
Kuang-che Wu88875db2017-07-20 10:47:53 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wu88875db2017-07-20 10:47:53 +08003# 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
8The strings to bisect are read from stdin, one item at a line.
9
10Example:
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 Wu02170592018-07-09 21:42:44 +080017 $ 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 Wu88875db2017-07-20 10:47:53 +080021
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
27from __future__ import print_function
28import logging
29import sys
30
Kuang-che Wu2526a672019-09-10 16:23:59 +080031from bisect_kit import bisector_cli
Kuang-che Wu88875db2017-07-20 10:47:53 +080032from bisect_kit import cli
33from bisect_kit import core
34
35logger = logging.getLogger(__name__)
36
37
38class 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 = {}
50 revlist = map(str.strip, sys.stdin.readlines())
51 return config, revlist
52
53 def __init__(self, config):
54 self.config = config
55
56 def setenv(self, env, rev):
57 pass
58
Kuang-che Wue80bb872018-11-15 19:45:25 +080059 def fill_candidate_summary(self, summary, interesting_indexes):
60 # Do nothing.
61 return
Kuang-che Wu88875db2017-07-20 10:47:53 +080062
63
64if __name__ == '__main__':
Kuang-che Wu2526a672019-09-10 16:23:59 +080065 bisector_cli.BisectorCommandLine(ListDomain).main()