97 parser = argparse.ArgumentParser(description=
'This script reads metadata from a given file')
98 parser.add_argument(
'filenames',
100 help=
'The filenames to read. User can provide a single file or a list of files.')
101 parser.add_argument(
'-v',
104 help=
'print detailed output on screen')
105 parser.add_argument(
'-o',
109 help=
"Saves the output in a file. By default, the output is written on the screen (stdout) in a prettier format for better readabiilty.")
110 parser.add_argument(
'--json',
112 help=
"Sets the output file format as json.")
113 parser.add_argument(
'--indent',
117 help=
"Sets the indent spaces in the output either on screen (without -o flag) either on file (with -o flag). By default, uses two spaces as indent.")
118 parser.add_argument(
'-m',
123 choices=[
'tiny',
'lite',
'full',
'peeker',
'iov'],
124 help=
"This flag provides the user capability to select the amount of metadata retrieved. There are five options: "
125 "tiny (only those values used in PyJobTransforms), "
128 "full (all available data found), "
129 "and iov (full+iov details)" )
131 parser.add_argument(
'-t',
136 choices=[
'POOL',
'BS'],
137 help=
"The file type of the input filename. By default, it tries to determine itself the file type of the input.")
138 parser.add_argument(
'-f',
144 help=
"The metadata keys to filter. ")
145 parser.add_argument(
'--promote',
148 help=
"Force promotion or not of the metadata keys ")
149 parser.add_argument(
'--hideContentList',
151 help=
"Hide content lists (event-level and metadata containers)")
152 parser.add_argument(
'--hideTrigger',
154 help=
"Hide trigger metadata")
155 args = parser.parse_args()
157 verbose = args.verbose
158 filenames = args.filenames
163 file_type = args.type
164 meta_key_filter = args.filter
166 msg.setLevel(logging.INFO
if verbose
else logging.WARNING)
168 handler = logging.StreamHandler()
169 handler.setLevel(logging.INFO
if verbose
else logging.WARNING)
171 formatter = logging.Formatter(
'%(name)s %(levelname)s %(message)s')
172 handler.setFormatter(formatter)
174 msg.addHandler(handler)
176 startTime = time.time()
177 msg.info(
'Imported headers in: {0} miliseconds'.
format((time.time() - startTime) * 1e3))
178 msg.info(
'The output file is: {0}'.
format(output))
179 metadata =
read_metadata(filenames, file_type, mode= mode, meta_key_filter= meta_key_filter, promote=args.promote)
183 print(json.dumps(metadata, indent=indent))
185 enc = sys.stdout.encoding
186 ascii =
not sys.stdout.isatty()
or not enc
or enc.lower().
find(
'ansi') >= 0
or enc.lower().
find(
'ascii') >= 0
187 print(
_tree_print(metadata, indent=indent, pad=18, dict_sort=
'key', list_max_items=8, ascii=ascii,
188 hide_content=args.hideContentList, hide_trigger=args.hideTrigger))
192 with open(output,
'w')
as fd:
193 print(json.dumps(metadata, indent=indent), file=fd)
195 with open(output,
'w')
as fd:
196 print(
_tree_print(metadata, indent=indent, pad=18, dict_sort=
'key', list_max_items=8, ascii=
True,
197 hide_content=args.hideContentList, hide_trigger=args.hideTrigger),