def addTemplate(self, task):
     handle, filename = tempfile.mkstemp('.tsktmpl', dir=self._path)
     os.close(handle)
     templateFile = codecs.open(filename, 'w', 'utf-8')
     writer = TemplateXMLWriter(templateFile)
     writer.write(task.copy())
     templateFile.close()
     self._tasks.append((TemplateXMLReader(file(filename, 'rU')).read(), os.path.split(filename)[-1]))
    def save(self):
        pickle.dump([name for task, name in self._tasks], file(os.path.join(self._path, 'list.pickle'), 'wb'))

        for task, name in self._tasks:
            templateFile = codecs.open(os.path.join(self._path, name), 'w', 'utf-8')
            writer = TemplateXMLWriter(templateFile)
            writer.write(self._copyTask(task))

        for task, name in self._toDelete:
            os.remove(os.path.join(self._path, name))
        self._toDelete = []
        patterns.Event('templates.saved', self).send()