Example #1
0
def main():
    import optparse
    parser = optparse.OptionParser('''usage: %prog [opts] <cmd> ...

 %prog validate <doc.json>
   Validate XPJSON document

 %prog simplify <doc.json> <out.json>
   Simplify XPJSON document (compile out inheritance, fill defaults)

 %prog import <doc.kml>
   Import a plan into the database. Supported formats: only KML for now.

    ''')
    parser.add_option('-s',
                      '--schema',
                      help='Schema to use when processing Plan or PlanLibrary')
    importOpts = optparse.OptionGroup(parser, 'Import-specific options')
    importOpts.add_option(
        '--formatCode',
        help=
        'Specify importer class by format code (default is to infer based on extension)'
    )
    importOpts.add_option('--creator',
                          help='Specify creator username [required]')
    importOpts.add_option('--planNumber',
                          type='int',
                          help='Specify plan number [required]')
    importOpts.add_option('--planVersion',
                          help='Specify plan version [required]')
    parser.add_option_group(importOpts)

    opts, args = parser.parse_args()

    if not args:
        parser.error('expected a command')
    cmd = args[0]

    if opts.schema is not None:
        schema = xpjson.loadDocument(opts.schema)
        if schema.type != 'PlanSchema':
            parser.error(
                '--schema must be the path to a XPJSON PlanSchema document')
    else:
        schema = None

    ######################################################################
    if cmd == 'validate':
        if len(args) != 2:
            parser.error('validate requires exactly 1 argument')
        docPath = args[1]

        try:
            doc = xpjson.loadDocument(docPath, schema)
            print 'VALID %s %s' % (doc.get('type'), docPath)
        except xpjson.NoSchemaError, t:
            parser.error(
                'you must specify the --schema argument to validate a document of type %s'
                % t)
        except:
Example #2
0
 def buildLibrary(planSchema):
     schema = xpjson.loadDocument(planSchema.schemaSource)
     library = xpjson.loadDocument(planSchema.librarySource,
                                   schema=schema,
                                   fillInDefaults=True)
     xpjson.dumpDocumentToPath(planSchema.simplifiedLibraryPath, library)
     print 'wrote simplified library for platform %s to %s' % (planSchema.platform, planSchema.simplifiedLibraryPath)
def test():
    schema = xpjson.loadDocument('fix')
    plan = xpjson.loadDocument('/Users/mfsmith3/projects/gds/xgds_isru/apps/xgds_kn/planner/plans/K10Black/20100802/HMP_B013A_PLAN-xp.json',
                               schema=schema)
    exporter = FillIdsPlanExporter()
    planDoc = exporter.exportPlan(plan, schema)
    open('/tmp/foo.json', 'wb').write(xpjson.dumpDocumentToString(planDoc))
def test():
    schema = xpjson.loadDocument('fix')
    plan = xpjson.loadDocument(
        '/Users/mfsmith3/projects/gds/xgds_isru/apps/xgds_kn/planner/plans/K10Black/20100802/HMP_B013A_PLAN-xp.json',
        schema=schema)
    exporter = FillIdsPlanExporter()
    planDoc = exporter.exportPlan(plan, schema)
    open('/tmp/foo.json', 'wb').write(xpjson.dumpDocumentToString(planDoc))
Example #5
0
 def buildLibrary(planSchema):
     schema = xpjson.loadDocument(planSchema.schemaSource)
     library = xpjson.loadDocument(planSchema.librarySource,
                                   schema=schema,
                                   fillInDefaults=True)
     xpjson.dumpDocumentToPath(planSchema.simplifiedLibraryPath, library)
     print 'wrote simplified library for platform %s to %s' % (
         planSchema.platform, planSchema.simplifiedLibraryPath)
Example #6
0
def main():
    import optparse

    parser = optparse.OptionParser(
        """usage: %prog [opts] <cmd> ...

 %prog validate <doc.json>
   Validate XPJSON document

 %prog simplify <doc.json> <out.json>
   Simplify XPJSON document (compile out inheritance, fill defaults)

 %prog import <doc.kml>
   Import a plan into the database. Supported formats: only KML for now.

    """
    )
    parser.add_option("-s", "--schema", help="Schema to use when processing Plan or PlanLibrary")
    importOpts = optparse.OptionGroup(parser, "Import-specific options")
    importOpts.add_option(
        "--formatCode", help="Specify importer class by format code (default is to infer based on extension)"
    )
    importOpts.add_option("--creator", help="Specify creator username [required]")
    importOpts.add_option("--planNumber", type="int", help="Specify plan number [required]")
    importOpts.add_option("--planVersion", help="Specify plan version [required]")
    parser.add_option_group(importOpts)

    opts, args = parser.parse_args()

    if not args:
        parser.error("expected a command")
    cmd = args[0]

    if opts.schema is not None:
        schema = xpjson.loadDocument(opts.schema)
        if schema.type != "PlanSchema":
            parser.error("--schema must be the path to a XPJSON PlanSchema document")
    else:
        schema = None

    ######################################################################
    if cmd == "validate":
        if len(args) != 2:
            parser.error("validate requires exactly 1 argument")
        docPath = args[1]

        try:
            doc = xpjson.loadDocument(docPath, schema)
            print "VALID %s %s" % (doc.get("type"), docPath)
        except xpjson.NoSchemaError, t:
            parser.error("you must specify the --schema argument to validate a document of type %s" % t)
        except:
