3 if __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')
14 opts, args = parser.parse_args()
21 good_defect_regex = re.compile(
'^[A-Za-z0-9_]*$')
28 if line ==
'' or line[0] ==
'#':
30 linep = line.partition(
' ')
31 comment = linep[2].strip()
33 print(
'Missing comment:', line)
35 defect = linep[0].strip()
36 if not good_defect_regex.match(defect):
37 print(
'Invalid defect name:', defect)
39 tocreate.append((defect, comment))
41 from DQDefects
import DefectsDB
42 from DQDefects.exceptions
import DefectExistsError
43 ddb = DefectsDB(opts.db, create=opts.create, read_only=
False)
45 print(
'Now creating defects on', opts.db)
46 for defect, comment
in tocreate:
48 print(
'Creating', defect, comment)
49 ddb.create_defect(defect,comment)
50 except DefectExistsError:
52 print(
'Defect', defect,
'already exists; ignoring')