Belle II Software  release-06-01-15
cli_upload.py
1 #!/usr/bin/env python3
2 
3 
10 
11 """
12 Script to upload local database to ConditionsDB.
13 
14 This script takes a local database file and will upload all payloads defined in
15 this file to the ConditionsDB and create iovs for each payload. It assumes that
16 all tags already exist.
17 """
18 
19 from basf2 import LogInfo, LogLevel, logging
20 
21 
22 def command_upload(args, db=None):
23  """
24  Upload a local database to the conditions database.
25 
26  This command allows uploading a local database which was created by basf2 to
27  the central database. It assumes that the globaltag already exists so
28  please create it before if necessary using 'tag create'.
29 
30  The command requires the tagname to upload the payloads to and a
31  database.txt containing the payloads and their iovs. One can supply a
32  directory where to look for the payloads, by default they are assumed to be
33  in the same directory as the database text file.
34  """
35 
36  if db is None:
37  args.add_argument("tag", metavar="TAGNAME",
38  help="globaltag to use for iov creation")
39  args.add_argument("payloadsfile", metavar="PAYLOADSFILE",
40  help="Testing payload storage file containing list of iovs")
41  normalize_group = args.add_mutually_exclusive_group()
42  normalize_group.add_argument('--normalize', dest="normalize", default=False, action="store_true",
43  help="Normalize the payload files to have reproducible checksums. "
44  "This option should only be used if the payload files were created "
45  "with an older software version (before release-04)")
46  normalize_group.add_argument('--normalize-name', type=str,
47  help="Set the file name in the root file metadata to the given value. "
48  "This implicitly enables ``--normalize`` and should only be used if "
49  "the payload files were created with an older software version (before release-04)")
50  args.add_argument("-j", type=int, default=1, dest="nprocess",
51  help="Number of concurrent connections to use for database "
52  "connection (default: %(default)s)")
53  args.add_argument("--retries", type=int, default=3,
54  help="Number of retries on connection problems (default: "
55  "%(default)s)")
56  args.add_argument("--ignore-existing", action="store_true", default=False,
57  help="Don't check if payloads or iovs already exist in database. "
58  "Speeds up initialization as the list of existing payloads "
59  "doesn't need to be downloaded. Can be used on first upload "
60  "but the script cannot resume an upload if this option is given")
61  return
62 
63  # modify logging to remove the useless module: lines
64  for level in LogLevel.values.values():
65  logging.set_info(level, LogInfo.LEVEL | LogInfo.MESSAGE | LogInfo.TIMESTAMP)
66 
67  # do the upload
68  normalize = args.normalize_name if args.normalize_name is not None else args.normalize
69  return 0 if db.upload(args.payloadsfile, args.tag, normalize, args.ignore_existing, args.nprocess) else 1