Example #1
0
class WavePlayerRTCManager:
    def __init__(self):
        encoding = locale.getpreferredencoding()
        sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors="replace")
        sys.stderr = codecs.getwriter(encoding)(sys.stderr, errors="replace")

        parser = utils.MyParser(version=__version__, description=__doc__)
        utils.addmanageropts(parser)
        parser.add_option('-g',
                          '--gui',
                          dest='guimode',
                          action="store_true",
                          default=False,
                          help=_('show file open dialog in GUI'))
        try:
            opts, args = parser.parse_args()
        except optparse.OptionError, e:
            print >> sys.stderr, 'OptionError:', e
            sys.exit(1)

        if opts.guimode == True:
            sel = utils.askopenfilename(title="select wave file")
            if sel is not None:
                args.append(sel)

        if len(args) != 1:
            parser.error("wrong number of arguments")
            sys.exit(1)

        self._file = args[0]
        self._comp = None
        self._manager = OpenRTM_aist.Manager.init(utils.genmanagerargs(opts))
        self._manager.setModuleInitProc(self.moduleInit)
        self._manager.activateManager()
Example #2
0
def main():
    global opts
    
    #encoding = locale.getpreferredencoding()
    #sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors = "replace")
    #sys.stderr = codecs.getwriter(encoding)(sys.stderr, errors = "replace")

    if hasattr(sys, "frozen"):
        basedir = os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding()))
    else:
        basedir = os.path.dirname(__file__)

    parser = utils.MyParser(version=__version__, usage="%prog [grammarfile]",
                            description=__doc__, epilog=__examples__)
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      default=False,
                      help='output verbose information')
    parser.add_option('-g', '--gui', dest='guimode', action="store_true",
                      default=False,
                      help='show file open dialog in GUI')
    try:
        opts, args = parser.parse_args()
    except optparse.OptionError as e:
        print ('OptionError:', e, file=sys.stderr)
        sys.exit(1)

    if opts.guimode == True:
        args.append(utils.askopenfilename(title="select W3C-SRGS grammar file"))

    if len(args) == 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    parser = etree.XMLParser(dtd_validation = True)
    xmlschema_doc = etree.parse(os.path.join(basedir, 'grammar.xsd'))
    xmlschema = etree.XMLSchema(xmlschema_doc)
    print ("Validating SRGS file %s..." % (args[0],))
    try:
        doc2 = etree.parse(args[0])
        doc2.xinclude()
    except etree.XMLSyntaxError as e:
        print ("[error] invalid xml syntax")
        print (e)
        myexit()
    except IOError as e:
        print ("[error] IO error: unable to open file ", args[0])
        print (e)
        myexit()
    try:
        xmlschema.assert_(doc2)
        print ("SRGS file is valid.")
    except AssertionError as b:
        print ("[error] Invalid SRGS file.")
        print (b)
        myexit()

    xmlschema2_doc = etree.parse(os.path.join(basedir, 'pls.xsd'))
    xmlschema2 = etree.XMLSchema(xmlschema2_doc)
    srgs = SRGS(args[0])
    try:
        for l in srgs._lex:
            print ("Validating PLS file %s..." % (l,))
            doc4 = etree.parse(l)
            try:
                xmlschema2.assert_(doc4)
                print ("PLS file is valid.")
            except AssertionError as b:
                print ("[error] Invalid PLS file.")
                print (b)
                myexit()
    except IOError:
        print ("[error] Cannot open PLS file: %s" % (",".join(srgs._lex),))
        myexit()
    myexit()
Example #3
0
                      default=False,
                      help=_('output verbose information'))
    parser.add_option('-r', '--target-rule', dest='targetrule', action="store",
                      type="string",
                      help=_('specify target rule id'))
    parser.add_option('-g', '--gui', dest='guimode', action="store_true",
                      default=False,
                      help=_('show file open dialog in GUI'))
    try:
        opts, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        sys.exit(1)

    if opts.guimode == True:
        sel = utils.askopenfilename(title="select W3C-SRGS grammar file")
        if sel is not None:
            args.append(sel)
        outname = utils.asksaveasfile()
        outfile = open(outname, 'w')
    
    if len(args) == 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    outfile = codecs.getwriter('utf-8')(outfile)

    srgs = SRGS(args[0])
    dic = LexiconDB(conf._lexicondb, __version__)
    if srgs._lang in ("jp", "ja"):
        alphabet = "x-KANA"
Example #4
0
                      type="string",
                      help=_('specify target rule id'))
    parser.add_option('-g',
                      '--gui',
                      dest='guimode',
                      action="store_true",
                      default=False,
                      help=_('show file open dialog in GUI'))
    try:
        opts, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        sys.exit(1)

    if opts.guimode == True:
        sel = utils.askopenfilename(title="select W3C-SRGS grammar file")
        if sel is not None:
            args.append(sel)
        outname = utils.asksaveasfile()
        outfile = open(outname, 'w')

    if len(args) == 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    outfile = codecs.getwriter('utf-8')(outfile)

    srgs = SRGS(args[0])
    dic = LexiconDB(conf._lexicondb, __version__)
    if srgs._lang in ("jp", "ja"):
        alphabet = "x-KANA"
Example #5
0
    parser = utils.MyParser(version=__version__, usage="%prog [grammarfile]",
                            description=__doc__, epilog=__examples__)
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      default=False,
                      help=_('output verbose information'))
    parser.add_option('-g', '--gui', dest='guimode', action="store_true",
                      default=False,
                      help=_('show file open dialog in GUI'))
    try:
        opts, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        sys.exit(1)

    if opts.guimode == True:
        args.append(utils.askopenfilename(title="select W3C-SRGS grammar file"))

    if len(args) == 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    parser = etree.XMLParser(dtd_validation = True)
    xmlschema_doc = etree.parse(os.path.join(basedir, 'grammar.xsd'))
    xmlschema = etree.XMLSchema(xmlschema_doc)
    print "Validating SRGS file %s..." % (args[0],)
    try:
        doc2 = etree.parse(args[0])
        doc2.xinclude()
    except etree.XMLSyntaxError, e:
        print "[error] invalid xml syntax"
        print e