| ... | ... |
@@ -64,6 +64,8 @@ Usage: |
| 64 | 64 |
glregistry params-tree [<group>] |
| 65 | 65 |
glregistry audit [<path>] |
| 66 | 66 |
glregistry audit-tree [<path>] |
| 67 |
+ glregistry refs <name> |
|
| 68 |
+ glregistry refs-all <name> |
|
| 67 | 69 |
glregistry -h|--help |
| 68 | 70 |
|
| 69 | 71 |
Commands: |
| ... | ... |
@@ -115,6 +117,11 @@ Commands: |
| 115 | 117 |
Search files in <path> if given, or the current directory if omitted, |
| 116 | 118 |
recursively for OpenGL API names and print them sorted on support, name, |
| 117 | 119 |
and location, in a tree. |
| 120 |
+ refs <name> |
|
| 121 |
+ Print the URLs of all reference pages with name <name>. |
|
| 122 |
+ refs-all <name> |
|
| 123 |
+ Print the URLs of all reference pages that mention <name>, sorted on |
|
| 124 |
+ support, in a tree. |
|
| 118 | 125 |
|
| 119 | 126 |
Environment variables: |
| 120 | 127 |
GLREGISTRY_CACHE |
| ... | ... |
@@ -27,6 +27,8 @@ Usage: |
| 27 | 27 |
glregistry params-tree [<group>] |
| 28 | 28 |
glregistry audit [<path>] |
| 29 | 29 |
glregistry audit-tree [<path>] |
| 30 |
+ glregistry refs <name> |
|
| 31 |
+ glregistry refs-all <name> |
|
| 30 | 32 |
glregistry -h|--help |
| 31 | 33 |
|
| 32 | 34 |
Commands: |
| ... | ... |
@@ -78,6 +80,11 @@ Commands: |
| 78 | 80 |
Search files in <path> if given, or the current directory if omitted, |
| 79 | 81 |
recursively for OpenGL API names and print them sorted on support, name, |
| 80 | 82 |
and location, in a tree. |
| 83 |
+ refs <name> |
|
| 84 |
+ Print all URLs of all reference pages with name <name>. |
|
| 85 |
+ refs-all <name> |
|
| 86 |
+ Print all URLs of all reference pages that mention <name>, sorted on |
|
| 87 |
+ support, in a tree. |
|
| 81 | 88 |
|
| 82 | 89 |
Environment variables: |
| 83 | 90 |
GLREGISTRY_CACHE |
| ... | ... |
@@ -109,7 +116,9 @@ import lxml.etree |
| 109 | 116 |
|
| 110 | 117 |
|
| 111 | 118 |
## Constants |
| 119 |
+REFPAGES_URL = 'https://registry.khronos.org/OpenGL-Refpages/' |
|
| 112 | 120 |
REGISTRY_URL = 'https://registry.khronos.org/OpenGL/' |
| 121 |
+REFPAGES_GIT = 'https://github.com/KhronosGroup/OpenGL-Refpages' |
|
| 113 | 122 |
XML_PATH = 'xml/gl.xml' |
| 114 | 123 |
REGEX = r'\b(gl|GL_)[0-9A-Z][0-9A-Za-z_]+\b' |
| 115 | 124 |
EXCLUDE_DIRS = ['.?*', '_*'] |
| ... | ... |
@@ -470,6 +479,49 @@ def audit_tree(xml, path=None): |
| 470 | 479 |
]) |
| 471 | 480 |
|
| 472 | 481 |
|
| 482 |
+### `refs_` |
|
| 483 |
+def refs_(name): |
|
| 484 |
+ local = os.path.join(CACHE, os.path.basename(REFPAGES_GIT)) |
|
| 485 |
+ if not os.path.exists(local): |
|
| 486 |
+ os.makedirs(os.path.dirname(local), exist_ok=True) |
|
| 487 |
+ subprocess.run(['git', 'clone', REFPAGES_GIT, local]) |
|
| 488 |
+ refs_ = collections.defaultdict(set) |
|
| 489 |
+ for file, *_ in grep(local, rf'\b{name}\b', [], [], True):
|
|
| 490 |
+ file = removeprefix(f'{local}{os.path.sep}', file)
|
|
| 491 |
+ try: |
|
| 492 |
+ support, *_, dir, base = os.path.normpath(file).split(os.path.sep) |
|
| 493 |
+ except: |
|
| 494 |
+ continue |
|
| 495 |
+ if support.startswith('gl') and dir.endswith('html'):
|
|
| 496 |
+ support = removeprefix('gl', support)
|
|
| 497 |
+ name, ext = os.path.splitext(base) |
|
| 498 |
+ url = urllib.parse.urljoin(REFPAGES_URL, file) |
|
| 499 |
+ if ext in ['.xml', '.xhtml']: |
|
| 500 |
+ refs_[support].add((name, url)) |
|
| 501 |
+ return refs_ |
|
| 502 |
+ |
|
| 503 |
+ |
|
| 504 |
+### `refs` |
|
| 505 |
+def refs(name): |
|
| 506 |
+ return sorted( |
|
| 507 |
+ url |
|
| 508 |
+ for support, locations in refs_(name).items() |
|
| 509 |
+ for name_, url in locations |
|
| 510 |
+ if name_ == name |
|
| 511 |
+ ) |
|
| 512 |
+ |
|
| 513 |
+ |
|
| 514 |
+### `refs_all` |
|
| 515 |
+def refs_all(name): |
|
| 516 |
+ for support, locations in sorted(refs_(name).items()): |
|
| 517 |
+ yield indentjoin(0, ',', [support]) |
|
| 518 |
+ for name_, url in sorted(locations): |
|
| 519 |
+ yield indentjoin(1, ':', [ |
|
| 520 |
+ name_, |
|
| 521 |
+ url, |
|
| 522 |
+ ]) |
|
| 523 |
+ |
|
| 524 |
+ |
|
| 473 | 525 |
## Main |
| 474 | 526 |
def main(): |
| 475 | 527 |
args = docopt.docopt(__doc__) |
| ... | ... |
@@ -492,6 +544,8 @@ def main(): |
| 492 | 544 |
if args['params-tree']: page(params_tree (xml_(), args['<group>'])) |
| 493 | 545 |
if args['audit']: page(audit (xml_(), args['<path>'])) |
| 494 | 546 |
if args['audit-tree']: page(audit_tree (xml_(), args['<path>'])) |
| 547 |
+ if args['refs']: page(refs (args['<name>'])) |
|
| 548 |
+ if args['refs-all']: page(refs_all (args['<name>'])) |
|
| 495 | 549 |
|
| 496 | 550 |
|
| 497 | 551 |
if __name__ == '__main__': |