-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_frame_metadata.py
97 lines (69 loc) · 2.54 KB
/
add_frame_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
GridPP and DIRAC: adding CERN@school frame metadata.
"""
import os
#...for parsing the arguments.
import argparse
#...for the logging.
import logging as lg
# Import the JSON library.
import json
# The DIRAC imports.
from DIRAC.Core.Base import Script
Script.parseCommandLine()
from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
#...for the CERN@school dataset wrapper.
from cernatschool.dataset import Dataset
if __name__ == "__main__":
print("")
print("########################################")
print("* GridPP and DIRAC: add frame metadata *")
print("########################################")
print("")
# Get the datafile path from the command line.
parser = argparse.ArgumentParser()
parser.add_argument("jsonPath", help="Path to the input dataset's JSON.")
parser.add_argument("outputPath", help="The path for the output files.")
parser.add_argument("gridOutputDir", help="The name of the output directory on the DFC.")
parser.add_argument("-v", "--verbose", help="Increase output verbosity", action="store_true")
args = parser.parse_args()
## The path to the metadata JSON file.
datapath = args.jsonPath
## The output path.
outputpath = args.outputPath
# Check if the output directory exists. If it doesn't, quit.
if not os.path.isdir(outputpath):
raise IOError("* ERROR: '%s' output directory does not exist!" % (outputpath))
## The output directory on the DFC.
gridoutdir = args.gridOutputDir
# Set the logging level.
if args.verbose:
level=lg.DEBUG
else:
level=lg.INFO
# Configure the logging.
lg.basicConfig(filename='log_add_frame_metadata.log', filemode='w', level=level)
print("*")
print("* Input JSON : '%s'" % (datapath))
print("* Output path : '%s'" % (outputpath))
print("* DFC output dir. : '%s'" % (gridoutdir))
print("*")
## The frame properties JSON file - FIXME: check it exists...
ff = open(datapath, "r")
#
fd = json.load(ff)
ff.close()
## The File Catalog client object.
fc = FileCatalogClient()
# Loop over the frames and upload them to the DFC.
for f in fd:
## The file name.
fn = f["frameid"] + ".txt"
print("* Found : '%s'" % (fn))
## The full LFN for the datafile.
lfn = gridoutdir + "/" + fn
metadataresult = fc.setMetadata(lfn, f)
print("*--> '%s'" % (lfn))
print metadataresult