import sys
import traceback
import platform
-import glob
import re
+import tempfile
import cPickle as pickle
from Cura.util import profile
def runPostProcessingPlugins(engineResult):
pluginConfigList = getPostProcessPluginConfig()
- pluginList = getPluginList()
+ pluginList = getPluginList('postprocess')
+ tempfilename = None
for pluginConfig in pluginConfigList:
plugin = None
for pluginTest in pluginList:
- if pluginTest['filename'] == pluginConfig['filename']:
+ if pluginTest.getFilename() == pluginConfig['filename']:
plugin = pluginTest
if plugin is None:
continue
- pythonFile = None
- for basePath in getPluginBasePaths():
- testFilename = os.path.join(basePath, pluginConfig['filename'])
- if os.path.isfile(testFilename):
- pythonFile = testFilename
- if pythonFile is None:
- continue
+ pythonFile = plugin.getFullFilename()
+
+ if tempfilename is None:
+ f = tempfile.NamedTemporaryFile(prefix='CuraPluginTemp', delete=False)
+ tempfilename = f.name
+ f.write(engineResult.getGCode())
+ f.close()
- locals = {'filename': gcodefilename}
- for param in plugin['params']:
+ locals = {'filename': tempfilename}
+ for param in plugin.getParams():
value = param['default']
if param['name'] in pluginConfig['params']:
value = pluginConfig['params'][param['name']]
except:
locationInfo = traceback.extract_tb(sys.exc_info()[2])[-1]
return "%s: '%s' @ %s:%s:%d" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]), os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
+ if tempfilename is not None:
+ f = open(tempfilename, "r")
+ engineResult.setGCode(f.read())
+ f.close()
+ os.unlink(tempfilename)
return None
import cStringIO as StringIO
from Cura.util import profile
+from Cura.util import plugin
from Cura.util import version
from Cura.util import gcodeInterpreter
def getGCode(self):
data = self._gcodeData.getvalue()
- block0 = data[0:2048]
- for k, v in self._replaceInfo.items():
- v = (v + ' ' * len(k))[:len(k)]
- block0 = block0.replace(k, v)
- return block0 + data[2048:]
+ if len(self._replaceInfo) > 0:
+ block0 = data[0:2048]
+ for k, v in self._replaceInfo.items():
+ v = (v + ' ' * len(k))[:len(k)]
+ block0 = block0.replace(k, v)
+ return block0 + data[2048:]
+ return data
+
+ def setGCode(self, gcode):
+ self._gcodeData = StringIO.StringIO(gcode)
+ self._replaceInfo = {}
def addLog(self, line):
self._engineLog.append(line)
returnCode = self._process.wait()
logThread.join()
if returnCode == 0:
- pluginError = None #profile.runPostProcessingPlugins(self._exportFilename)
+ pluginError = plugin.runPostProcessingPlugins(self._result)
if pluginError is not None:
print pluginError
self._result.addLog(pluginError)