forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_doc.py
executable file
·86 lines (77 loc) · 3.22 KB
/
check_doc.py
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
#!/usr/bin/python
# Check that driver documentation pages are consistent with driver capabilities
import os
from osgeo import gdal
doc_source = os.path.join(os.path.dirname(os.path.dirname(__file__)), "doc", "source")
map_doc_caps = {}
for subdir in ("raster", "vector"):
dirname = os.path.join(doc_source, "drivers", subdir)
for f in os.listdir(dirname):
filename = os.path.join(dirname, f)
shortnames = []
supports_create = False
supports_createcopy = False
for l in open(filename, "rt").readlines():
if l.startswith(".. shortname:: "):
shortnames.append(l[len(".. shortname:: ") : -1])
elif "supports_create::" in l:
supports_create = True
elif "supports_createcopy::" in l:
supports_createcopy = True
for shortname in shortnames:
d = {}
if supports_create:
d["supports_create"] = True
if supports_createcopy:
d["supports_createcopy"] = True
if shortname.upper() in map_doc_caps:
assert subdir == "vector"
map_doc_caps["OGR_" + shortname.upper()] = d
else:
map_doc_caps[shortname.upper()] = d
for i in range(gdal.GetDriverCount()):
drv = gdal.GetDriver(i)
shortname = drv.ShortName
if shortname in ("BIGGIF", "GTX", "NULL", "GNMFile", "GNMDatabase", "HTTP"):
continue
if shortname == "OGR_GMT":
shortname = "GMT"
if shortname == "OGR_OGDI":
shortname = "OGDI"
if shortname == "NWT_GRC":
# mixed in same page as NWT_GRD, which confuses our logic
continue
if shortname == "SQLite":
# sqlite.rst and rasterlite2.rst declare both SQLite driver name,
# which confuses our logic
continue
if shortname in ("OpenFileGDB", "NGW"):
# one page in vector and another one in raster, which confuses our logic
continue
assert shortname.upper() in map_doc_caps, drv.ShortName
doc_caps = map_doc_caps[shortname.upper()]
if drv.GetMetadataItem(gdal.DCAP_CREATE):
if shortname == "PDF":
continue # Supports Create() but in a very specific mode, hence better not advertizing it
assert (
"supports_create" in doc_caps
), f"Driver {shortname} declares DCAP_CREATE but doc does not!"
else:
if shortname == "HDF4":
continue # This is actually the HDF4Image
assert (
"supports_create" not in doc_caps
), f"Driver {shortname} does not declare DCAP_CREATE but doc does!"
if drv.GetMetadataItem(gdal.DCAP_CREATECOPY):
if shortname == "WMTS":
continue # Supports CreateCopy() but in a very specific mode, hence better not advertizing it
assert (
"supports_createcopy" in doc_caps
), f"Driver {shortname} declares DCAP_CREATECOPY but doc does not!"
else:
if not drv.GetMetadataItem(gdal.DCAP_CREATE):
if shortname == "JP2MrSID":
continue # build dependent
assert (
"supports_createcopy" not in doc_caps
), f"Driver {shortname} does not declare DCAP_CREATECOPY but doc does!"