[pygccxml-commit] SF.net SVN: pygccxml:[1566] ui/web
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2009-01-13 15:36:50
|
Revision: 1566
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1566&view=rev
Author: roman_yakovenko
Date: 2009-01-13 15:36:40 +0000 (Tue, 13 Jan 2009)
Log Message:
-----------
more changes to WEB UI
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/decl_printer.py
pyplusplus_dev/unittests/ctypes_pof_tester.py
ui/web/code_generator.py
ui/web/config.py
ui/web/forms.py
ui/web/main.py
ui/web/templates/generated_tmpl.html
Added Paths:
-----------
ui/web/wizard.py
Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -259,7 +259,8 @@
def visit_variable(self ):
self.print_decl_header()
curr_level = self.level + 1
- self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) + os.linesep)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s' % self.__inst.type.decl_string + os.linesep)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + 'value: %s' % self.__inst.value + os.linesep)
if self.__print_details:
byte_size = 'size: %d'%(self.__inst.type.byte_size)
self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep)
Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py
===================================================================
--- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -141,15 +141,15 @@
udt = self.module_ref.create()
self.failUnless( 1977 == self.module_ref.read_user_data(udt) )
self.module_ref.destroy( udt )
-
-
+
+
def create_suite():
suite = unittest.TestSuite()
if 'win' in sys.platform:
suite.addTest( unittest.makeSuite(pof_tester_t))
suite.addTest( unittest.makeSuite(issues_tester_t))
- #suite.addTest( unittest.makeSuite(enums_tester_t))
+ suite.addTest( unittest.makeSuite(enums_tester_t))
suite.addTest( unittest.makeSuite(opaque_tester_t))
return suite
Modified: ui/web/code_generator.py
===================================================================
--- ui/web/code_generator.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ ui/web/code_generator.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -6,34 +6,33 @@
from pyplusplus import module_builder
class manager_t:
- def __init__( self ):
- pass
- def show_declarations( self, source_code ):
+ def show_declarations( self, file_configuration ):
try:
- reader = parser.source_reader_t( config=config.gccxml )
- decls = reader.read_string( source_code )
+ reader = parser.project_reader_t( config=config.gccxml )
+ decls = reader.read_files( [file_configuration] )
global_ns = declarations.get_global_namespace( decls )
tmp = []
- declarations.print_declarations( decls, verbose=False, writer=lambda x: tmp.append( x ) )
- return '\n'.join( tmp )
+ declarations.print_declarations( decls, verbose=False, writer=lambda x: tmp.append( x.rstrip() ) )
+ print os.linesep.join( tmp )
+ return os.linesep.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 )
+ return '', '\n'.join( user_msg )
def generate_pypp_code( self, source_code ):
return "import pyplusplus"
- def generate_bpl_code( self, source_code ):
+ def generate_bpl_code( self, file_configuration ):
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 = module_builder.module_builder_t( [ file_configuration ]
+ , gccxml_path=config.gccxml.gccxml_path
+ , compiler=config.gccxml.compiler)
mb.decls( header_dir=config.temp_dir ).include()
mb.build_code_creator( "pyplusplus" )
code = mb.code_creator.create()
@@ -41,12 +40,12 @@
code = code.replace( '\r\n', '\n' )
warnings = _logging_.loggers.stream.getvalue()
_logging_.loggers.stream.close()
- return code, warnings
+ 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 )
+ return '', '\n'.join( user_msg )
if __name__ == '__main__':
m = manager_t()
Modified: ui/web/config.py
===================================================================
--- ui/web/config.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ ui/web/config.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -10,16 +10,16 @@
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' ) ):
+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
+#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 )
+ gccxml = parser.config_t( gccxml_path=gccxml_path, compiler='msvc71' )
else: #use gccxml from PATH
gccxml = parser.config_t()
Modified: ui/web/forms.py
===================================================================
--- ui/web/forms.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ ui/web/forms.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -1,12 +1,13 @@
import config
import web
-import textcha
+from pygccxml import parser
+import wizard
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:
+ if self.value is not None:
value = web.net.websafe(self.value)
return self.tmpl % dict( name=web.net.websafe(self.name)
, value=value
@@ -43,49 +44,79 @@
if i.post:
controls.append( i.post )
return self.tmpl % dict( attrs=self.render_addattrs(), inputs='\n'.join( controls ) )
-
-
-class generator_t( SimpleForm ):
- def __init__( self, action, code_generator=None, method='post' ):
+
+
+class generator_t:
+ def __init__( self, code_generator, input ):
+ self.__input = input
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%")
- self.__textcha_question = web.form.Hidden( "textcha_question", value=textcha.random_question(), style="width:60%;", id='textcha-question')
- self.__textcha_answer = web.form.Textbox( "textcha_answer", value="", style="width:40%;", maxlength="120", id='textcha-answer')
- SimpleForm.__init__( self
- , Label( 'source_code', value="Source code:" )
- , RawHTML( '<br/>' )
- , self.__source_code
- , RawHTML( '<br/>' )
- , self.__textcha_question
- , Label( 'textcha_question', value=self.__textcha_question.value )
- , self.__textcha_answer
- , RawHTML( '<br/><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 = ''
- if not textcha.is_human( request_data[ self.__textcha_question.name], request_data[ self.__textcha_answer.name] ):
- generated = warnings = "Please answer the question!"
- return generated, warnings
- 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 )
+ self.__handlers = {
+ "VIEW_XML" : self.on_view_xml
+ , "VIEW_DECLS" : self.on_view_decls
+ , "GENERATE_BP_CODE" : self.on_generate_bp_code
+ , "GENERATE_BP_PYPP_CODE" : self.on_generate_bp_pypp_code
+ , "GENERATE_CTYPES_CODE" : self.on_generate_ctypes_code
+ , "GENERATE_CTYPES_PYPP_CODE" : self.on_generate_ctypes_pypp_code
+ }
+
+ def __create_fc( self, prefix ):
+ fto_key = prefix + '_TAKE_CODE_FROM'
+ code_key = prefix + '_SOURCE_CODE'
+ file_key = prefix + '_FILE_NAME'
+ if self.__input[fto_key] == 'text':
+ return parser.create_text_fc( self.__input[ code_key ] )
else:
- generated = 'error - unknown submit action'
- return generated, warnings
-
+ return parser.create_source_fc( self.__input[ file_key ] )
+
+ def on_view_xml( self ):
+ fc = self.__create_fc( 'GCCXML' )
+ decls_tree, warnings = self.__code_generator.show_declarations( fc )
+ return decls_tree, warnings
+
+ def on_view_decls( self ):
+ fc = self.__create_fc( 'GCCXML' )
+ decls_tree, warnings = self.__code_generator.show_declarations( fc )
+ return decls_tree, warnings
+
+ def on_generate_bp_code( self ):
+ fc = self.__create_fc( 'BP' )
+ code, warnings = self.__code_generator.generate_bpl_code( fc )
+ return code, warnings
+
+ def on_generate_bp_pypp_code( self ):
+ w = wizard.wizard_t()
+ code = w.create_bpl_code( config.gccxml, self.__create_fc( 'BP' ) )
+ return code, ''
+
+ def on_generate_ctypes_code( self ):
+ pass
+
+ def on_generate_ctypes_pypp_code( self ):
+ pass
+
+ def not_found_handler( self ):
+ raise RuntimeError( 'Error - unknown submit action' )
+
+ def __select_handler( self ):
+ for key, handler in self.__handlers.iteritems():
+ if key in self.__input:
+ return handler
+ else:
+ return self.not_found_handler
+
+ def process( self ):
+ handler = self.__select_handler()
+ return handler()
+
+
+ #~ 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
+
Modified: ui/web/main.py
===================================================================
--- ui/web/main.py 2009-01-12 22:33:13 UTC (rev 1565)
+++ ui/web/main.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -21,9 +21,10 @@
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)
+ form = forms.generator_t( code_generator.manager_t(), web.input() )
+ generated_frender = web.template.frender('templates/generated_tmpl.html')
+ generated, warnings = form.process()
+ return generated_frender(generated, warnings)
if __name__ == '__main__':
app = web.application(urls, globals(), autoreload=True)
Modified: ui/web/templates/generated_tmpl.html
===================================================================
--- ui/web/templates/generated_tmpl.html 2009-01-12 22:33:13 UTC (rev 1565)
+++ ui/web/templates/generated_tmpl.html 2009-01-13 15:36:40 UTC (rev 1566)
@@ -1,28 +1,21 @@
-<!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>
+$def with ( generated_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>
+ <label>Generated code</label>
+ <br/>
+ <textarea name="generated_code" rows="20" cols="180" readonly="true">$generated_code</textarea>
+ <br/>
+ <label>Warnings and Errors</label>
+ <br/>
+ <textarea name="generated_code" rows="20" cols="180" readonly="true">$warnings</textarea>
+
+</body>
+</html>
Added: ui/web/wizard.py
===================================================================
--- ui/web/wizard.py (rev 0)
+++ ui/web/wizard.py 2009-01-13 15:36:40 UTC (rev 1566)
@@ -0,0 +1,81 @@
+"""generates Py++ code from the user data"""
+import os
+from pygccxml import parser
+
+BP_FILE_CODE_TEMPLATE = \
+"""
+import os
+from pyplusplus import module_builder
+
+#Creating an instance of class that will help you to expose your declarations
+mb = module_builder.module_builder_t( [r"%(file_name)s"]
+ , gccxml_path=r"%(gccxml_path)s"
+ , include_paths=%(include_paths)s
+ , define_symbols=%(define_symbols)s )
+
+#print all parsed declarations and some information about them
+mb.print_declarations()
+
+#Py++ has smart algorithm, which automaticly selects what declarations should be
+#exported, but of course you can change that.
+
+#building code creator. After this step you should not modify declarations.
+mb.build_code_creator( module_name='pyplusplus' )
+
+#writing code to file.
+mb.write_module( './bindings.cpp' )
+"""
+
+BP_TEXT_CODE_TEMPLATE = \
+r'''
+import os
+import tempfile
+from pygccxml import parser
+from pyplusplus import module_builder
+
+code = \
+"""
+%(text)s
+"""
+
+
+#Creating an instance of class that will help you to expose your declarations
+mb = module_builder.module_builder_t( [parser.create_text_fc(code)]
+ , gccxml_path=r"%(gccxml_path)s"
+ , include_paths=%(include_paths)s
+ , define_symbols=%(define_symbols)s )
+
+#print all parsed declarations and some information about them
+mb.print_declarations()
+
+#select all declarations from the code fragment and export them
+mb.decls( header_dir=tempfile.tempdir ).include()
+
+mb.add_declaration_code( code, tail=False )
+
+#building code creator. After this step you should not modify declarations.
+mb.build_code_creator( module_name='pyplusplus' )
+
+#writing code to file.
+mb.write_module( './bindings.cpp' )
+'''
+
+class wizard_t( object ):
+ """code generator that creates Py++ code"""
+ def __init__( self ):
+ object.__init__( self )
+
+ def create_bpl_code( self, gccxml_cfg, file_configuration ):
+ tmpl = None
+ substitute_dict = dict( gccxml_path=gccxml_cfg.gccxml_path
+ , include_paths=`gccxml_cfg.include_paths`
+ , define_symbols=`gccxml_cfg.define_symbols` )
+ if file_configuration.content_type == file_configuration.CONTENT_TYPE.TEXT:
+ global BP_TEXT_CODE_TEMPLATE
+ tmpl = BP_TEXT_CODE_TEMPLATE
+ substitute_dict['text'] = '\n'.join( [ line.rstrip() for line in file_configuration.data.split('\n') ] )
+ else:
+ global BP_FILE_CODE_TEMPLATE
+ tmpl = BP_FILE_CODE_TEMPLATE
+ substitute_dict['file_name'] = file_configuration.data
+ return tmpl % substitute_dict
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|