[pygccxml-commit] SF.net SVN: pygccxml:[1445] ui
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-10-22 22:49:31
|
Revision: 1445 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1445&view=rev Author: roman_yakovenko Date: 2008-10-22 21:55:39 +0000 (Wed, 22 Oct 2008) Log Message: ----------- adding initial web interface, based on web.py project Added Paths: ----------- ui/ ui/web/ ui/web/code_generator.py ui/web/config.py ui/web/forms.py ui/web/main.py ui/web/static/ ui/web/static/favicon.ico ui/web/templates/ ui/web/templates/generated.html ui/web/templates/generated_tmpl.html ui/web/templates/generator.html ui/web/templates/generator_tmpl.html ui/web/web.zip Property changes on: ui/web ___________________________________________________________________ Added: svn:ignore + config.pyc code_generator.pyc forms.pyc main.pyc Added: ui/web/code_generator.py =================================================================== --- ui/web/code_generator.py (rev 0) +++ ui/web/code_generator.py 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,54 @@ +import os +import config +from pygccxml import parser +from pyplusplus import _logging_ +from pygccxml import declarations +from pyplusplus import module_builder + +class manager_t: + def __init__( self ): + pass + + def show_declarations( self, source_code ): + try: + reader = parser.source_reader_t( config=config.gccxml ) + decls = reader.read_string( source_code ) + global_ns = declarations.get_global_namespace( decls ) + tmp = [] + declarations.print_declarations( decls, verbose=False, writer=lambda x: tmp.append( x ) ) + return '\n'.join( tmp ) + except Exception, error: + user_msg = [ 'Error occured during code generation process!' ] + user_msg.append( 'Error:' ) + user_msg.append( str( error ) ) + return '\n'.join( user_msg ) + + + def generate_pypp_code( self, source_code ): + return "import pyplusplus" + + def generate_bpl_code( self, source_code ): + try: + _logging_.loggers.make_inmemory() + + f = parser.create_text_fc( source_code ) + mb = module_builder.module_builder_t( [ f ] + , gccxml_path=config.gccxml.gccxml_path ) + mb.decls( header_dir=config.temp_dir ).include() + mb.build_code_creator( "pyplusplus" ) + code = mb.code_creator.create() + code = code.replace( '\n\r', '\n' ) + code = code.replace( '\r\n', '\n' ) + warnings = _logging_.loggers.stream.getvalue() + _logging_.loggers.stream.close() + return code, warnings + except Exception, error: + user_msg = [ 'Error occured during code generation process!' ] + user_msg.append( 'Error:' ) + user_msg.append( str( error ) ) + return '\n'.join( user_msg ) + +if __name__ == '__main__': + m = manager_t() + m.generate_bpl_code( 'int do_smth( int &);int do_smth( int, int);' ) + Added: ui/web/config.py =================================================================== --- ui/web/config.py (rev 0) +++ ui/web/config.py 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,26 @@ +import os +import sys +import getpass +import tempfile + +this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) +projects_root_dir = os.path.dirname( os.path.dirname( this_module_dir_path ) ) + +sys.path.insert( 0, os.path.join( this_module_dir_path, 'web.zip' ) ) + +if os.path.exists( os.path.join( projects_root_dir, 'pygccxml_dev' ) ): + sys.path.append( os.path.join( projects_root_dir, 'pygccxml_dev' ) ) +if os.path.exists( os.path.join( projects_root_dir, 'pyplusplus_dev' ) ): + sys.path.append( os.path.join( projects_root_dir, 'pyplusplus_dev' ) ) +#else use installed modules + +from pygccxml import parser +from pyplusplus import module_builder + +gccxml_path = os.path.join( projects_root_dir, 'gccxml_bin', 'v09', sys.platform, 'bin' ) +if os.path.exists( gccxml_path ): + gccxml = parser.config_t( gccxml_path=gccxml_path ) +else: #use gccxml from PATH + gccxml = parser.config_t() + +temp_dir = tempfile.gettempdir() Added: ui/web/forms.py =================================================================== --- ui/web/forms.py (rev 0) +++ ui/web/forms.py 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,96 @@ +import config +import web + +class Label(web.form.Input): + tmpl = """<label name="%(name)s" %(atts)s>%(value)s</label>%(note)s""" + def render(self): + value = '' + if self.value is not None: + value = web.net.websafe(self.value) + return self.tmpl % dict( name=web.net.websafe(self.name) + , value=value + , atts=self.addatts() + , note=self.rendernote(self.note) ) + +class RawHTML(web.form.Input): + def __init__(self, html, *validators, **attrs): + web.form.Input.__init__( self, '', *validators, **attrs ) + self.__html = html + def render(self): + return self.__html + +class SimpleForm( web.form.Form ): + tmpl = """<form %(attrs)s>\n%(inputs)s\n</form>\n""" + def __init__(self, *inputs, **kw): + web.form.Form.__init__( self, *inputs, **kw ) + self.__kw = kw + self.__kw.pop( 'validators', None ) + + def render_addattrs( self ): + attrs = [] + for (n, v) in self.__kw.iteritems(): + attrs.append( ' %s="%s"' % (n, web.net.websafe(v)) ) + return ''.join( attrs ) + + def render( self ): + controls = [] + controls.append( self.rendernote(self.note) ) + for i in self.inputs: + if i.pre: + controls.append( i.pre ) + controls.append( i.render() ) + if i.post: + controls.append( i.post ) + return self.tmpl % dict( attrs=self.render_addattrs(), inputs='\n'.join( controls ) ) + + +""" + <form action="/generated.html" method="post" id="SourceCodeForm" style="width:80%; float:left;"> + <label>Source code:</label> + <br/> + <textarea name="source_code" rows="20" style="width:100%;"></textarea> + <br/> + <input type="submit" name="show_decls" value="Show declarations" /> + <a></a> + <input type="submit" name="generate_bp" value="Generate Boost.Python code" /> + <a></a> + <input type="submit" name="generate_pypp" value="Generate Py++ code" /> + </form> +""" + + +class generator_t( SimpleForm ): + def __init__( self, action, code_generator=None, method='post' ): + self.__code_generator = code_generator + self.__show_decls = web.form.Button( 'Show declarations', type="submit" ) + self.__generate_bpl_code = web.form.Button( 'Generate Boost.Python code', type="submit" ) + self.__generate_pypp_code = web.form.Button( 'Generate Py++ code', id="generate_pypp_code", type="submit" ) + self.__source_code = web.form.Textarea( "source_code", rows="20", style="width:100%;") + SimpleForm.__init__( self + , Label( 'source_code', value="Source code:" ) + , RawHTML( '<br/>' ) + , self.__source_code + , RawHTML( '<br/>' ) + , self.__show_decls + , RawHTML( '<a></a>' ) + , self.__generate_bpl_code + , RawHTML( '<a></a>' ) + , self.__generate_pypp_code + , action=action + , method=method + , style="width:80%; float:left;" ) + + def process( self, request_data ): + warnings = '' + generated = '' + source_code = request_data[ self.__source_code.name] + if self.__show_decls.name in request_data: + generated = self.__code_generator.show_declarations( source_code ) + elif self.__generate_pypp_code.name in request_data: + generated = self.__code_generator.generate_pypp_code( source_code ) + elif self.__generate_bpl_code.name in request_data: + generated, warnings = self.__code_generator.generate_bpl_code( source_code ) + else: + generated = 'error - unknown submit action' + return generated, warnings + Added: ui/web/main.py =================================================================== --- ui/web/main.py (rev 0) +++ ui/web/main.py 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,27 @@ +import config + +import sys +import web +import forms +import code_generator + +urls = ( "/", "generator" + , '/generator.html', 'generator' + , '/generated.html', 'generated' ) + +render = web.template.render('templates/') + +class generator: + def GET(self, name=None): + form = forms.generator_t(action='/generated.html') + return render.generator(form) + +class generated: + def POST(self, r_url=None ): + form = forms.generator_t( action='', code_generator=code_generator.manager_t() ) + generated, warnings = form.process( web.input() ) + return render.generated(generated, warnings) + +if __name__ == '__main__': + app = web.application(urls, globals(), autoreload=True) + app.run() Added: ui/web/static/favicon.ico =================================================================== (Binary files differ) Property changes on: ui/web/static/favicon.ico ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: ui/web/templates/generated.html =================================================================== --- ui/web/templates/generated.html (rev 0) +++ ui/web/templates/generated.html 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,35 @@ +$def with (code, warnings) +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <title>pygccxml & py++ demo - generated code</title> +</head> +<body> + <h2>pygccxml & py++ demo - generated code</h2> + <span style="width:80%; float:left;"> + <label>Generated code:</label> + <br/> + <textarea name="generated_code" rows="20" readonly="true" style="width:100%;">$:code</textarea> + </span> + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100%;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100%;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> + <span style="width:100%;"> + <br/> + <label>Warnings:</label> + <br/> + <textarea name="warnings" rows="15" readonly="true" style="width:100%;">$:warnings</textarea> + </span> +</body> +</html> Added: ui/web/templates/generated_tmpl.html =================================================================== --- ui/web/templates/generated_tmpl.html (rev 0) +++ ui/web/templates/generated_tmpl.html 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <title>pygccxml & py++ demo - generated code</title> +</head> +<body> + <h2>pygccxml & py++ demo - generated code</h2> + <span style="width:80%; float:left;"> + <label>Generated code</label> + <br/> + <textarea name="generated_code" rows="20" readonly="true" style="width:100%;">hihi</textarea> + </span> + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> +</body> +</html> Added: ui/web/templates/generator.html =================================================================== --- ui/web/templates/generator.html (rev 0) +++ ui/web/templates/generator.html 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,25 @@ +$def with (generator_form) +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <title>pygccxml & py++ demo</title> +</head> +<body> + <h2>pygccxml & py++ demo</h2> + $:generator_form.render() + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> +</body> +</html> Added: ui/web/templates/generator_tmpl.html =================================================================== --- ui/web/templates/generator_tmpl.html (rev 0) +++ ui/web/templates/generator_tmpl.html 2008-10-22 21:55:39 UTC (rev 1445) @@ -0,0 +1,34 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <title>pygccxml & py++ demo</title> +</head> +<body> + <h2>pygccxml & py++ demo</h2> + <form action="/generated.html" method="post" id="SourceCodeForm" style="width:80%; float:left;"> + <label>Source code:</label> + <br/> + <textarea name="source_code" rows="20" style="width:100%;"></textarea> + <br/> + <input type="submit" name="show_decls" value="Show declarations" /> + <a></a> + <input type="submit" name="generate_bp" value="Generate Boost.Python code" /> + <a></a> + <input type="submit" name="generate_pypp" value="Generate Py++ code" /> + </form> + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> +</body> +</html> Added: ui/web/web.zip =================================================================== (Binary files differ) Property changes on: ui/web/web.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |