summaryrefslogtreecommitdiffstats
path: root/bin/check-syntax
blob: c6005d22be2dc99ed806065a261e825fdc2ef85b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python

import os
import os.path
import string
import sys

def setup_paths():
    check_file = 'lib/python/debian_support.py'
    path = os.getcwd()
    while 1:
        if os.path.exists("%s/%s" % (path, check_file)):
            sys.path = [path + '/lib/python'] + sys.path
            return path
        idx = string.rfind(path, '/')
        if idx == -1:
            raise ImportError, "could not setup paths"
        path = path[0:idx]
root_path = setup_paths()

import bugs

def do_parse(f):
    names = {}
    errors = False
    for r in f:
        n = r.name
        if n[0:4] in ('CAN', 'CVE'):
            n = n[4:]
        if names.has_key(n):
            if names[n] <> r.name:
                sys.stderr.write("error: duplicate CVE entry: %s and %s\n"
                                 % (names[n], r.name))
            else:
                sys.stderr.write("error: duplicate CVE entry: %s\n"
                                 % r.name)
            errors = True
        names[n] = r.name
    if errors:
        sys.exit(1)
    

def parse_CAN(name):
    do_parse(bugs.CVEFile(name))

def parse_CVE(name):
    f = bugs.CVEFile(name)
    # Relax syntax checking a bit.
    f.no_version_needs_note = False
    do_parse(f)

def parse_DSA(name):
    do_parse(bugs.DSAFile(name))

def parse_DTSA(name):
    do_parse(bugs.DTSAFile(name))

file_types = {'CAN' : parse_CAN,
              'CVE' : parse_CVE,
              'DSA' : parse_DSA,
              'DTSA' : parse_DTSA}

if len(sys.argv) <> 3 or not file_types.has_key(sys.argv[1]):
    l = file_types.keys()
    l.sort()
    sys.stderr.write("usage: check-syntax {%s} file-name\n"
                     % '|'.join(l))
    sys.exit(1)

file_types[sys.argv[1]](sys.argv[2])

© 2014-2024 Faster IT GmbH | imprint | privacy policy