运行FME工作台的Python脚本

时间:2019-01-11 14:00:10

标签: python gis postgis fme

我有500多个xml文件,每个xml文件应在FME工作台上单独处理(每个XML文件的FME工作台迭代)。 对于这样的建议,我必须在(IDLE 2.7或替代的python控制台)上运行python文件,以为每个xml文件迭代FME工作台。

过去,整个过程都可以在其他PC上正常进行。现在,我运行模块后,出现以下错误:

回溯(最近一次拨打电话):E:\ XML_Data   文件“ E:\ XML_Data \ process \ 01_XML_Tile_1.py”,第28行,在     如果打开时显示“翻译成功”(path_log +“ \” +数据+“ .log”)。read(): IOError:[Errno 2]没有这样的文件或目录:'E:\ XML_Data \ data_out \ log_01 \ re_3385-5275.xml.log'

附加了python代码。

非常感谢您的帮助。

import os
import time
# Mainpath and Working Folder:
#path_main = r"E:\XML_Data"
path_main = r"E:\XML_Data"
teil = str("01")

# variables
path_in = path_main + r"\data_in\03_Places\teil_" + teil                # "Source folder of  XML files"
path_in_tile10 = path_main + r"\data_in\01_Tiling\10x10.shp"            # "Source folder of Grid shapefile"
path_in_commu = path_main + r"\data_in\02_Communities\Communities.shp"  # "Source folder of Communities shapefile"
path_out = path_main + r"\data_out\teil_" + teil                        # "Output folder of shapefiles that resulted from XML files (tile_01 folder)"
path_log = path_main + r"\data_out\log_" + teil                         # "Output folder of log files for each run(log_01 folder)"
path_fme = r"%FME_EXE_2015%"                                            # "C:\Program Files\FME2015\fme.exe"
path_fme_workbench = path_main + r"\process\PY_FME2015.fmw"             # "path of FME workbench"
datalists = os.listdir(path_in)
count = 0

# Schleife, in which each file is processed individually in FME
for data in datalists:
    if data.find(".xml") != -1:
        count +=1
        print ("Run-No." + str(count) + ": with data " + data)
        os.system (path_fme + " " + path_fme_workbench + " " + "--SourceDataset_XML"+ " " + path_in + "\\" + data + " " + "--SourceDataset_SHAPE" + " " + path_in_tile10 + " " + "--SourceDataset_SHAPE_COMU" + " " + path_in_commu + " " + "--DestDataset_SHAPE" +" " +path_out + " " +"LOG_FILENAME" + " " + path_log + "\\" + data + ".log" )
        print ("Data processed: " + data)
        shape = str(data[19:28]) + "_POPINT_CENTR_UTM32N.shp"
        print ("ResultsFileName: " + shape)
        if "Translation was SUCCESSFUL" in open(path_log + "\\" + data + ".log").read():
            # Translation was successful and SHP file exists:
            if os.path.isfile(path_out + "\\" + shape):
                write_log = open(path_out + "\\" + "result_xml.log", "a")
                write_log.write(time.asctime(time.localtime()) + " " + shape + "\n")
                write_log.close()
                print("Everything ok")
            #Translation was successful, but SHP file does not exist:
            else:
                write_log = open(path_out + "\\" + "error_xml.log", "a")
                write_log.write(time.asctime(time.localtime()) + " Data: " + shape + " unavailable.\n")
                write_log.close()      
        # Translation was not successful:
        else:
            write_log = open(path_out + "\\" + "error_xml.log", "a")
            write_log.write(time.asctime(time.localtime()) + " Translation " + Data + " not successful.\n")
            write_log.close()

print ("Number of calculated files: " + str(count))

2 个答案:

答案 0 :(得分:0)

该脚本很可能在os.system行中失败,因此不是通过命令创建日志文件。由于您提到的是另一台计算机,所以它可能是由多种原因引起的,例如FME的版本不同(因此环境变量%FME_EXE_2015%将不存在)。

答案 1 :(得分:0)

使用工作区流道变压器来执行此操作。