Python scripting uploader - Scripts

uploadStarter

Previous  Chapter  Next

 

The uploadStarter script is loading the python environment for the upload. It will try to initialize the provided uploader. If the instance of the actual uploader cannot be created, the script will return. If the instantiation is successful, the script will open for reading the file to be uploaded and will call the ParseFile  method (method must parse the file an create the upload objects which will be transformed into a FASTSUITE E2 toolpath).

 

The script is part of the FASTSUITE Edition 2 installation and may not be modified.


import os

from os.path import exists

 

def OpenFile(filePath):

    dirPath = os.path.dirname(filePath)

    if not exists(dirPath):

        return None

    return open(filePath, "r")

 

 

def UploadProgramFromFile(operator):

    logger = operator.GetLogOperator()

    logger.LogDebug("Starting Uploader")

 

    #### Get the class name of the uploader from globals and instantiate

    uploaderClass = "no_name"

    try:

        uploaderClass = globals()[UPLOAD_CLASS_NAME]

    except:

        logger.LogError("Uploader class name is not set! Aborting upload.")

        return

    

    uploader = uploaderClass()

    if uploader is None:

        logger.LogError("Could not initialize uploader class. Aborting upload.")

        return

    

    uploader.Initialize(operator)

    

    for sourceFile in operator.GetSourceFiles():

        logger.LogDebug("Opening file " + sourceFile)

        try:

            fileObject = OpenFile(sourceFile)

            if fileObject is None:

                logger.LogError("Unable to open file at " + sourceFile)

                continue

                

            uploader.ParseFile(operator, fileObject)

            fileObject.close()

        except Exception as Argument:

            logger.LogError("Error while parsing file " + sourceFile)

            logger.LogError(str(Argument))

        

    uploader.Finalize(operator)


Previous
Previous page
Chapter
Chapter page
Next
Next page