コード例 #1
0
def convert(conf,inputs,outputs):
    if list(conf.keys()).count("oo")>0 and list(conf["oo"].keys()).count("external")>0 and conf["oo"]["external"]=="true":
        from subprocess import Popen, PIPE
        process = Popen([conf["oo"]["path"]],stdin=PIPE,stdout=PIPE)
        script="import pp.PaperMint as PaperMint\n"
        script+="pm=PaperMint.LOClient()\n"
        script+="pm.loadDoc('"+inputs["oDoc"]["value"]+"')\n"
        docPath=conf["main"]["tmpPath"]+"/"+inputs["tDoc"]["value"]
        script+="pm.saveDoc('"+docPath+"')\n"
        script+="pm.unloadDoc('"+docPath+"')\n"
        process.stdin.write(script)
        process.stdin.close()
    else:
        import PaperMint
        pm=PaperMint.LOClient()
        pm.loadDoc(inputs["oDoc"]["value"])
        docPath=conf["main"]["tmpPath"]+"/"+inputs["tDoc"]["value"]
        pm.saveDoc(docPath)
        pm.unloadDoc(docPath)
    
    outputs["Result"]["value"]=open(docPath,"r").read()
    outputs["Result"]["mimeType"]=pm.outputFormat[pm.format][0]
    os.unlink(docPath)
    
    return zoo.SERVICE_SUCCEEDED
コード例 #2
0
def printMap(conf,inputs,outputs):
    import sys
    if list(conf.keys()).count("oo")>0 and list(conf["oo"].keys()).count("external")>0 and conf["oo"]["external"]=="true":
        from subprocess import Popen, PIPE
        import json
        print >> sys.stderr,"Start"
        sys.stderr.flush()
        err_log = file(conf["main"]["tmpPath"]+'/tmp_err_log_file', 'w', 0)
        os.dup2(err_log.fileno(), sys.stderr.fileno())
        process = Popen([conf["oo"]["path"]],stdin=PIPE,stdout=PIPE)
        print >> sys.stderr,"Started"
        script=""
        if conf["senv"].has_key("prescr"):
            script+=conf["senv"]["prescr"]
        script+="import pp.PaperMint as PaperMint\n"
        print >> sys.stderr,"PaperMint) imported"        
    else:
        import PaperMint
    
    coeff=1;
    sizes={
        "preview": (1024*coeff,768*coeff),
        "A4l": (1024*coeff,768*coeff),
        "A4lp": (1024*coeff,768*coeff),
        "A4": (768*coeff,1024*coeff),
        "A4p": (768*coeff,1024*coeff)
        }
    csize=sizes[inputs["iFormat"]["value"]]
    
    docPath=conf["main"]["tmpPath"]+"/"+conf["lenv"]["usid"]+"_"+inputs["tDoc"]["value"].replace('.pdf','.odt')
    if list(conf.keys()).count("oo")>0 and list(conf["oo"].keys()).count("external")>0 and conf["oo"]["external"]=="true":
        script+="pm=PaperMint.LOClient()\n"
        script+='pm.loadDoc("'+conf["main"]["dataPath"]+'/ftp/templates/MM-'+inputs["iFormat"]["value"]+'-template.odt")\n'
	script+='pm.saveDoc("'+docPath+'")\n'
        script+='pm.unloadDoc("'+conf["main"]["dataPath"]+'/ftp/templates/MM-'+inputs["iFormat"]["value"]+'-template.odt")\n'
	script+='pm.loadDoc("'+docPath+'")\n'
    else:
        pm=PaperMint.LOClient()
        # Load the document
        pm.loadDoc(conf["main"]["dataPath"]+"/ftp/templates/MM-"+inputs["iFormat"]["value"]+"-template.odt")
    
    # Load the map
    import mapscript
    mapfile=conf["main"]["dataPath"]+"/public_maps/project_"+inputs["map"]["value"]+".map"
    m=mapscript.mapObj(mapfile)
    if inputs["map"]["value"]=="indicateurs":
	import mapfile.service as mapfile
	mi=mapscript.mapObj(conf["main"]["dataPath"]+"/indexes_maps/project_PIndex"+conf["senv"]["last_index"]+".map")
	conf["senv"]["previous_map"]=conf["senv"]["last_map"]
	conf["senv"]["last_map"]="PIndex"+conf["senv"]["last_index"]
	#mapfile.saveLegendIconsForLayer(conf,m,m,ml,m.numlayers-1,prefix="indexes_");
	mapfile.saveLegendIcons(conf,mi,prefix="indexes_")
	ml=mi.getLayer(0).clone()
	ml.metadata.set("ows_title",inputs["index_name"]["value"])
	m.insertLayer(ml)
	conf["senv"]["last_map"]=conf["senv"]["previous_map"]
	inputs["layers"]["value"]+=","+str(m.numlayers-1)
    for i in range(m.numlayers):
        m.getLayer(i).status=mapscript.MS_OFF
    m.setProjection("init=epsg:900913")

    # Set activated layers to on
    layers=inputs["layers"]["value"].split(",")
    layerNames=[]
    script0=""
    print >> sys.stderr,"LAYERS:"+str(layers)
    nblayer=0
    for i in layers:
        if i!="":
            layer=m.getLayer(int(i))
            if layer is None:
                break
            layer.status=mapscript.MS_ON
            print >> sys.stderr,layer.metadata.get("mmIcon")
            try:
		lname=layer.metadata.get("ows_title")
            except:
		lname=layer.name
            if layer.numclasses==1:
                if layer.metadata.get("mmIcon"):
                    ico=layer.metadata.get("mmIcon").replace(conf["main"]["tmpUrl"],conf["main"]["tmpPath"])
                try:
                    if layer.metadata.get("mmIcon"):
                        layerNames+=["[_"+layer.name+"_] "+lname]
                        script0+='pm.insertImageAt("[_'+layer.name+'_]","'+ico+'",True)\n'
                    else:
                        layerNames+=[" "+layer.name]
                except Exception,e:
                    print >> sys.stderr,e
                    if layer.metadata.get("mmIcon"):
                        try:
                            layerNames+=["[_"+layer.name+"_] "+lname]
                            script0+='pm.insertImageAt("[_'+layer.name+'_]","'+ico+'",True)\n'
                        except:
                            continue
                    else:
                        layerNames+=[" "+layer.name]
            else:
                try:
                    toAppend=[m.getLayer(layer.index).metadata.get("ows_title")]
                except:
                    toAppend=[m.getLayer(layer.index).name]
                script0+="pm.nblayer="+str(nblayer)+"\n"
                for k in range(0,layer.numclasses):
                    if layer.metadata.get("mmIcon_"+str(k)):
                        toAppend+=["[_"+layer.name+"_"+str(k)+"_] "+layer.getClass(k).name]
                        ico=layer.metadata.get("mmIcon_"+str(k)).replace(conf["main"]["tmpUrl"],conf["main"]["tmpPath"])
                        script0+='pm.insertImageAt("[_'+layer.name+"_"+str(k)+'_]","'+ico+'",True)\n'
                    else:
                        toAppend+=[layer.getClass(k).name]
                layerNames+=toAppend
            nblayer+=1