ATLAS Offline Software
Loading...
Searching...
No Matches
dq_defect_bulk_create_defects.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3if __name__ == '__main__':
4 import optparse, sys, re
5 parser = optparse.OptionParser()
6 parser.usage = 'Usage: %prog [options] inputfiles'
7 parser.add_option('--db', default='test_defects.db/COMP200',
8 help='Change database defects will be added to')
9 parser.add_option('--create', default=False, action='store_true',
10 help='Will create database if set')
11 parser.add_option('--ignoreold', default=False, action='store_true',
12 help='Ignore attempted redefinitions of existing defects')
13
14 opts, args = parser.parse_args()
15
16 if len(args) < 1:
17 parser.print_help()
18 sys.exit(1)
19
20 tocreate = []
21 good_defect_regex = re.compile('^[A-Za-z0-9_]*$')
22 for f in args:
23 infile = open(f, 'r')
24
25
26 for line in infile:
27 line = line.strip()
28 if line == '' or line[0] == '#':
29 continue
30 linep = line.partition(' ')
31 comment = linep[2].strip()
32 if comment == '':
33 print('Missing comment:', line)
34 sys.exit(1)
35 defect = linep[0].strip()
36 if not good_defect_regex.match(defect):
37 print('Invalid defect name:', defect)
38 sys.exit(1)
39 tocreate.append((defect, comment))
40
41 from DQDefects import DefectsDB
42 from DQDefects.exceptions import DefectExistsError
43 ddb = DefectsDB(opts.db, create=opts.create, read_only=False)
44
45 print('Now creating defects on', opts.db)
46 for defect, comment in tocreate:
47 try:
48 print('Creating', defect, comment)
49 ddb.create_defect(defect,comment)
50 except DefectExistsError:
51 if opts.ignoreold:
52 print('Defect', defect, 'already exists; ignoring')
53 else:
54 raise
void print(char *figname, TCanvas *c1)