#NEWLINE# def main( ) : #NEWLINE# #INDENT# import os.path #NEWLINE# import argparse #NEWLINE# from argparse import ArgumentParser #NEWLINE# opener = URLOpener ( ) #NEWLINE# def get_spec( value ) : #NEWLINE# #INDENT# if ( value not in SPECS ) : #NEWLINE# #INDENT# raise argparse . ArgumentTypeError ( 'Unknown specification' ) #NEWLINE# #UNINDENT# spec_cls = SPECS [ value ] #NEWLINE# if os . path . exists ( ( value + '.xml' ) ) : #NEWLINE# #INDENT# logger . info ( "using local specification: '%s.xml'" , value ) #NEWLINE# return spec_cls . from_file ( ( value + '.xml' ) ) #NEWLINE# #UNINDENT# logger . info ( "getting '%s' specification from SVN" , value ) #NEWLINE# return spec_cls . from_svn ( opener = opener ) #NEWLINE# #UNINDENT# def ext_file( value ) : #NEWLINE# #INDENT# msg = 'Invalid extensions argument' #NEWLINE# if os . path . exists ( value ) : #NEWLINE# #INDENT# msg = 'Invalid extensions file' #NEWLINE# try : #NEWLINE# #INDENT# with open ( value , 'r' ) as f : #NEWLINE# #INDENT# return f . read ( ) . split ( ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return [ v . strip ( ) for v in value . split ( ',' ) if v ] #NEWLINE# #UNINDENT# raise argparse . ArgumentTypeError ( msg ) #NEWLINE# #UNINDENT# def version( value ) : #NEWLINE# #INDENT# if ( ( value is None ) or ( len ( value . strip ( ) ) == 0 ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# v = value #NEWLINE# if ( '.' not in v ) : #NEWLINE# #INDENT# v = '{}.0' . format ( v ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return Version ( * map ( int , v . split ( '.' ) ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# raise argparse . ArgumentTypeError ( 'Invalid version: "{}"' . format ( value ) ) #NEWLINE# #UNINDENT# def cmdapi( value ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return dict ( ( ( p [ 0 ] , version ( p [ 1 ] ) ) for p in ( list ( map ( str . strip , e . split ( '=' ) ) ) for e in filter ( bool , map ( str . strip , value . split ( ',' ) ) ) ) ) ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# raise argparse . ArgumentTypeError ( 'Invalid api-string: "{}"' . format ( value ) ) #NEWLINE# #UNINDENT# description = __doc__ #NEWLINE# parser = ArgumentParser ( description = description ) #NEWLINE# parser . add_argument ( '--profile' , dest = 'profile' , choices = [ 'core' , 'compatibility' ] , default = 'compatibility' , help = 'OpenGL profile (defaults to compatibility)' ) #NEWLINE# parser . add_argument ( '--out-path' , dest = 'out' , required = True , help = 'Output path for loader' ) #NEWLINE# parser . add_argument ( '--api' , dest = 'api' , type = cmdapi , help = 'API type/version pairs, like "gl=3.2,gles=", no version means latest' ) #NEWLINE# parser . add_argument ( '--generator' , dest = 'generator' , default = 'd' , choices = [ 'c' , 'c-debug' , 'd' , 'nim' , 'volt' ] , required = True , help = 'Language to generate the binding for' ) #NEWLINE# parser . add_argument ( '--extensions' , dest = 'extensions' , default = None , type = ext_file , help = 'Path to extensions file or comma separated list of extensions, if missing all extensions are included' ) #NEWLINE# parser . add_argument ( '--spec' , dest = 'spec' , default = 'gl' , choices = [ 'gl' , 'egl' , 'glx' , 'wgl' ] , help = 'Name of the spec' ) #NEWLINE# parser . add_argument ( '--no-loader' , dest = 'no_loader' , action = 'store_true' ) #NEWLINE# parser . add_argument ( '--quiet' , dest = 'quiet' , action = 'store_true' ) #NEWLINE# ns = parser . parse_args ( ) #NEWLINE# if ( not ns . quiet ) : #NEWLINE# #INDENT# logging . basicConfig ( format = '[%(asctime)s][%(levelname)s\t][%(name)-7s\t]: %(message)s' , datefmt = '%m/%d/%Y %H:%M:%S' , level = logging . DEBUG ) #NEWLINE# #UNINDENT# spec = get_spec ( ns . spec ) #NEWLINE# if ( spec . NAME == 'gl' ) : #NEWLINE# #INDENT# spec . profile = ns . profile #NEWLINE# #UNINDENT# api = ns . api #NEWLINE# if ( ( api is None ) or ( len ( api . keys ( ) ) == 0 ) ) : #NEWLINE# #INDENT# api = { #NEWLINE# #INDENT# spec . NAME : None , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ( generator_cls , loader_cls ) = glad . lang . get_generator ( ns . generator , spec . NAME . lower ( ) ) #NEWLINE# if ( loader_cls is None ) : #NEWLINE# #INDENT# return parser . error ( 'API/Spec not yet supported' ) #NEWLINE# #UNINDENT# loader = loader_cls ( api ) #NEWLINE# loader . disabled = ns . no_loader #NEWLINE# logger . info ( "generating '%s' bindings" , cmdapi . NAME ) #NEWLINE# with generator_cls ( ns . out , spec , api , ns . extensions , loader = loader , opener = opener ) as generator : #NEWLINE# #INDENT# generator . generate ( ) #NEWLINE# #UNINDENT# logger . info ( "generating '%s' bindings - done" , spec . NAME )