Python line by line execution

296 Views Asked by At

I couldn't fine solution for this question using search option so my question is: I have a script that does the job but only for one file. Just to explain what`s going on here:

import sys
sys.path.append('C:\Program Files\FME\fmeobjects\python27')

import fmeobjects 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = 'C:\FME\Project_1.fmw'

parameters = {}
parameters['SourceDataset_ACAD'] ='C:\AutoCAD\Project_1.dwg'
parameters['DestDataset_OGCKML'] ='C:\Maps_KMZ\Project_1.kmz'  
runner.runWithParameters(workspace, parameters)

try:
    # Run Workspace with parameters set in above directory
    runner.runWithParameters(workspace, parameters)
    # or use promptRun to prompt for published parameters
    #runner.promptRun(workspace)
except fmeobjects.FMEException as ex:
    # Print out FME Exception if workspace failed
    print ex.message
else:
    #Tell user the workspace ran
    print('The Workspace is ran successfully'.format(workspace))

runner = None

This script executes FMW file that does conversion from AutoCAD DWG (C:\AutoCAD) to KMZ file and stores it in C:\Maps_KMZ folder. Now, I need to do the same thing for about 20-ish FME files that are in the same source folder. Is it possible to execute each file at the time and add specific time frame between two executions let`s say 2 minute pause between them, because I can not run 2 or more conversions at the same time, it would crash Windows.

Thank you very much for your help!

1

There are 1 best solutions below

6
Code-Apprentice On

I suggest that you modify your script to use command line arguments. You can either use sys.argv directly for a very simple interface or the parseargs module for more complex options.

You can write the interface to accept individual files names or directory names. To traverse the files of a directory, look at os.walk().