350 argparser = argparse.ArgumentParser(
'Parse arguments')
351 argparser.add_argument(
'--infile',help=
'path to input file',required=
True,type=str)
352 argparser.add_argument(
'--declare',help=
'validate and declare the metadata for the file specified in --infile to SAM',action=
'store_true')
353 argparser.add_argument(
'--appname',help=
'application name for SAM metadata',type=str)
354 argparser.add_argument(
'--appversion',help=
'application version for SAM metadata',type=str)
355 argparser.add_argument(
'--appfamily',help=
'application family for SAM metadata',type=str)
356 argparser.add_argument(
'--campaign',help=
'Value for DUNE.campaign for SAM metadata',type=str)
357 argparser.add_argument(
'--data_stream',help=
'Value for data_stream for SAM metadata',type=str)
358 argparser.add_argument(
'--requestid',help=
'Value for DUNE.requestid for SAM metadata',type=str)
359 argparser.add_argument(
'--set_processed',help=
'Set for parent file as processed in SAM metadata',action=
"store_true")
360 argparser.add_argument(
'--strip_parents',help=
'Do not include the file\'s parents in SAM metadata for declaration',action=
"store_true")
361 argparser.add_argument(
'--no_crc',help=
'Leave the crc out of the generated json',action=
"store_true")
362 argparser.add_argument(
'--skip_dumper',help=
'Skip running sam_metadata_dumper on the input file',action=
"store_true")
363 argparser.add_argument(
'--input_json',help=
'Input json file containing metadata to be added to output (can contain ANY valid SAM metadata parameters)',type=str)
366 args = argparser.parse_args()
372 expSpecificMetadata =
expMetaData(os.environ[
'SAM_EXPERIMENT'], args.infile)
373 mddict = expSpecificMetadata.getmetadata()
375 if args.input_json !=
None:
376 if os.path.exists(args.input_json):
378 injson=
open(args.input_json)
379 arbjson = json.load(injson)
380 for key
in list(arbjson.keys()):
381 mddict[key] = arbjson[key]
383 print(
'Error loading input json file.')
386 print(
'Error, specified input file does not exist.')
389 if 'application' in mddict
and 'name' not in list(mddict[
'application'].
keys())
and args.appname !=
None:
390 mddict[
'application'][
'name'] = args.appname
391 if 'application' in mddict
and 'version' not in list(mddict[
'application'].
keys())
and args.appversion !=
None:
392 mddict[
'application'][
'version'] = args.appversion
393 if 'application' in mddict
and 'family' not in list(mddict[
'application'].
keys())
and args.appfamily !=
None:
394 mddict[
'application'][
'family'] = args.appfamily
395 if args.appfamily !=
None and args.appname !=
None and args.appversion !=
None:
396 mddict[
'application'] = {}
397 mddict[
'application'][
'family'] = args.appfamily
398 mddict[
'application'][
'name'] = args.appname
399 mddict[
'application'][
'version'] = args.appversion
400 if 'DUNE.campaign' not in list(mddict.keys())
and args.campaign !=
None:
401 mddict[
'DUNE.campaign'] = args.campaign
402 if args.data_stream !=
None:
403 mddict[
'data_stream'] = args.data_stream
404 if args.requestid !=
None:
405 mddict[
'DUNE.requestid'] = args.requestid
408 print(
'You have not implemented a defineMetaData function by providing an experiment.')
409 print(
'No metadata keys will be saved')
412 mdtext = json.dumps(mddict, indent=2, sort_keys=
True)
415 ih.declareFile(mdtext)
417 if args.set_processed:
418 swc = samweb_client.SAMWebClient(
'dune')
419 moddict = {
"DUNE.production_status" :
"processed" }
420 for parent
in moddict[
'parents']:
421 fname = moddict[
'parents'][parent][
'file_name']
423 swc.modifyFileMetadata(fname, moddict)
425 print(
'Error modidying metadata for %s' % fname)
int open(const char *, int)
Opens a file descriptor.