def main() : from pluggdapps import loadpackages loadpackages() # This is important, otherwise plugins in other packages # will not be detected. argparser = mainoptions() options = argparser.parse_args() pa = Pluggdapps.boot( None ) # Initialize plugins setts = { 'lex_debug' : int( options.debug ), 'yacc_debug' : int( options.debug ), 'debug' : True, } compiler = pa.qp( pa, ISettings, 'tayra.ttlcompiler', settings=setts ) if options.version : print( tayra.__version__ ) elif options.test : from tayra.test.teststd import test_stdttl print( "Executing TTL tests ..." ) setts['beautify_html'] = False compiler = pa.qp( pa, ISettings, 'tayra.ttlcompiler', settings=setts ) test_stdttl( compiler, options ) elif options.ttllex and options.ttlfile : print( "Lexing file %r ..." % options.ttlfile ) lexical( pa, options ) elif options.dump and options.ttlfile : print( "Parsing and dumping file %r ..." % options.ttlfile ) ast = yaccer( pa, options, debuglevel=int(options.debug) ) dumptext = ast.dump( context=Context() ) text = open( options.ttlfile, encoding='utf-8-sig' ).read() if dumptext != text : open( 'dump', 'w' ).write( dumptext ) open( 'text', 'w' ).write( text ) assert False print( "Dump of AST matches the original text :)") elif options.show and options.ttlfile : print( "Parsing and describing file %r ..." % options.ttlfile ) ast = yaccer( pa, options, debuglevel=int(options.debug) ) ast.show() elif options.ttlfile and isfile( options.ttlfile ) : print( "Translating file %r ..." % options.ttlfile ) tayra.translatefile( options.ttlfile, compiler, options )
def main(): from pluggdapps import loadpackages loadpackages() # This is important, otherwise plugins in other packages # will not be detected. argparser = mainoptions() options = argparser.parse_args() pa = Pluggdapps.boot(None) # Initialize plugins setts = { 'lex_debug': int(options.debug), 'yacc_debug': int(options.debug), 'debug': True, } compiler = pa.qp(pa, ISettings, 'tayra.ttlcompiler', settings=setts) if options.version: print(tayra.__version__) elif options.test: from tayra.test.teststd import test_stdttl print("Executing TTL tests ...") setts['beautify_html'] = False compiler = pa.qp(pa, ISettings, 'tayra.ttlcompiler', settings=setts) test_stdttl(compiler, options) elif options.ttllex and options.ttlfile: print("Lexing file %r ..." % options.ttlfile) lexical(pa, options) elif options.dump and options.ttlfile: print("Parsing and dumping file %r ..." % options.ttlfile) ast = yaccer(pa, options, debuglevel=int(options.debug)) dumptext = ast.dump(context=Context()) text = open(options.ttlfile, encoding='utf-8-sig').read() if dumptext != text: open('dump', 'w').write(dumptext) open('text', 'w').write(text) assert False print("Dump of AST matches the original text :)") elif options.show and options.ttlfile: print("Parsing and describing file %r ..." % options.ttlfile) ast = yaccer(pa, options, debuglevel=int(options.debug)) ast.show() elif options.ttlfile and isfile(options.ttlfile): print("Translating file %r ..." % options.ttlfile) tayra.translatefile(options.ttlfile, compiler, options)
def test_stdttl(compiler, options): for f in sorted(os.listdir(STDTTLDIR)): if any([f.endswith(x) for x in skipttls]): continue if f.endswith('.ttl'): print(f, ' ...', end='') ttlfile = join(STDTTLDIR, f) options.context = contexts.get(f, '{}') translatefile(ttlfile, compiler, options) pyfile = ttlfile + '.py' htmlfile = join(STDTTLDIR, f.split('.', 1)[0] + '.html') refpyfile = join(STDTTLREFDIR, f + '.py') refhtmlfile = join(STDTTLREFDIR, f.split('.', 1)[0] + '.html') # os.system( 'diff %s %s' % (htmlfile, refhtmlfile) ) if f in ['templaterule.ttl']: continue try: #assert open( pyfile ).read() == open( refpyfile ).read() assert open(htmlfile).read() == open(refhtmlfile).read() except: raise else: print('ok')
def test_stdttl( compiler, options ) : for f in sorted( os.listdir( STDTTLDIR )) : if any([ f.endswith( x ) for x in skipttls ]) : continue if f.endswith('.ttl') : print( f, ' ...', end='' ) ttlfile = join(STDTTLDIR, f) options.context = contexts.get(f, '{}') translatefile( ttlfile, compiler, options ) pyfile = ttlfile + '.py' htmlfile = join( STDTTLDIR, f.split('.', 1)[0]+'.html' ) refpyfile = join( STDTTLREFDIR, f+'.py' ) refhtmlfile = join( STDTTLREFDIR, f.split('.', 1)[0]+'.html' ) # os.system( 'diff %s %s' % (htmlfile, refhtmlfile) ) if f in [ 'templaterule.ttl' ] : continue try : #assert open( pyfile ).read() == open( refpyfile ).read() assert open( htmlfile ).read() == open( refhtmlfile ).read() except : raise else : print( 'ok' )
def render() : tayra.translatefile( './tayra/template.ttl', compiler, options )