import platform
import re
import tempfile
+import ConfigParser
import cPickle as pickle
from Cura.util import profile
_pluginList = None
class pluginInfo(object):
+ """
+ Plugin information object. Used to keep track of information about the available plugins in this installation of Cura.
+ Each plugin as meta-data associated with it which can be retrieved from this class.
+ """
def __init__(self, dirname, filename):
self._dirname = dirname
self._filename = filename
# 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":
if _pluginList is None:
_pluginList = []
for basePath in getPluginBasePaths():
- for filename in os.listdir(basePath):
- if filename.startswith('.'):
- continue
- if filename.startswith('_'):
- continue
- if os.path.isdir(os.path.join(basePath, filename)):
- if os.path.exists(os.path.join(basePath, filename, 'script.py')):
- _pluginList.append(pluginInfo(basePath, os.path.join(filename, 'script.py')))
- elif filename.endswith('.py'):
- _pluginList.append(pluginInfo(basePath, filename))
+ if os.path.isdir(basePath):
+ for filename in os.listdir(basePath):
+ if filename.startswith('.'):
+ continue
+ if filename.startswith('_'):
+ continue
+ if os.path.isdir(os.path.join(basePath, filename)):
+ if os.path.exists(os.path.join(basePath, filename, 'script.py')):
+ _pluginList.append(pluginInfo(basePath, os.path.join(filename, 'script.py')))
+ elif filename.endswith('.py'):
+ _pluginList.append(pluginInfo(basePath, filename))
ret = []
for plugin in _pluginList:
if plugin.getType() == pluginType:
ret.append(plugin)
return ret
-def runPostProcessingPlugins(engineResult):
- pluginConfigList = getPostProcessPluginConfig()
+def runPostProcessingPlugins(engineResult, pluginConfigList):
pluginList = getPluginList('postprocess')
tempfilename = None
if tempfilename is None:
f = tempfile.NamedTemporaryFile(prefix='CuraPluginTemp', delete=False)
tempfilename = f.name
- f.write(engineResult.getGCode())
+ gcode = engineResult.getGCode()
+ while True:
+ 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