Example #7
0
def loadDocument(path):
    """
    Return the result of xpjson.loadDocument(), but first setting some
    configuration we prefer for Astrobee.
    """
    xpjson.CHECK_UNKNOWN_FIELDS = False  # suppress some warnings
    xpjson.KEEP_PARAM_SPECS = True  # inhibit deletion of paramSpecs during load
    return xpjson.loadDocument(path)
Example #8
0
 def getSchema(self):
     if not self.schema:
         try:
             self.schema = xpjson.loadDocument(self.simplifiedSchemaPath)
         except:  # pylint: disable=W0702
             logging.warning('could not load XPJSON schema from ' + self.simplifiedSchemaPath)
             raise
     return self.schema
Example #9
0
 def getSchema(self):
     if not self.schema:
         try:
             self.schema = xpjson.loadDocument(self.simplifiedSchemaPath)
         except:  # pylint: disable=W0702
             logging.warning('could not load XPJSON schema from ' +
                             self.simplifiedSchemaPath)
             raise
     return self.schema
Example #10
0
 def getLibrary(self):
     if not self.library:
         try:
             self.library = xpjson.loadDocument(self.simplifiedLibraryPath,
                                                schema=self.getSchema(),
                                                fillInDefaults=True)
         except:  # pylint: disable=W0702
             logging.warning('could not load XPJSON library from ' + self.simplifiedLibraryPath)
             raise
     return self.library
Example #11
0
 def getLibrary(self):
     if not self.library:
         try:
             self.library = xpjson.loadDocument(self.simplifiedLibraryPath,
                                                schema=self.getSchema(),
                                                fillInDefaults=True)
         except:  # pylint: disable=W0702
             logging.warning('could not load XPJSON library from ' +
                             self.simplifiedLibraryPath)
             raise
     return self.library
Example #12
0
def writeCommandDictionary(inSchemaPath, outHtmlPath, **kwargs):
    """
    The master function that reads in an XPJSON PlanSchema document and outputs
    a command dictionary.
    """
    settings = copy.deepcopy(DEFAULT_DICTIONARY_SETTINGS)
    settings.update(kwargs)
    xpjson.CHECK_UNKNOWN_FIELDS = False  # suppress some warnings
    schema = xpjson.loadDocument(inSchemaPath)
    hlist = []

    def p(x):
        hlist.append(x)
        hlist.append('\n')

    commandSpecs = sorted(schema.commandSpecs, key=lambda spec: spec.id)

    if settings['includeIndex']:
        p('<div class="command_index">')
        p('  <h6 class="title">Index</h6>')
        p('  <ul>')
        for c in commandSpecs:
            p('    <li><a href="#command_%s">%s</a></li>' % (c.id, c.id))
        p('  </ul>')
        p('</div>')

    for c in commandSpecs:
        # logging.debug('%s', json.dumps(getCommandSpecInfo(settings, c), sort_keys=True, indent=4))
        commandInfo = getCommandSpecInfo(settings, c)
        chtml = getCommandSpecHtml(settings['commandSpecTemplateHtml'],
                                   commandInfo)
        p(chtml)

    outHtmlText = settings['docTemplateHtml'] % {
        'title': settings['title'],
        'style': settings['styleSheet'],
        'commands': ''.join(hlist)
    }
    with open(outHtmlPath, 'w') as outHtmlStream:
        outHtmlStream.write(outHtmlText)
    logging.info('wrote output to %s', outHtmlPath)
Example #13
0
def writeCommandDictionary(inSchemaPath, outHtmlPath, **kwargs):
    """
    The master function that reads in an XPJSON PlanSchema document and outputs
    a command dictionary.
    """
    settings = copy.deepcopy(DEFAULT_DICTIONARY_SETTINGS)
    settings.update(kwargs)
    xpjson.CHECK_UNKNOWN_FIELDS = False  # suppress some warnings
    schema = xpjson.loadDocument(inSchemaPath)
    hlist = []

    def p(x):
        hlist.append(x)
        hlist.append('\n')

    commandSpecs = sorted(schema.commandSpecs, key=lambda spec: spec.id)

    if settings['includeIndex']:
        p('<div class="command_index">')
        p('  <h2 class="title">Index</h2>')
        p('  <ul>')
        for c in commandSpecs:
            p('    <li><a href="#command_%s">%s</a></li>' % (c.id, c.id))
        p('  </ul>')
        p('</div>')

    for c in commandSpecs:
        # logging.debug('%s', json.dumps(getCommandSpecInfo(settings, c), sort_keys=True, indent=4))
        commandInfo = getCommandSpecInfo(settings, c)
        chtml = getCommandSpecHtml(settings['commandSpecTemplateHtml'], commandInfo)
        p(chtml)

    outHtmlText = settings['docTemplateHtml'] % {
        'title': settings['title'],
        'style': settings['styleSheet'],
        'commands': ''.join(hlist)
    }
    with open(outHtmlPath, 'w') as outHtmlStream:
        outHtmlStream.write(outHtmlText)
    logging.info('wrote output to %s', outHtmlPath)
