3 from __future__
import print_function
5 desc
= '''Generate the difference of two YAML files into a new YAML file (works on
6 pair of directories too). A new attribute 'Added' is set to True or False
7 depending whether the entry is added or removed from the first input to the
10 The tools requires PyYAML.'''
13 # Try to use the C parser.
15 from yaml
import CLoader
as Loader
17 from yaml
import Loader
21 from collections
import defaultdict
23 if __name__
== '__main__':
24 parser
= argparse
.ArgumentParser(description
=desc
)
27 help='An optimization record file or a directory searched for optimization '
28 'record files that are used as the old version for the comparison')
31 help='An optimization record file or a directory searched for optimization '
32 'record files that are used as the new version for the comparison')
38 help='Max job count (defaults to %(default)s, the current CPU count)')
44 help='Maximum number of remarks stored in an output file')
46 '--no-progress-indicator',
50 help='Do not display any indicator of how many YAML files were read.')
51 parser
.add_argument('--output', '-o', default
='diff{}.opt.yaml')
52 args
= parser
.parse_args()
54 files1
= optrecord
.find_opt_files(args
.yaml_dir_or_file_1
)
55 files2
= optrecord
.find_opt_files(args
.yaml_dir_or_file_2
)
57 print_progress
= not args
.no_progress_indicator
58 all_remarks1
, _
, _
= optrecord
.gather_results(files1
, args
.jobs
, print_progress
)
59 all_remarks2
, _
, _
= optrecord
.gather_results(files2
, args
.jobs
, print_progress
)
61 added
= set(all_remarks2
.values()) - set(all_remarks1
.values())
62 removed
= set(all_remarks1
.values()) - set(all_remarks2
.values())
69 result
= list(added | removed
)
71 r
.recover_yaml_structure()
73 for i
in range(0, len(result
), args
.max_size
):
74 with
open(args
.output
.format(i
/ args
.max_size
), 'w') as stream
:
75 yaml
.dump_all(result
[i
:i
+ args
.max_size
], stream
)