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
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/env python3
#
# Copyright (C) 2013-2019 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
#
import re
import sys
def checkdriverimpls(filename):
intable = False
mainprefix = None
errs = False
with open(filename, "r") as fh:
lineno = 0
for line in fh:
lineno = lineno + 1
if intable:
if "}" in line:
intable = False
mainprefix = None
continue
m = re.search(r'''\.(\w+)\s*=\s*(\w+),?''', line)
if m is not None:
api = m.group(1)
impl = m.group(2)
if api in ["no", "name"]:
continue
if impl in ["NULL"]:
continue
suffix = impl
prefix = re.sub(r'''^([a-z]+)(.*?)$''', r'''\1''', impl)
if mainprefix is not None:
if mainprefix != prefix:
print(("%s:%d Bad prefix '%s' for API '%s', " +
"expecting '%s'") %
(filename, lineno, prefix, api, mainprefix),
file=sys.stderr)
errs = True
else:
mainprefix = prefix
if not api.startswith(mainprefix):
suffix = re.sub(r'''^[a-z]+''', "", suffix)
suffix = re.sub(r'''^([A-Z]+)''',
lambda m: m.group(1).lower(), suffix)
if api != suffix:
want = api
if want.startswith("nwf"):
want = "NWF" + want[3:]
if not api.startswith(mainprefix):
want = re.sub(r'''^([a-z])''',
lambda m: m.group(1).upper(), want)
want = mainprefix + want
print(("%s:%d Bad impl name '%s' for API " +
"'%s', expecting '%s'") %
(filename, lineno, impl, api, want),
file=sys.stderr)
errs = True
else:
m = re.search(r'''^(?:static\s+)?(vir(?:\w+)?Driver)''' +
r'''\s+(?!.*;)''', line)
if m is not None:
drv = m.group(1)
if drv in [
"virNWFilterCallbackDriver",
"virNWFilterTechDriver",
"virConnectDriver"]:
continue
intable = True
return errs
status = 0
for filename in sys.argv[1:]:
if checkdriverimpls(filename):
status = 1
sys.exit(status)
|