Example #14
0
 def test_schema(self):
     _schema = xpjson.loadDocument(SCHEMA_PATH)
Example #15
0
def test():
    schema = xpjson.loadDocument(xpjson.EXAMPLE_PLAN_SCHEMA_PATH)
    plan = xpjson.loadDocument(xpjson.EXAMPLE_PLAN_PATH, schema=schema)
    exporter = KmlPlanExporter()
    open('/tmp/foo.kml', 'wb').write(exporter.exportPlan(plan, schema))
Example #16
0
 def test_plan(self):
     schema = xpjson.loadDocument(SCHEMA_PATH)
     _plan = xpjson.loadDocument(PLAN_PATH, schema=schema)
Example #17
0
 def buildSchema(planSchema):
     schema = xpjson.loadDocument(planSchema.schemaSource)
     xpjson.dumpDocumentToPath(planSchema.simplifiedSchemaPath, schema)
     print 'wrote simplified schema for platform %s to %s' % (planSchema.platform, planSchema.simplifiedSchemaPath)
Example #18
0
 def test_library(self):
     schema = xpjson.loadDocument(SCHEMA_PATH)
     _library = xpjson.loadDocument(LIBRARY_PATH, schema=schema)
Example #19
0
                'you must specify the --schema argument to validate a document of type %s'
                % t)
        except:
            traceback.print_exc()
            print
            print 'INVALID %s' % docPath

    ######################################################################
    elif cmd == 'simplify':
        if len(args) != 3:
            parser.error('simplify requires exactly 2 arguments')
        docPath = args[1]
        outPath = args[2]

        try:
            doc = xpjson.loadDocument(docPath, schema, fillInDefaults=True)
            xpjson.dumpDocumentToPath(outPath, doc)
            print 'wrote simplified %s to %s' % (doc.get('type'), outPath)
        except xpjson.NoSchemaError, t:
            parser.error(
                'you must specify the --schema argument to validate a document of type %s'
                % t)
        except:
            traceback.print_exc()
            print
            print 'ERROR could not simplify %s' % docPath

    ######################################################################
    elif cmd == 'import':
        if len(args) != 2:
            parser.error('import requires exactly 1 argument (import path)')
Example #20
0
def test():
    schema = xpjson.loadDocument(xpjson.EXAMPLE_PLAN_SCHEMA_PATH)
    plan = xpjson.loadDocument(xpjson.EXAMPLE_PLAN_PATH, schema=schema)
    exporter = KmlPlanExporter()
    open('/tmp/foo.kml', 'wb').write(exporter.exportPlan(plan, schema))
Example #21
0
 def test_library(self):
     schema = xpjson.loadDocument(SCHEMA_PATH)
     _library = xpjson.loadDocument(LIBRARY_PATH, schema=schema)
Example #22
0
 def test_plan(self):
     schema = xpjson.loadDocument(SCHEMA_PATH)
     _plan = xpjson.loadDocument(PLAN_PATH, schema=schema)
Example #23
0
 def buildSchema(planSchema):
     schema = xpjson.loadDocument(planSchema.schemaSource)
     xpjson.dumpDocumentToPath(planSchema.simplifiedSchemaPath, schema)
     print 'wrote simplified schema for platform %s to %s' % (
         planSchema.platform, planSchema.simplifiedSchemaPath)
Example #24
0
 def test_schema(self):
     _schema = xpjson.loadDocument(SCHEMA_PATH)
Example #25
0
        except xpjson.NoSchemaError, t:
            parser.error("you must specify the --schema argument to validate a document of type %s" % t)
        except:
            traceback.print_exc()
            print
            print "INVALID %s" % docPath

    ######################################################################
    elif cmd == "simplify":
        if len(args) != 3:
            parser.error("simplify requires exactly 2 arguments")
        docPath = args[1]
        outPath = args[2]

        try:
            doc = xpjson.loadDocument(docPath, schema, fillInDefaults=True)
            xpjson.dumpDocumentToPath(outPath, doc)
            print "wrote simplified %s to %s" % (doc.get("type"), outPath)
        except xpjson.NoSchemaError, t:
            parser.error("you must specify the --schema argument to validate a document of type %s" % t)
        except:
            traceback.print_exc()
            print
            print "ERROR could not simplify %s" % docPath

    ######################################################################
    elif cmd == "import":
        if len(args) != 2:
            parser.error("import requires exactly 1 argument (import path)")
        importPath = args[1]