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