def __init__(self, parent, suite, trait, template, name='TemplateViewWindow'): BaseTextEditWindow.__init__(self, parent, TemplateTextEdit, name=name) self.initPaellaCommon() self.trait = Trait(self.conn, suite=suite) self.mainView.trait = self.trait self.trait.set_trait(trait) self.resize(600, 800) self.set_template(template)
class TemplateViewWindow(BaseTextEditWindow): def __init__(self, parent, suite, trait, template, name='TemplateViewWindow'): BaseTextEditWindow.__init__(self, parent, TemplateTextEdit, name=name) self.initPaellaCommon() self.trait = Trait(self.conn, suite=suite) self.mainView.trait = self.trait self.trait.set_trait(trait) self.resize(600, 800) self.set_template(template) def set_template(self, template): self.current_template = template self._set_template() def _status_msg(self, status=None): msg = 'Trait: %s' % self.trait.current_trait msg = '%s (template %s)' % (msg, self.current_template) if status is None: return msg else: return '%s %s' % (status, msg) def _update_status(self, status=None): msg = self._status_msg(status=status) self.statusBar().message(msg) def _set_template(self): template = self.current_template data = self.trait.get_template_contents(template) self.mainView.setText(data) self._update_status() def initActions(self): BaseTextEditWindow.initActions(self) collection = self.actionCollection() self.newAction = KStdAction.openNew( self.mainView.slotCreateNewVariable, collection) def initMenus(self): pass def initToolbar(self): toolbar = self.toolBar() self.newAction.plug(toolbar) BaseTextEditWindow.initToolbar(self) def slotSave(self): text = str(self.mainView.text()) oldtext = self.trait.get_template_contents(self.current_template) if oldtext != text: self.trait.update_template(self.current_template, contents=text) self._update_status('Saved') else: KMessageBox.information(self, 'Nothing has changed') self._update_status()
class TemplateViewWindow(BaseTextEditWindow): def __init__(self, parent, suite, trait, template, name='TemplateViewWindow'): BaseTextEditWindow.__init__(self, parent, TemplateTextEdit, name=name) self.initPaellaCommon() self.trait = Trait(self.conn, suite=suite) self.mainView.trait = self.trait self.trait.set_trait(trait) self.resize(600, 800) self.set_template(template) def set_template(self, template): self.current_template = template self._set_template() def _status_msg(self, status=None): msg = 'Trait: %s' % self.trait.current_trait msg = '%s (template %s)' % (msg, self.current_template) if status is None: return msg else: return '%s %s' % (status, msg) def _update_status(self, status=None): msg = self._status_msg(status=status) self.statusBar().message(msg) def _set_template(self): template = self.current_template data = self.trait.get_template_contents(template) self.mainView.setText(data) self._update_status() def initActions(self): BaseTextEditWindow.initActions(self) collection = self.actionCollection() self.newAction = KStdAction.openNew(self.mainView.slotCreateNewVariable, collection) def initMenus(self): pass def initToolbar(self): toolbar = self.toolBar() self.newAction.plug(toolbar) BaseTextEditWindow.initToolbar(self) def slotSave(self): try: text = str(self.mainView.text()) except UnicodeEncodeError: text = unicode(self.mainView.text()) #text = text.encode() text = text.encode('utf') oldtext = self.trait.get_template_contents(self.current_template) if oldtext != text: self.trait.update_template(self.current_template, contents=text) self._update_status('Saved') else: KMessageBox.information(self, 'Nothing has changed') self._update_status()
print 'template modified' self.save_template(template, tmp) os.remove(path) if __name__ == '__main__': #f = file('tmp/trait.xml') #tx = TraitXml(f) import sys ct = convert_text_to_cheetah_template text = file('/etc/adduser.conf').read() text = file('/etc/bash.bashrc').read() ctest = file('ctest').read() from paella.db import PaellaConnection conn = PaellaConnection() tt = TraitTemplate(conn, 'etch') from paella.db.trait.main import Trait trait = Trait(conn) traits = trait.get_trait_list() def ptraits(): for trait in traits: print 'trait', trait print '-'*30 tt.set_trait(trait) for template in [r.template for r in tt.templates()]: print 'processing template', template text = tt.templatedata(template) ct(text) print print '='*30
self.save_template(template, tmp) os.remove(path) if __name__ == '__main__': #f = file('tmp/trait.xml') #tx = TraitXml(f) import sys ct = convert_text_to_cheetah_template text = file('/etc/adduser.conf').read() text = file('/etc/bash.bashrc').read() ctest = file('ctest').read() from paella.db import PaellaConnection conn = PaellaConnection() tt = TraitTemplate(conn, 'etch') from paella.db.trait.main import Trait trait = Trait(conn) traits = trait.get_trait_list() def ptraits(): for trait in traits: print 'trait', trait print '-' * 30 tt.set_trait(trait) for template in [r.template for r in tt.templates()]: print 'processing template', template text = tt.templatedata(template) ct(text) print print '=' * 30