📄 wsdl2biws.py
字号:
from optparse import OptionParserfrom BiWsdlBiJsStubCodeGen import *from BiWsdlBiWs2StubCodeGen import *from BiWsdlBiAppCodeGen import *from BiWsdl import *import loggingimport sysVERSION_INFO = "Wsdl2BiWs 1.0"Wsdl2BiWsLogger = logging.getLogger("Wsdl2BiWsLogger")def setupOptionsParser(): lParser = OptionParser(version=VERSION_INFO) lParser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Display additional diagnostic messages.") lParser.add_option("-c", "--comments", action="store", dest="engine.comments", choices=["none", "default"], help="Specify type of comments to generate in stub code.") lParser.add_option("-b", "--bindows", action="store", dest="app.bindowspath", help="Set the path of the Bindows installation (default ../bindows).") lParser.add_option("-t", "--calltype", action="store", choices=["async", "sync", "both"], dest="engine.calltype", help="Set type of calls to generate in stub.") lParser.add_option("-s", "--service", action="append", dest="services", help="Generate specific services.") lParser.add_option("-o", "--out", action="store", dest="engine.output", help="Override default output file.") lParser.add_option("-a", "--app", action="store", dest="app.output", help="Generate a sample application using the web service.") lParser.add_option("--nolaunch", action="store_true", dest="nolaunch", help="Don't launch generated sample application.") lParser.add_option("--oldws", action="store_true", dest="oldws", help="Use the old BiWebService component as basis for the stub. This is not compatible with Mozilla.") return lParser if __name__=="__main__": lFmt = logging.Formatter("%(message)s") lHandler = logging.StreamHandler(sys.stdout) lHandler.setFormatter(lFmt) logging.getLogger().addHandler(lHandler) logging.getLogger().setLevel(logging.INFO) try: # Parse options lParser = setupOptionsParser() (lCommandLineOptions, lInputFile) = lParser.parse_args() if len(lInputFile)<>1: lParser.print_help() sys.exit(0) Wsdl2BiWsLogger.info(VERSION_INFO) if lCommandLineOptions.verbose: logging.getLogger().setLevel(logging.DEBUG) logging.disable(logging.NOTSET) # Prepare engine config options lDefaultOutput = re.search("([^\\./\\\\]+)(\.[^/\\\\\\\\.]*)*$", lInputFile[0]).group(1)+".js"; lEngineConfig = {} if not lEngineConfig.has_key("output"): lEngineConfig["output"]=lDefaultOutput for lKey in lCommandLineOptions.__dict__.keys(): if lKey.startswith("engine.") and lCommandLineOptions.__dict__[lKey]: lEngineConfig[lKey[7:]]=lCommandLineOptions.__dict__[lKey] # Get WSDL file and load BiWsdl Wsdl2BiWsLogger.info("Loading definitions...") lWsdl = None try: lWsdl = BiWsdl(lInputFile[0]) except Exception,e: print "Could not load '" + lInputFile[0] + "':", e sys.exit(2) # Prepare code gen aggregator lCodeGenAgg = BiWsdlCodeGenEngineAggregator() # Setup stub codegen engine, with default output options, and apply config if lCommandLineOptions.oldws: lStubGenEngine = BiWsdlBiJsStubCodeGen() else: lStubGenEngine = BiWsdlBiWs2StubCodeGen() lCodeGenAgg.addEngine(lStubGenEngine) Wsdl2BiWsLogger.debug("Applying stub codegen config.") lStubGenEngine.applyConfig(lEngineConfig) Wsdl2BiWsLogger.debug("Generating script to file " + lStubGenEngine.getOutput()) lAppCodeGen = None # Setup app codegen engine if necessary if lCommandLineOptions.__dict__["app.output"]: lAppCodeGen = BiWsdlBiAppCodeGen(lInputFile[0], lStubGenEngine.getOutput()) lCodeGenAgg.addEngine(lAppCodeGen) for lKey in lCommandLineOptions.__dict__.keys(): if lKey.startswith("app.") and lCommandLineOptions.__dict__[lKey]: lEngineConfig[lKey[4:]]=lCommandLineOptions.__dict__[lKey] Wsdl2BiWsLogger.debug("Applying app codegen config.") lAppCodeGen.applyConfig(lEngineConfig) lAppCodeGen.setOldws(lCommandLineOptions.oldws) if os.path.abspath(os.path.dirname(lAppCodeGen.getOutput())) <> os.path.abspath(os.path.dirname(lStubGenEngine.getOutput())): raise Exception("Sample application and stub output must reside in the same path.") Wsdl2BiWsLogger.debug("Generating app to file " + lAppCodeGen.getOutput()) # Get list of services to process, and make sure it's valie if not lCommandLineOptions.services: lCommandLineOptions.services=lWsdl.getServices().getNames() else: for lServName in lCommandLineOptions.services: if not lWsdl.getServices().getDefinition(lServName): print "Invalid service name " + lServName sys.exit(1) # Start generation Wsdl2BiWsLogger.info("Starting code generation...") lCodeGenAgg.startGen() # Generate services. for lServName in lCommandLineOptions.services: Wsdl2BiWsLogger.debug("Generating code for service " + lServName) lService = lWsdl.getServices().getDefinition(lServName) lCodeGenAgg.generateService(lService) # End generation Wsdl2BiWsLogger.debug("Finalizing code generation...") lCodeGenAgg.endGen() Wsdl2BiWsLogger.info("Code generation done.") if lAppCodeGen and not lCommandLineOptions.__dict__["nolaunch"]: Wsdl2BiWsLogger.info("Launching test application.") os.system("start " + lAppCodeGen.getLaunchTarget()) except Exception, e: Wsdl2BiWsLogger.error(str(e)) sys.exit(100)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -