def LoadTestHSLParser(dirTest): # Create the parser (hslFiles, importPath) = GetHSLTestFiles(dirTest) parser = HSLParser(importPath = importPath) # Parse the HSL files for hslFile in hslFiles: parser.parseFile(hslFile) parser.parseDone() return parser
def LoadTestHSLParser(dirTest): # Create the parser (hslFiles, importPath) = GetHSLTestFiles(dirTest) parser = HSLParser(importPath=importPath) # Parse the HSL files for hslFile in hslFiles: parser.parseFile(hslFile) parser.parseDone() return parser
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action="store", type="string", dest="outputFile", help="output file", metavar="FILE") cmdParser.add_option("-I", action="append", dest="importDirs", default=[], help="add directory to import path", metavar="DIR") # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") if cmdOptions.outputFile is None: cmdParser.error("Must specify output file") # Parse HSL files parser = HSLParser(cmdOptions.importDirs) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Generate HTML print >> sys.stderr, 'Generating "%s" ...' % cmdOptions.outputFile out = open(cmdOptions.outputFile, 'w') try: write_html(out.write, parser.getmodel()) except SystemExit: raise except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1) finally: out.close()
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action = "store", type = "string", dest = "outputFile", help = "output file", metavar = "FILE") cmdParser.add_option("-I", action = "append", dest = "importDirs", default = [], help = "add directory to import path", metavar = "DIR") # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") if cmdOptions.outputFile is None: cmdParser.error("Must specify output file") # Parse HSL files parser = HSLParser(cmdOptions.importDirs) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Generate HTML print >> sys.stderr, 'Generating "%s" ...' % cmdOptions.outputFile out = open(cmdOptions.outputFile, 'w') try: write_html(out.write, parser.getmodel()) except SystemExit: raise except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1) finally: out.close()
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action = "store", type = "string", dest = "outputDir", default = ".", help = "output directory", metavar = "DIR") cmdParser.add_option("-b", action = "store", type = "string", dest = "baseName", default = "hdk", help = "base file name (e.g. 'hdk')", metavar = "NAME") cmdParser.add_option("-i", action = "append", dest = "actionsInclusive", help = "include only specified actions", metavar = "ACTION") cmdParser.add_option("-x", action = "append", dest = "actionsExclusive", help = "exclude specified actions", metavar = "ACTION") cmdParser.add_option("-I", action = "append", dest = "importDirs", default = [], help = "add directory to import path", metavar = "DIR") # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") # Parse HSL files parser = HSLParser(cmdOptions.importDirs) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Include/exclude actions if cmdOptions.actionsExclusive is not None: parser.filterActions(cmdOptions.actionsExclusive, True) if not parser.errors and cmdOptions.actionsInclusive is not None: parser.filterActions(cmdOptions.actionsInclusive, False) if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Get the parsed actions, types and services model = parser.getmodel() if not model.actions: print >> sys.stderr, "Error: No actions defined" sys.exit(1) # Ensure the output directory exists if not os.path.isdir(cmdOptions.outputDir): try: os.makedirs(cmdOptions.outputDir) except: print >> sys.stderr, "Error: Couldn't create directory '%s'" % cmdOptions.outputDir sys.exit(1) # Generate code try: gen = WSDLGenerator(model, cmdOptions.baseName) gen.generate(cmdOptions.outputDir, sys.stdout) except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1)
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action="store", type="string", dest="outputDir", default=".", help="output directory", metavar="DIR") cmdParser.add_option("-b", action="store", type="string", dest="baseName", default="hdk", help="base file name (e.g. 'hdk')", metavar="NAME") cmdParser.add_option("-i", action="append", dest="actionsInclusive", help="include only specified actions", metavar="ACTION") cmdParser.add_option("-x", action="append", dest="actionsExclusive", help="exclude specified actions", metavar="ACTION") cmdParser.add_option("-I", action="append", dest="importDirs", default=[], help="add directory to import path", metavar="DIR") # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") # Parse HSL files parser = HSLParser(cmdOptions.importDirs) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Include/exclude actions if cmdOptions.actionsExclusive is not None: parser.filterActions(cmdOptions.actionsExclusive, True) if not parser.errors and cmdOptions.actionsInclusive is not None: parser.filterActions(cmdOptions.actionsInclusive, False) if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Get the parsed actions, types and services model = parser.getmodel() if not model.actions: print >> sys.stderr, "Error: No actions defined" sys.exit(1) # Ensure the output directory exists if not os.path.isdir(cmdOptions.outputDir): try: os.makedirs(cmdOptions.outputDir) except: print >> sys.stderr, "Error: Couldn't create directory '%s'" % cmdOptions.outputDir sys.exit(1) # Generate code try: gen = WSDLGenerator(model, cmdOptions.baseName) gen.generate(cmdOptions.outputDir, sys.stdout) except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1)
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action="store", type="string", dest="outputDir", default=".", help="output directory", metavar="DIR") cmdParser.add_option("-b", action="store", type="string", dest="baseName", default="hdk", help="base file name (e.g. 'hdk')", metavar="NAME") cmdParser.add_option("-I", action="append", dest="importDirs", default=[], help="add directory to import path", metavar="DIR") cmdParser.add_option("--action-include", action="append", dest="actionsInclusive", help="include only specified actions", metavar="ACTION") cmdParser.add_option("--action-exclude", action="append", dest="actionsExclusive", help="exclude specified actions", metavar="ACTION") cmdParser.add_option("--event-include", action="append", dest="eventsInclusive", help="include only specified events", metavar="EVENT") cmdParser.add_option("--event-exclude", action="append", dest="eventsExclusive", help="exclude specified events", metavar="EVENT") cmdParser.add_option("--noid", action="store", dest="noid", default=None, help="network object identifier (optional)") cmdParser.add_option("--friendly-name", action="store", dest="friendly_name", default=None, help="network object friendly name (optional)", metavar="NAME") cmdParser.add_option("--client", action="store_true", dest="client", default=False, help="generate client module"), cmdParser.add_option("--noauth", action="store_true", dest="noauth", default=False, help="set noauth attribute for all module actions"), cmdParser.add_option("--action-location", action="store", type="string", dest="actionLocation", default="/HNAP1", help="specify the module actions HTTP location", metavar="PATH") cmdParser.add_option("--dom-schema", action="store_true", dest="dom_schema", default=False, help="generate DOM schemas for user-defined structs") cmdParser.add_option("--server-methods", action="store_true", dest="server_methods", default=False, help="generate server method implementation file"), cmdParser.add_option("--adi-report", action="store_true", dest="adi_report", default=False, help="generate module ADI report"), # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") # Check we have a valid UUID. noid = None if cmdOptions.noid is not None: noid = uuid.UUID(cmdOptions.noid) # Parse HSL files parser = HSLParser(importPath=cmdOptions.importDirs, noauth=cmdOptions.noauth) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Include/exclude actions and events if cmdOptions.actionsInclusive is not None: parser.filterActions(cmdOptions.actionsInclusive, False) if cmdOptions.actionsExclusive is not None: parser.filterActions(cmdOptions.actionsExclusive, True) if cmdOptions.eventsInclusive is not None: parser.filterEvents(cmdOptions.eventsInclusive, False) if cmdOptions.eventsExclusive is not None: parser.filterEvents(cmdOptions.eventsExclusive, True) if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Get the parsed actions, types and services model = parser.getmodel() if not model.actions and not cmdOptions.dom_schema: print >> sys.stderr, "Error: No actions defined" sys.exit(1) # Ensure the output directory exists if not os.path.isdir(cmdOptions.outputDir): try: os.makedirs(cmdOptions.outputDir) except: print >> sys.stderr, "Error: Couldn't create directory '%s'" % cmdOptions.outputDir sys.exit(1) # Generate code try: gen = ModuleGenerator(model, cmdOptions.baseName, noid, cmdOptions.friendly_name, cmdOptions.actionLocation, cmdOptions.dom_schema, cmdOptions.server_methods, cmdOptions.client, cmdOptions.adi_report) gen.generate(cmdOptions.outputDir, sys.stdout) except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1)
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hnap...") cmdParser.add_option("-o", action = "store", type = "string", dest = "outputDir", default = ".", help = "output directory", metavar = "DIR") cmdParser.add_option("-b", action = "store", type = "string", dest = "baseName", default = "hdkcli", help = "base file name (e.g. 'hdk')", metavar = "NAME") cmdParser.add_option("--module-name", action = "store", type = "string", dest = "moduleName", default = "hdk", help = "name for module (schema) files", metavar = "MODULE") cmdParser.add_option("-I", action = "append", dest = "importDirs", default = [], help = "add directory to import path", metavar = "DIR") cmdParser.add_option("--action-include", action = "append", dest = "actionsInclusive", help = "include only specified HNAP actions", metavar = "ACTION") cmdParser.add_option("--action-exclude", action = "append", dest = "actionsExclusive", help = "exclude specified HNAP actions", metavar = "ACTION") cmdParser.add_option("--action-location", action = "store", type = "string", dest = "actionLocation", default = "/HNAP1", help = "specify the module actions HTTP location", metavar = "PATH") cmdParser.add_option("--dom-schema", action = "store_true", dest = "domSchema", default = False, help = "generate DOM schemas for user-defined structs") cmdParser.add_option("--no-inline", action = "store_true", dest = "noInline", default = False, help = "do not generate inline code") # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HNAP file") # Parse HNAP files parser = HSLParser(cmdOptions.importDirs) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Include/exclude HNAP actions if cmdOptions.actionsExclusive is not None: parser.filterActions(cmdOptions.actionsExclusive, True) if not parser.errors and cmdOptions.actionsInclusive is not None: parser.filterActions(cmdOptions.actionsInclusive, False) if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Get the parsed actions, types and services model = parser.getmodel() if not model.actions and not cmdOptions.domSchema: print >> sys.stderr, "Error: No actions defined" sys.exit(1) # Ensure the output directory exists if not os.path.isdir(cmdOptions.outputDir): try: os.makedirs(cmdOptions.outputDir) except: print >> sys.stderr, "Error: Couldn't create directory '%s'" % cmdOptions.outputDir sys.exit(1) # Generate code try: gen = CppClientGenerator(model, cmdOptions.baseName, cmdOptions.moduleName, cmdOptions.actionLocation, cmdOptions.domSchema, not cmdOptions.noInline) gen.generate(cmdOptions.outputDir, sys.stdout) except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1)
def main(): # Command line options cmdParser = optparse.OptionParser("usage: %prog [options] hsl...") cmdParser.add_option("-o", action = "store", type = "string", dest = "outputDir", default = ".", help = "output directory", metavar = "DIR") cmdParser.add_option("-b", action = "store", type = "string", dest = "baseName", default = "hdk", help = "base file name (e.g. 'hdk')", metavar = "NAME") cmdParser.add_option("-I", action = "append", dest = "importDirs", default = [], help = "add directory to import path", metavar = "DIR") cmdParser.add_option("--action-include", action = "append", dest = "actionsInclusive", help = "include only specified actions", metavar = "ACTION") cmdParser.add_option("--action-exclude", action = "append", dest = "actionsExclusive", help = "exclude specified actions", metavar = "ACTION") cmdParser.add_option("--event-include", action = "append", dest = "eventsInclusive", help = "include only specified events", metavar = "EVENT") cmdParser.add_option("--event-exclude", action = "append", dest = "eventsExclusive", help = "exclude specified events", metavar = "EVENT") cmdParser.add_option("--noid", action = "store", dest = "noid", default = None, help = "network object identifier (optional)") cmdParser.add_option("--friendly-name", action = "store", dest = "friendly_name", default = None, help = "network object friendly name (optional)", metavar = "NAME") cmdParser.add_option("--client", action = "store_true", dest = "client", default = False, help = "generate client module"), cmdParser.add_option("--noauth", action = "store_true", dest = "noauth", default = False, help = "set noauth attribute for all module actions"), cmdParser.add_option("--action-location", action = "store", type = "string", dest = "actionLocation", default = "/HNAP1", help = "specify the module actions HTTP location", metavar = "PATH") cmdParser.add_option("--dom-schema", action = "store_true", dest = "dom_schema", default = False, help = "generate DOM schemas for user-defined structs") cmdParser.add_option("--server-methods", action = "store_true", dest = "server_methods", default = False, help = "generate server method implementation file"), cmdParser.add_option("--adi-report", action = "store_true", dest = "adi_report", default = False, help = "generate module ADI report"), # Parse command line options (cmdOptions, cmdArgs) = cmdParser.parse_args() if cmdArgs is None or not cmdArgs: cmdParser.error("Must specify at least one HSL file") # Check we have a valid UUID. noid = None if cmdOptions.noid is not None: noid = uuid.UUID(cmdOptions.noid) # Parse HSL files parser = HSLParser(importPath = cmdOptions.importDirs, noauth = cmdOptions.noauth) for file in cmdArgs: parser.parseFile(file) parser.parseDone() if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Include/exclude actions and events if cmdOptions.actionsInclusive is not None: parser.filterActions(cmdOptions.actionsInclusive, False) if cmdOptions.actionsExclusive is not None: parser.filterActions(cmdOptions.actionsExclusive, True) if cmdOptions.eventsInclusive is not None: parser.filterEvents(cmdOptions.eventsInclusive, False) if cmdOptions.eventsExclusive is not None: parser.filterEvents(cmdOptions.eventsExclusive, True) if parser.errors: for error in parser.errors: print >> sys.stderr, error sys.exit(1) # Get the parsed actions, types and services model = parser.getmodel() if not model.actions and not cmdOptions.dom_schema: print >> sys.stderr, "Error: No actions defined" sys.exit(1) # Ensure the output directory exists if not os.path.isdir(cmdOptions.outputDir): try: os.makedirs(cmdOptions.outputDir) except: print >> sys.stderr, "Error: Couldn't create directory '%s'" % cmdOptions.outputDir sys.exit(1) # Generate code try: gen = ModuleGenerator(model, cmdOptions.baseName, noid, cmdOptions.friendly_name, cmdOptions.actionLocation, cmdOptions.dom_schema, cmdOptions.server_methods, cmdOptions.client, cmdOptions.adi_report) gen.generate(cmdOptions.outputDir, sys.stdout) except: print >> sys.stderr, "Error: An unexpected exception occurred generating code:" traceback.print_exc() sys.exit(1)