1#!/usr/bin/env python2
2"""Switch part of the objects file in working set to (possible) bad ones.
3
4The "portion" is defined by the file (which is passed as the only argument to
5this script) content. Every line in the file is an object index, which will be
6set to good (mark as 0).
7
8This switch script is made for the noincremental-prune test. This makes sure
9that, after pruning starts (>1 bad item is found), that the number of args sent
10to the switch scripts is equals to the actual number of items (i.e. checking
11that noincremental always holds).
12
13Warning: This switch script assumes the --file_args option
14"""
15
16from __future__ import print_function
17
18import shutil
19import sys
20
21import common
22
23
24def Main(argv):
25  """Switch part of the objects file in working set to (possible) bad ones."""
26  working_set = common.ReadWorkingSet()
27  objects_file = common.ReadObjectsFile()
28  object_index = common.ReadObjectIndex(argv[1])
29
30  for oi in object_index:
31    working_set[oi] = objects_file[oi]
32
33  shutil.copy(argv[1], './noinc_prune_bad')
34
35  common.WriteWorkingSet(working_set)
36
37  return 0
38
39
40if __name__ == '__main__':
41  retval = Main(sys.argv)
42  sys.exit(retval)
43