blob: 6be93994a8363245a1a0ed634436ebe765bec98a [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
31from bisect_kit import cli
32from bisect_kit import core
33
34logger = logging.getLogger(__name__)
35
36
37class 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
63if __name__ == '__main__':
Kuang-che Wu68db08a2018-03-30 11:50:34 +080064 cli.BisectorCommandLine(ListDomain).main()