/[secure-testing]/bin/update-db
ViewVC logotype

Contents of /bin/update-db

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2155 - (show annotations) (download)
Sat Sep 24 15:35:43 2005 UTC (7 years, 8 months ago) by fw
File size: 1699 byte(s)
bin/update-db:
  Improve reporting of syntax errors.
1 #!/usr/bin/python
2
3 import os
4 import os.path
5 import string
6 import sys
7
8 def setup_paths():
9 check_file = 'lib/python/debian_support.py'
10 path = os.getcwd()
11 while 1:
12 if os.path.exists("%s/%s" % (path, check_file)):
13 sys.path = [path + '/lib/python'] + sys.path
14 return path
15 idx = string.rfind(path, '/')
16 if idx == -1:
17 raise ImportError, "could not setup paths"
18 path = path[0:idx]
19 os.chdir(setup_paths())
20
21 import bugs
22 import debian_support
23 import security_db
24
25 db_file = 'data/security.db'
26 try:
27 db = security_db.DB(db_file, verbose=True)
28 new_file = False
29 except security_db.SchemaMismatch:
30 os.unlink(db_file)
31 db = security_db.DB(db_file, verbose=True)
32 new_file = True
33
34 cursor = db.writeTxn()
35
36 # Bug lists (CAN/CVE/DSA/DTSA)
37
38 try:
39 warnings = db.readBugs(cursor, 'data')
40 except SyntaxError, e:
41 if e.filename is None or e.lineno is None:
42 print "error:", e
43 else:
44 print "%s:%d: %s" % (e.filename, e.lineno, e.msg)
45 sys.exit(1)
46 except debian_support.ParseError, e:
47 e.printOut(sys.stderr)
48 sys.exit(1)
49 except security_db.InsertError, e:
50 for err in e.errors:
51 print err
52 sys.exit(1)
53 if warnings:
54 for x in warnings:
55 print x
56 sys.exit(1)
57
58 # Packages
59
60 db.readPackages(cursor, 'data/packages')
61
62 if new_file:
63 db.commit(cursor)
64 cursor = db.writeTxn()
65
66 # Removed packages
67
68 db.readRemovedPackages(cursor, 'data/packages/removed-packages')
69
70 # Calculate vulnerability information.
71
72 warnings = db.calculateVulnerabilities(cursor)
73 if warnings:
74 for x in warnings:
75 print x
76 sys.exit(1)
77
78 # Everything worked well.
79
80 db.commit(cursor)

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5