1#!/usr/bin/python3 2# 3# Copyright (c) 2020 The Khronos Group Inc. 4# 5# SPDX-License-Identifier: Apache-2.0 6"""Script to create symbolic links for aliases in reference pages 7 Usage: makemanaliases.py -refdir refpage-output-directory""" 8 9import argparse 10import os 11import sys 12 13if __name__ == '__main__': 14 parser = argparse.ArgumentParser() 15 16 parser.add_argument('-genpath', action='store', 17 default=None, 18 help='Path to directory containing generated *api.py module') 19 parser.add_argument('-refdir', action='store', 20 required=True, 21 help='Path to directory containing reference pages to symlink') 22 23 args = parser.parse_args() 24 25 # Look for api.py in the specified directory 26 if args.genpath is not None: 27 sys.path.insert(0, args.genpath) 28 import api 29 30 # Change to refpage directory 31 try: 32 os.chdir(args.refdir) 33 except: 34 print('Cannot chdir to', args.refdir, file=sys.stderr) 35 sys.exit(1) 36 37 # For each alias in the API alias map, create a symlink if it 38 # doesn't exist - and warn if it does exist. 39 40 for key in api.alias: 41 alias = key + '.html' 42 src = api.alias[key] + '.html' 43 44 if not os.access(src, os.R_OK): 45 # This shouldn't happen, but is possible if the api module isn't 46 # generated for the same set of APIs as were the refpages. 47 print('No source file', src, file=sys.stderr) 48 continue 49 50 if os.access(alias, os.R_OK): 51 # If the link already exists, that's not necc. a problem, so 52 # don't fail, but it should be checked out 53 print('Unexpected alias file "' + alias + '" exists, skipping', 54 file=sys.stderr) 55 else: 56 # Create link from alias refpage to page for what it's aliasing 57 os.symlink(src, alias) 58