예제 #1
0
def execute(options, args):
    if options.optdebug:
        print options, args
    if options.full:
        options.full = False
        options.toxml = True
        print "Pass 1 - Parse and write XML file . . ."
        execute(options,args)
        
        options.toxml = False
        options.topython = True
        print "Pass 2 - Pythonize and write PY file . . ."
        execute(options,[ arg+".xml" for arg in args])

        options.topython = False
        options.exec_python = True
        print "Pass 3 - Test PY file load . . ."
        execute(options,[ arg.replace(".qs",".py") for arg in args])
        print "Done."
        
    elif options.exec_python:
        import qsatype
        for filename in args:
            realpath = os.path.realpath(filename)
            path, name = os.path.split(realpath)
            mod = Module(name, path)
            if mod.loadModule():
                print mod.module
                print mod.module.form
            else:
                print "Error cargando modulo %s" % name
            
    elif options.topython:
        from pytnyzer import pythonize
        for filename in args:
            bname = os.path.basename(filename)
            if options.storepath:
                destname = os.path.join(options.storepath,bname+".py") 
            else:
                destname = filename+".py"
            destname = destname.replace(".qs.xml.py",".py")
            pythonize(filename, destname)
    
    else:        
        for filename in args:
            bname = os.path.basename(filename)
            print "File:", bname
            prog = flscriptparse.parse(open(filename).read())                      
            if not prog:
                print "No se pudo abrir el fichero."
                continue
            if options.toxml == False: 
                # Si no se quiere guardar resultado, no hace falta calcular mas
                continue
            
            tree_data = flscriptparse.calctree(prog, alias_mode = 0)
            if not tree_data:
                print "No se pudo parsear."
                continue
        
            ast = post_parse(tree_data)
            if ast is None:
                print "No se pudo analizar."
                continue
            if options.storepath:
                destname = os.path.join(options.storepath,bname+".xml") 
            else:
                destname = filename+".xml"
            f1 = open(destname,"w")
            f1.write(etree.tostring(ast, pretty_print = True))
            f1.close()
예제 #2
0
def execute(options, args):
    if options.optdebug:
        print options, args
    if options.full:
        options.full = False
        options.toxml = True
        print "Pass 1 - Parse and write XML file . . ."
        execute(options,args)
        
        options.toxml = False
        options.topython = True
        print "Pass 2 - Pythonize and write PY file . . ."
        execute(options,[ arg+".xml" for arg in args])

        options.topython = False
        options.exec_python = True
        #print "Pass 3 - Test PY file load . . ."
        #execute(options,[ (arg+".xml.py").replace(".qs.xml.py",".py") for arg in args])
        print "Done."
        
    elif options.exec_python:
        import qsatype
        for filename in args:
            realpath = os.path.realpath(filename)
            path, name = os.path.split(realpath)
            mod = Module(name, path)
            if mod.loadModule():
                print mod.module
                print mod.module.form
            else:
                print "Error cargando modulo %s" % name
            
    elif options.topython:
        from pytnyzer import pythonize
        for filename in args:
            bname = os.path.basename(filename)
            if options.storepath:
                destname = os.path.join(options.storepath,bname+".py") 
            else:
                destname = filename+".py"
            destname = destname.replace(".qs.xml.py",".py")
            pythonize(filename, destname)
    
    else:        
        nfs = len(args)
        for nf, filename in enumerate(args):
            bname = os.path.basename(filename)
            sys.stdout.write("Parsing File: %-35s . . . .        (%.1f%%)    " % (bname,100.0*(nf+1.0)/nfs))
            sys.stdout.flush();
            prog = flscriptparse.parse(open(filename).read())                      
            sys.stdout.write("\r");
            if not prog:
                print "Error: No se pudo abrir %-35s          \n" % (repr(filename))
                continue
            if prog["error_count"] > 0:
                print "Encontramos %d errores parseando: %-35s          \n" % (prog["error_count"], repr(filename))
                continue
            if options.toxml == False: 
                # Si no se quiere guardar resultado, no hace falta calcular mas
                continue
            
            tree_data = flscriptparse.calctree(prog, alias_mode = 0)
            if not tree_data:
                print "No se pudo parsear %-35s          \n" % (repr(filename))
                continue
            ast = post_parse(tree_data)
            if ast is None:
                print "No se pudo analizar %-35s          \n" % (repr(filename))
                continue
            if options.storepath:
                destname = os.path.join(options.storepath,bname+".xml") 
            else:
                destname = filename+".xml"
            f1 = open(destname,"w")
            f1.write(etree.tostring(ast, pretty_print = True))
            f1.close()