summaryrefslogtreecommitdiffstats
path: root/bin/check-syntax
blob: 2daaeaefdea754b0ec3d7a22c6d9f72f869a2f8f (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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
import debian_support

def do_parse(f):
    names = {}
    errors = False
    try:
        for r in f:
            n = r.name
            if n[0:4] in ('CAN', 'CVE'):
                n = n[4:]
            if n in names:
                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
    except debian_support.ParseError as e:
        e.printOut(sys.stderr)
        errors = True
    if errors:
        sys.exit(1)

def construct(c, name):
    if name == '-':
        f = sys.stdin
        name = '<stdin>'
    else:
        f  = open(name)
    return c(name, f)

sources = debian_support.getconfig()["sources"]

def find_source(name):
    for source in sources:
        if source["name"] == name:
            return source

    return None

def parse_file(name, filename):
    source = find_source(name)
    cls = source["class"]
    cls = getattr(bugs, cls)
    f = construct(cls, filename)

    if cls == bugs.CVEFile:
        # Relax syntax checking a bit.
        f.no_version_needs_note = False

    do_parse(f)

if len(sys.argv) == 2 and sys.argv[1] == "--get":
    l = [src["name"] for src in sources]
    print(' '.join(l))
    sys.exit(0)

if len(sys.argv) != 3 or find_source(sys.argv[1]) == None:
    l = [src["name"] for src in sources]
    l.sort()
    sys.stderr.write("usage: check-syntax {%s} file-name\n"
                     % '|'.join(l))
    sys.exit(1)

parse_file(sys.argv[1], sys.argv[2])

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