update_metadata.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import json
5 import samweb_client as swc
6 
7 def update_info(flist, md):
8  nfiles = len(flist)
9  ith = 0
10  for f in flist:
11  sys.stdout.write("{}/{} Updating Metadata for: {}\n".format(ith, nfiles, f))
12  sys.stdout.flush()
13  sam.modifyFileMetadata(f,md)
14  ith += 1
15  print("-- Done")
16  return
17 
18 
19 if __name__ == '__main__':
20  import argparse
21  parser = argparse.ArgumentParser(
22  prog='update_metadata.py',
23  description="Update one metadata field for multiple files matching SAM dimensions.",
24  epilog="")
25  parser.add_argument('-d', '--dimensions', type=str, help="SAM dimensions")
26  parser.add_argument('-m', '--metadata', type=json.loads, help="metadata to be updated")
27  parser.add_argument('-f', '--filejson', type=string, help="Json file containing metadata to be updated")
28  args = parser.parse_args()
29 
30  sam = swc.SAMWebClient("dune")
31 
32  flist=sam.listFiles(args.dimensions)
33  print("%d files matching dimension." % (len(flist)))
34  if args.metadata is not None:
35  update_info(flist, args.metadata)
36  return
37  if args.metadata is None and args.file is not None:
38  with open(args.filejson) as fjson:
39  update_info(flist, json.loads(fjson))
40  return
int open(const char *, int)
Opens a file descriptor.
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
def update_info(flist, md)