ATLAS Offline Software
meta-diff.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 """This script reads metadata from a given file"""
5 
6 from __future__ import print_function
7 
8 import argparse
9 import os
10 import sys
11 
12 from PyUtils.MetaDiff import meta_diff
13 
14 # escape sequence [?1034h which appear on several runs due to smm capability
15 # (Meta Mode On) for xterm.
16 if "TERM" in os.environ:
17  del os.environ["TERM"]
18 
19 
20 def main():
21  """Handle command line arguments and call meta_diff"""
22 
23  parser = argparse.ArgumentParser(
24  description="Compare the metadata content of two files"
25  )
26 
27  parser.add_argument(
28  "files",
29  nargs=2,
30  metavar="FILE",
31  help="The names of two files to compare",
32  )
33 
34  parser.add_argument(
35  "-v",
36  "--verbose",
37  action="store_true",
38  help="print detailed output on screen",
39  )
40 
41  parser.add_argument(
42  "-s",
43  "--ordered",
44  action="store_true",
45  help="When comparing lists, check the element order too.",
46  )
47 
48  parser.add_argument(
49  "-r",
50  "--regex",
51  action="store_true",
52  help="Allows filtering by regex instead of by plain string",
53  )
54 
55  parser.add_argument(
56  "-k",
57  "--key-only",
58  action="store_true",
59  help="Show only the keys and not the difference",
60  )
61 
62  parser.add_argument(
63  "-d",
64  "--drop",
65  nargs="+",
66  default=None,
67  metavar="KEY",
68  help="Keys to drop from metadata retrieved from file. Separe nested dictionary keys using '.'. An '*' matches any key.",
69  )
70 
71  parser.add_argument(
72  "-m",
73  "--mode",
74  default="full",
75  metavar="MODE",
76  type=str,
77  choices=["tiny", "lite", "full", "peeker"],
78  help="""\
79  This flag provides the user capability to select the amount of
80  metadata retrieved. There are four options:
81  tiny (only those values used in PyJobTransforms),
82  lite
83  peeker
84  and full ( all available data found)
85  """,
86  )
87 
88  parser.add_argument(
89  "-t",
90  "--type",
91  default=None,
92  metavar="TYPE",
93  type=str,
94  choices=["POOL", "BS"],
95  help="""\
96  The file type of the input filename. By default, it tries to
97  determine itself the file type of the input.
98  """,
99  )
100 
101  parser.add_argument(
102  "-f",
103  "--filter",
104  default=[],
105  metavar="FILTER",
106  nargs="+",
107  type=str,
108  help="Expression to select specific metadata fields to retrieve.",
109  )
110 
111  parser.add_argument(
112  "-x",
113  "--diff-format",
114  default="simple",
115  type=str,
116  choices=["simple", "diff"],
117  help="Switch between 'simple' or 'diff' style differences ",
118  )
119 
120  parser.add_argument(
121  "--promote",
122  default=None,
123  type=bool,
124  help="Force promotion or not of the metadata keys ",
125  )
126 
127  parser.add_argument(
128  "--ignoreTrigger",
129  action='store_true',
130  help="Ignore trigger metadata",
131  )
132 
133  args = parser.parse_args()
134 
135  if len(args.files) != 2:
136  print("you must supply two files to compare")
137  sys.exit(1)
138 
139  for file_name in args.files:
140  if not os.path.exists(file_name):
141  print("File does not exists: {}".format(file_name))
142  sys.exit(1)
143 
144 
145  diff = meta_diff(
146  args.files,
147  verbose=args.verbose,
148  ordered=args.ordered,
149  drop=args.drop,
150  mode=args.mode,
151  meta_key_filter=args.filter,
152  file_type=args.type,
153  promote=args.promote,
154  diff_format=args.diff_format,
155  regex=args.regex,
156  key_only=args.key_only,
157  ignore_trigger=args.ignoreTrigger,
158  )
159 
160 
161  if diff:
162  print("\n".join(diff))
163  sys.exit(1)
164 
165  sys.exit(0)
166 
167 
168 if __name__ == "__main__":
169  main()
vtune_athena.format
format
Definition: vtune_athena.py:14
meta-diff.main
def main()
Definition: meta-diff.py:20
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.MetaDiff.meta_diff
def meta_diff(files, verbose=False, ordered=False, drop=None, mode="lite", meta_key_filter=None, file_type=None, promote=False, diff_format="simple", regex=False, key_only=False, ignore_trigger=False)
Definition: MetaDiff.py:280
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28