chiark / gitweb /
Fixing post processing plugins.
authordaid <daid303@gmail.com>
Wed, 12 Feb 2014 14:06:28 +0000 (15:06 +0100)
committerdaid <daid303@gmail.com>
Wed, 12 Feb 2014 14:06:28 +0000 (15:06 +0100)
Cura/util/plugin.py
Cura/util/sliceEngine.py

index 382c62e2563512b5abb22c1888a141322d962883..77b103d31b2aa48a53f5e0bf24561aee968b9ffd 100644 (file)
@@ -8,8 +8,8 @@ import os
 import sys
 import traceback
 import platform
-import glob
 import re
+import tempfile
 import cPickle as pickle
 
 from Cura.util import profile
@@ -108,26 +108,27 @@ def getPluginList(pluginType):
 
 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']]
@@ -144,4 +145,9 @@ def runPostProcessingPlugins(engineResult):
                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
index ceca5b95b1528c95fc121b35888be1caa8e7375a..924662854335fd07ae9afede445a7d9d6dc356fd 100644 (file)
@@ -21,6 +21,7 @@ import struct
 import cStringIO as StringIO
 
 from Cura.util import profile
+from Cura.util import plugin
 from Cura.util import version
 from Cura.util import gcodeInterpreter
 
@@ -93,11 +94,17 @@ class EngineResult(object):
 
        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)
@@ -361,7 +368,7 @@ class Engine(object):
                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)