def generate_routines(self): s = 'import %s as IO\n\n' % TYPES_FILE[:-3] s += 'class %sImplementation:\n' % self.name s += '\tdef start_routine(self, config):\n\t\tpass\n\n' s += '\tdef synchronize(self, config):\n\t\tpass\n\n' s += '\tdef stop_routine(self):\n\t\tpass\n\n' for method in self.methods: s += '\tdef %s(self, request):\n'% method.name if method.inputMessage: s += "\t\t#request - object of IO.%s\n" % method.inputMessage.typeName else: s += "\t\t#request - None object \n" if method.outputMessage: s += '\t\t#response - object of IO.%s\n' % method.outputMessage.typeName else: s += '\t\t#response - None object\n' s += '\n\t\tpass\n\n' fname = os.path.join(self.app_path, ROUTINES_FILE) if os.path.exists(fname): sys.stdout.write('Warning: File %s is already exists. Write to %s.new\n' % (fname,fname)) fname += '.new' f = open(fname,'w') f.write(replace(s)) f.close()
def generate_tests(self): s = 'import unittest\n' s += 'import %s as types\n' % TYPES_FILE[:-3] s += 'from %s import *\n\n\n' % ROUTINES_FILE[:-3] s += 'class Test%s(unittest.TestCase):\n'%self.name for method in self.methods: s += '\tdef test_%s(self):\n' % method.name s += '\t\t#write code for testing %s routine\n\n'% method.name s += '\t\tpass\n\n' fname = os.path.join(self.app_path, TEST_FILE) if os.path.exists(fname): sys.stdout.write('Warning: File %s is already exists. Write to %s.new\n' % (fname,fname)) fname += '.new' f = open(fname,'w') f.write(replace(s)) f.close()
def generate_types(self): s = 'import soaplib\n' s += 'from soaplib.serializers.clazz import ClassSerializer\n' s += 'import soaplib.serializers.primitive as simple\n' s += 'import soaplib.serializers.binary as binary\n\n' for typedef in self.types: s += typedef.generate_code() s += '\n' for method in self.methods: if method.inputMessage: s += method.inputMessage.generate_code() s += "\n" if method.outputMessage: s += method.outputMessage.generate_code() s += "\n" f = open(os.path.join(self.app_path, TYPES_FILE),'w') f.write(replace(s)) f.close()
def generate_application(self): s = 'from %s import *\n' % TYPES_FILE[:-3] s += 'import %s\n' % ROUTINES_FILE[:-3] s += 'import WSGI\n' s += 'import soaplib\n' s += 'from soaplib.util import get_callback_info, get_stacktrace\n' s += 'from soaplib.client import make_service_client\n' s += 'from AsyncWorkManager import AsyncWorkQueue\n' s += 'from WSGI import soapmethod\n\n\n' s += 'class %s ( WSGI.SoapApplication ):\n' % self.name s += "\tdef start(self, config={}):\n\t\t''' init routine for web service'''\n" s += '\t\tself.__implementation = %s.%sImplementation()\n'%(ROUTINES_FILE[:-3], self.name) s += '\t\tself.__implementation.start_routine(config)\n' s += "\n\tdef synchronize(self, config):\n\t\t'''synchronize application cache and configuration'''\n\t\tself.__implementation.synchronize(config)\n" s += "\n\tdef stop(self):\n\t\t'''destroy routine for web service'''\n\t\tself.__implementation.stop_routine()\n" for method in self.methods: s += method.generate_code('\t') s += '\n' f = open(os.path.join(self.app_path, APP_FILE),'w') f.write(replace(s)) f.close()