import platform
import re
import tempfile
+import ConfigParser
import cPickle as pickle
from Cura.util import profile
# else:
# print "Unknown item in plugin meta data: %s %s" % (line[0], line[1])
+ self._readSettings(os.path.join(profile.getBasePath()))
+ for plugindir in getPluginBasePaths():
+ self._readSettings(plugindir)
+
+ def _readSettings(self, indir):
+ settings_file = os.path.join(indir, 'plugin_defaults.ini')
+ plugin_basename = re.sub(r'\.pyc?','',os.path.basename(self._filename))
+ if not os.path.exists(settings_file):
+ return
+ cfg = ConfigParser.ConfigParser()
+ try:
+ cfg.read(settings_file)
+ except:
+ traceback.print_exc()
+ if not cfg.has_section(plugin_basename):
+ return
+ for param in self._params:
+ name = param['name']
+ if cfg.has_option(plugin_basename, name):
+ param['default'] = cfg.get(plugin_basename, name)
+
def getFilename(self):
return self._filename
def setPostProcessPluginConfig(config):
profile.putProfileSetting('plugin_config', pickle.dumps(config))
+def overridePostProcessPluginConfig(config):
+ profile.setTempOverride('plugin_config', pickle.dumps(config))
+
def getPluginBasePaths():
ret = []
if platform.system() != "Windows":
ret.append(plugin)
return ret
-def runPostProcessingPlugins(engineResult):
- pluginConfigList = getPostProcessPluginConfig()
+def runPostProcessingPlugins(engineResult, pluginConfigList):
pluginList = getPluginList('postprocess')
tempfilename = None
tempfilename = f.name
gcode = engineResult.getGCode()
while True:
- data = gcode.read()
+ data = gcode.read(16 * 1024)
if len(data) == 0:
break
f.write(data)
f.close()
+ del gcode
locals = {'filename': tempfilename}
for param in plugin.getParams():
try:
execfile(pythonFile, locals)
except:
+ traceback.print_exc()
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())
+ engineResult.setGCode("")
+ import gc
+ gc.collect()
+ data = f.read(4096)
+ while len(data) > 0:
+ engineResult._gcodeData.write(data)
+ data = f.read(4096)
f.close()
os.unlink(tempfilename)
return None