class TemplateEditor(QSplitter): def __init__(self, parent, suite, name='TemplateEditor'): QSplitter.__init__(self, parent, name) self.app = get_application_pointer() self.trait = None self.listView = TraitListView(self, 'template') self.mainEdit = SimpleEdit(self) self.set_suite(suite) self.refreshListView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def set_suite(self, suite): self.suite = suite self.listView.set_suite(suite) self.trait = Trait(self.conn, suite=suite) def set_trait(self, trait): self.trait.set_trait(trait) def refreshListView(self): self.listView.refreshlistView() def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'row'): self.mainEdit.setText(self.listView.getData())
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list( self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) #self.installer = TraitInstaller(self.conn, self.suite) self.installer = ProfileInstaller(self.conn) self.installer.set_logfile() self.installer.set_profile(self.profile) self.installer.set_target(self.target) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
class TemplateEditor(QSplitter): def __init__(self, app, parent, suite, name='TemplateEditor'): QSplitter.__init__(self, parent, name) dbwidget(self, app) self.trait = None self.listView = TraitList(self.app, self, 'template') self.mainEdit = SimpleEdit(self.app, self) self.set_suite(suite) self.refreshListView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def set_suite(self, suite): self.suite = suite self.listView.set_suite(suite) self.trait = Trait(self.conn, suite=suite) def set_trait(self, trait): self.trait.set_trait(trait) def refreshListView(self): self.listView.refreshlistView() def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'row'): self.mainEdit.setText(self.listView.getData())
class ToolkitDatabase(object): def __init__(self, conn): self.conn = conn self.profile = Profile(self.conn) self.family = Family(self.conn) self.suite = None self.trait = None self.machine = MachineHandler(self.conn) def set_profile(self, profile): self.profile.set_profile(profile) self.suite = self.profile.current.suite self.trait = Trait(self.conn, self.suite) def set_trait(self, trait): self.trait.set_trait(trait) def set_machine(self, machine): self.machine.set_machine(machine) profile = self.machine.get_profile() self.set_profile(profile) if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT']) def env(self): env = TemplatedEnvironment() if self.trait.current_trait is not None: env.update(self.trait._parents.Environment()) env.update(self.profile.get_family_data()) env.update(self.profile.get_profile_data()) if self.machine.current_machine is not None: env.update(self.machine.get_machine_data()) return env
def reset_rows(self): if self.suite is None: self.traits = None self.set_rows([]) else: self.traits = Trait(self.conn, self.suite) self.set_rows(self.traits.get_traits()) self.set_row_select(self.trait_selected)
def __init__(self, parent, trait, suite, name='ParentAssigner'): self.app = get_application_pointer() self.conn = self.app.conn self.suite = suite self.trait = Trait(self.conn, suite=self.suite) self.trait.set_trait(trait) BaseAssigner.__init__(self, parent, name=name) self.connect(self, SIGNAL('okClicked()'), self.slotInsertNewParents)
def __init__(self, parent, trait, suite, name='TraitDescriptionWindow'): BaseTextEditWindow.__init__(self, parent, KTextEdit, name=name) self.initPaellaCommon() self.trait = Trait(self.conn, suite=suite) self.trait.set_trait(trait) self.resize(600, 800) desc = self.trait.get_description() if desc is not None: self.mainView.setText(desc)
class TraitDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn) def set_trait(self, trait): self.clear_body() self.trait.set_trait(trait) title = SimpleTitleElement('Trait: %s' % trait, bgcolor='IndianRed', width='100%') self.body.appendChild(title) self.body.appendChild(HR()) plist = UnorderedList() parents = self.trait.parents(trait=trait) parent_section = SectionTitle('Parents') parent_section.create_rightside_table() parent_section.append_rightside_anchor( Anchor('hello.there.dude', 'edit')) parent_section.append_rightside_anchor( Anchor('hello.there.dudee', 'edit2')) self.body.appendChild(parent_section) for parent in parents: pp = Anchor('show.parent.%s' % parent, parent) plist.appendChild(ListItem(pp)) self.body.appendChild(plist) #ptitle_anchor = Anchor('edit.packages.%s' % trait, 'Packages') ptitle = SectionTitle('Packages') ptitle_anchor = Anchor('new.package.%s' % trait, '(new)') td = TD() td.appendChild(ptitle_anchor) ptitle.row.appendChild(td) self.body.appendChild(ptitle) rows = self.trait.packages(trait=trait, action=True) self.body.appendChild(PackageTable(rows, bgcolor='SkyBlue3')) ttitle = Anchor('edit.templates.%s' % trait, 'Templates') self.body.appendChild(SectionTitle(ttitle)) rows = self.trait.templates( trait=trait, fields=['package', 'template', 'templatefile']) if len(rows): self.body.appendChild(TemplateTable(rows, bgcolor='DarkSeaGreen3')) self.body.appendChild(SectionTitle('Variables', href='foo.var.ick')) if len(self.trait.environ.keys()): env = TraitEnvTable(trait, self.trait.environ, bgcolor='MistyRose3') self.body.appendChild(env) self.body.appendChild(SectionTitle('Scripts')) slist = UnorderedList() for row in self.trait._scripts.scripts(trait=trait): script = row.script sa = Anchor('show.script.%s' % script, script) slist.appendChild(ListItem(sa)) self.body.appendChild(slist)
def importupdate(self, path, action): tarball = TraitTarFile(path) trait = tarball.get_trait() traitdb = Trait(self.conn, self.suite) if action == 'import': traitdb.insert_trait(path, suite=self.suite) for info in tarball: if info.name[:10] == 'templates/': #tarball.extract(info, template_path) pass self.reset_rows()
def __init__(self, conn, suite): self.menu = make_menu(['delete'], self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.suite = suite self.trait = Trait(self.conn, self.suite) self.package_menu = make_menu(['install', 'remove', 'purge', 'drop'], self.set_package) self.parent_menu = make_menu(['drop'], self.modify_parent) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.package_menu), 'packages') self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents') self.set_size_request(400, 300)
class PaellaFile(object): def __init__(self, conn, fspath, flags, *mode): logging.info('PaellaFile.__init__ start') self.conn = conn self.fileobj = None self.info = pathinfo(fspath) #logging.info('info %s' % self.info) #logging.info('conn %s' % self.conn) self.fspath = fspath self.traitdb = Trait(self.conn, self.info['suite']) #logging.info('traitdb %s' % self.traitdb) #logging.info('set trait to %s' % self.info['trait']) self.traitdb.set_trait(self.info['trait']) logging.info('traitdb.current_trait %s' % self.traitdb.current_trait) #logging.info('PaellaFile.__init__ info: %s' % self.info) fname = self.info['fname'] ftype = self.info['ftype'] if ftype == 'scripts': self. fileobj = self.traitdb._scripts.scriptfile(fname) else: logging.warn('Unable to handle ftype of %s' % ftype) logging.info('PaellaFile initialized with %s, %s' % (ftype, fname)) def read(self, length, offset): logging.info('PaellaFile.read(%d, %d)' % (length, offset)) self.fileobj.seek(offset) data = self.fileobj.read(length) #logging.info('read data %s' % data) return data def fgetattr(self): logging.info('PaellaFile.fgetattr called') st = MyStat() st.st_mode = stat.S_IFREG | 0644 st.st_uid = os.getuid() st.st_gid = os.getgid() st.st_size = self.fileobj.len return st def release(self, flags): self.fileobj.close() def test__getattr__(self, attribute, *args, **kw): if hasattr(self, attribute): return getattr(self, attribute, *args, **kw) else: logging.warn('%s called in PaellaFile' % attribute) raise AttributeError , "PaellaFile instance has no attribute '%s'" % attribute
class TraitDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn) def set_trait(self, trait): self.clear_body() self.trait.set_trait(trait) title = SimpleTitleElement('Trait: %s' % trait, bgcolor='IndianRed', width='100%') self.body.appendChild(title) self.body.appendChild(HR()) plist = UnorderedList() parents = self.trait.parents(trait=trait) parent_section = SectionTitle('Parents') parent_section.create_rightside_table() parent_section.append_rightside_anchor(Anchor('hello.there.dude', 'edit')) parent_section.append_rightside_anchor(Anchor('hello.there.dudee', 'edit2')) self.body.appendChild(parent_section) for parent in parents: pp = Anchor('show.parent.%s' % parent, parent) plist.appendChild(ListItem(pp)) self.body.appendChild(plist) #ptitle_anchor = Anchor('edit.packages.%s' % trait, 'Packages') ptitle = SectionTitle('Packages') ptitle_anchor = Anchor('new.package.%s' % trait, '(new)') td = TD() td.appendChild(ptitle_anchor) ptitle.row.appendChild(td) self.body.appendChild(ptitle) rows = self.trait.packages(trait=trait, action=True) self.body.appendChild(PackageTable(rows, bgcolor='SkyBlue3')) ttitle = Anchor('edit.templates.%s' % trait, 'Templates') self.body.appendChild(SectionTitle(ttitle)) rows = self.trait.templates(trait=trait, fields=['package', 'template', 'templatefile']) if len(rows): self.body.appendChild(TemplateTable(rows, bgcolor='DarkSeaGreen3')) self.body.appendChild(SectionTitle('Variables', href='foo.var.ick')) if len(self.trait.environ.keys()): env = TraitEnvTable(trait, self.trait.environ, bgcolor='MistyRose3') self.body.appendChild(env) self.body.appendChild(SectionTitle('Scripts')) slist = UnorderedList() for row in self.trait._scripts.scripts(trait=trait): script = row.script p = Paragraph() sa = Anchor('show.script.%s' % script, script) ea = Anchor('edit.script.%s' % script, ' (edit)') p.appendChild(sa) p.appendChild(ea) slist.appendChild(ListItem(p)) self.body.appendChild(slist)
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ["PAELLA_PROFILE"] self.target = path(os.environ["PAELLA_TARGET"]) self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list(self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) # self.installer = TraitInstaller(self.conn, self.suite) self.installer = ProfileInstaller(self.conn) self.installer.set_logfile() self.installer.set_profile(self.profile) self.installer.set_target(self.target) if os.environ.has_key("PAELLA_MACHINE"): self.machine = os.environ["PAELLA_MACHINE"] if os.environ.has_key("PAELLA_TRAIT"): self.set_trait(os.environ["PAELLA_TRAIT"])
def __init__(self, app, parent, suite): SimpleSplitWindow.__init__(self, app, parent, TraitView, 'TraitMainWindow') self.app = app self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.suite = suite self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.trait = Trait(self.conn, suite=suite) self.refreshListView() self.view.set_suite(suite) self.resize(600, 800) self.setCaption('%s traits' % suite)
class TraitDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn) def set_trait(self, trait): self.clear_body() self.trait.set_trait(trait) title = SimpleTitleElement("Trait: %s" % trait, bgcolor="IndianRed", width="100%") self.body.appendChild(title) self.body.appendChild(HR()) plist = UnorderedList() parents = self.trait.parents(trait=trait) parent_section = SectionTitle("Parents") parent_section.create_rightside_table() parent_section.append_rightside_anchor(Anchor("hello.there.dude", "edit")) parent_section.append_rightside_anchor(Anchor("hello.there.dudee", "edit2")) self.body.appendChild(parent_section) for parent in parents: pp = Anchor("show.parent.%s" % parent, parent) plist.appendChild(ListItem(pp)) self.body.appendChild(plist) # ptitle_anchor = Anchor('edit.packages.%s' % trait, 'Packages') ptitle = SectionTitle("Packages") ptitle_anchor = Anchor("new.package.%s" % trait, "(new)") td = TD() td.appendChild(ptitle_anchor) ptitle.row.appendChild(td) self.body.appendChild(ptitle) rows = self.trait.packages(trait=trait, action=True) self.body.appendChild(PackageTable(rows, bgcolor="SkyBlue3")) ttitle = Anchor("edit.templates.%s" % trait, "Templates") self.body.appendChild(SectionTitle(ttitle)) rows = self.trait.templates(trait=trait, fields=["package", "template", "templatefile"]) if len(rows): self.body.appendChild(TemplateTable(rows, bgcolor="DarkSeaGreen3")) self.body.appendChild(SectionTitle("Variables", href="foo.var.ick")) if len(self.trait.environ.keys()): env = TraitEnvTable(trait, self.trait.environ, bgcolor="MistyRose3") self.body.appendChild(env) self.body.appendChild(SectionTitle("Scripts")) slist = UnorderedList() for row in self.trait._scripts.scripts(trait=trait): script = row.script sa = Anchor("show.script.%s" % script, script) slist.appendChild(ListItem(sa)) self.body.appendChild(slist)
def __init__(self, parent, suite): BaseSplitWindow.__init__(self, parent, TraitView, name='TraitMainWindow-%s' % suite) print 'in TraitMainWindow suite is', suite # from BasePaellaWindow self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.mainView.set_suite(suite) self.setCaption('%s traits' % suite) # these values should be in a configfile self.resize(500, 800) self.splitter.setSizes([100, 400]) self.trait = Trait(self.conn, suite=suite) self.refreshListView() # dialog pointers self._import_export_dirsel_dialog = None
class TraitDescriptionWindow(BaseTextEditWindow): def __init__(self, parent, trait, suite, name='TraitDescriptionWindow'): BaseTextEditWindow.__init__(self, parent, KTextEdit, name=name) self.initPaellaCommon() self.trait = Trait(self.conn, suite=suite) self.trait.set_trait(trait) self.resize(600, 800) desc = self.trait.get_description() if desc is not None: self.mainView.setText(desc) def _status_msg(self, status=None): msg = 'Description of trait %s' % self.trait.current_trait if status is None: return msg else: return '%s %s' % (status, msg) def slotSave(self): text = str(self.mainView.text()) oldtext = self.trait.get_description() if oldtext is None: oldtext = '' if oldtext != text: self.trait.set_description(text) self._update_status('Saved') else: KMessageBox.information(self, 'Nothing has changed') self._update_status()
class ParentAssigner(BaseAssigner): def __init__(self, parent, trait, suite, name='ParentAssigner'): self.app = get_application_pointer() self.conn = self.app.conn self.suite = suite self.trait = Trait(self.conn, suite=self.suite) self.trait.set_trait(trait) BaseAssigner.__init__(self, parent, name=name) self.connect(self, SIGNAL('okClicked()'), self.slotInsertNewParents) def initView(self): traits = self.trait.get_trait_list() traits.sort() parents = self.trait.parents() traits = [t for t in traits if t != self.trait.current_trait] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() avail_traits = [t for t in traits if t not in parents] for trait in avail_traits: r = QListBoxText(abox, trait) for trait in parents: r = QListBoxText(sbox, trait) def slotInsertNewParents(self): sbox = self.listBox.selectedListBox() parents = [str(sbox.item(n).text()) for n in range(sbox.numRows())] self.trait.update_parents(parents)
def readdir(self, fspath, offset): dirents = ['.', '..'] if fspath == '/': dirents.extend(self.db.suitecursor.get_suites()) else: logging.warn("Need to handle %s" % fspath) depth = fspath.count('/') logging.warn('depth is %d' % depth) if depth == 1: suite = os.path.basename(fspath) logging.info('fspath is %s' % fspath) logging.info('suite is %s' % suite) traitdb = Trait(self.conn, suite) traits = traitdb.get_trait_list() dirents.extend(traits) elif depth == 2: trait = os.path.basename(fspath) dirname = os.path.dirname(fspath) suite = os.path.basename(dirname) logging.info('depth 2, suite %s, trait %s' % (suite, trait)) dirents.extend(['scripts', 'templates']) elif depth == 3: ignore, suite, trait, ftype = fspath.split('/') logging.info('ftype is %s' % ftype) logging.info('suite is %s' % suite) logging.info('trait is %s' % trait) traitdb = Trait(self.conn, suite) traitdb.set_trait(trait) if ftype == 'scripts': scripts = traitdb._scripts.scripts(trait=trait) scripts = [row.script for row in scripts] dirents.extend(scripts) else: logging.warn('unable to handle ftype %s' % ftype) else: logging.warn('unable to handle depth of %d' % depth) for ent in dirents: yield fuse.Direntry(ent)
class TraitManagerBrowser(ListNoteBook): def __init__(self, conn, suite=None): self.menu = make_menu(TRAITCMDS, self.trait_command) ListNoteBook.__init__(self) self.conn = conn self.suite = suite self.reset_rows() for page in ['parents', 'packages', 'templates', 'scripts']: self.append_page(ScrollCList(), page) def set_suite(self, suite): self.suite = suite self.reset_rows() def trait_command(self, *args): print args def reset_rows(self): if self.suite is None: self.traits = None self.set_rows([]) else: self.traits = Trait(self.conn, self.suite) self.set_rows(self.traits.get_traits()) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0][0] self.select_trait(trait) def select_trait(self, trait): for page in ['parents', 'packages', 'templates', 'scripts']: if page in self.pages: self.remove_page(page) self.append_page(TraitBrowser(self.conn, self.suite), 'parents') self.pages['parents'].select_trait(trait) self.append_page(TemplateBrowser(self.conn, self.suite, trait), 'templates') self.append_page(ScriptBrowser(self.conn, self.suite, trait), 'scripts')
def __init__(self, conn, fspath, flags, *mode): logging.info('PaellaFile.__init__ start') self.conn = conn self.fileobj = None self.info = pathinfo(fspath) #logging.info('info %s' % self.info) #logging.info('conn %s' % self.conn) self.fspath = fspath self.traitdb = Trait(self.conn, self.info['suite']) #logging.info('traitdb %s' % self.traitdb) #logging.info('set trait to %s' % self.info['trait']) self.traitdb.set_trait(self.info['trait']) logging.info('traitdb.current_trait %s' % self.traitdb.current_trait) #logging.info('PaellaFile.__init__ info: %s' % self.info) fname = self.info['fname'] ftype = self.info['ftype'] if ftype == 'scripts': self. fileobj = self.traitdb._scripts.scriptfile(fname) else: logging.warn('Unable to handle ftype of %s' % ftype) logging.info('PaellaFile initialized with %s, %s' % (ftype, fname))
class TraitManagerBrowser(ListNoteBook): def __init__(self, conn, suite=None): self.menu = make_menu(TRAITCMDS, self.trait_command) ListNoteBook.__init__(self) self.conn = conn self.suite = suite self.reset_rows() for page in ["parents", "packages", "templates", "scripts"]: self.append_page(ScrollCList(), page) def set_suite(self, suite): self.suite = suite self.reset_rows() def trait_command(self, *args): print args def reset_rows(self): if self.suite is None: self.traits = None self.set_rows([]) else: self.traits = Trait(self.conn, self.suite) self.set_rows(self.traits.get_traits()) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0][0] self.select_trait(trait) def select_trait(self, trait): for page in ["parents", "packages", "templates", "scripts"]: if page in self.pages: self.remove_page(page) self.append_page(TraitBrowser(self.conn, self.suite), "parents") self.pages["parents"].select_trait(trait) self.append_page(TemplateBrowser(self.conn, self.suite, trait), "templates") self.append_page(ScriptBrowser(self.conn, self.suite, trait), "scripts")
class TraitBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(['delete'], self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.suite = suite self.trait = Trait(self.conn, self.suite) self.package_menu = make_menu(['install', 'remove', 'purge', 'drop'], self.set_package) self.parent_menu = make_menu(['drop'], self.modify_parent) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.package_menu), 'packages') self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents') self.set_size_request(400, 300) def modify_parent(self, menuitem, action): if action == 'drop': parents = self._get_listbox_col_('parents', 'trait') self.trait.delete_parents(parents) self.__set_pages(self.current_trait) def modify_trait(self, menuitem, action): if action == 'delete': trait = self.listbox.get_selected_data()[0].trait self.trait.delete_trait(trait) self.reset_rows() def reset_rows(self): self.set_rows(self.trait.get_traits()) self.set_row_select(self.trait_selected) def __set_droptargets__(self, pages): set_receive_targets(pages['packages'].listbox, self.drop_package, TARGETS.get('package', self.suite)) set_receive_targets(pages['parents'].listbox, self.drop_trait, TARGETS.get('trait', self.suite)) def set_package(self, menu_item, action): packages = self._get_listbox_col_('packages', 'package') trait = self.current_trait self.trait.set_action(action, packages) self.__set_pages(self.current_trait) def pop_mymenu(self, widget, event, menu): if right_click_pressed(event): menu.popup(None, None, None, event.button, event.time) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0].trait self.select_trait(trait) def select_trait(self, trait): self.current_trait = trait self.trait.set_trait(trait) self.__set_pages(self.current_trait) def __set_pages(self, trait): pages = dict(self.pages) pages['packages'].set_rows(self.trait.packages(action=True)) pages['packages'].set_select_mode('multi') pages['parents'].set_rows(self.trait.parents(), ['trait']) pages['parents'].set_select_mode('multi') self.__set_droptargets__(pages) def drop_package(self, listbox, context, x, y, selection, targettype, time): packages = Set(selection.data.split('^&^')) self.trait.insert_packages(packages) self.__set_pages(self.current_trait) def drop_trait(self, listbox, context, x, y, selection, targettype, time): traits = selection.data.split('^&^') self.trait.insert_parents(traits) self.__set_pages(self.current_trait) def _get_listbox_col_(self, page, field): pages = dict(self.pages) return [row[field] for row in pages[page].listbox.get_selected_data()] def change_suite(self, suite): self.suite = suite self.trait = Trait(self.conn, self.suite) self.reset_rows()
def set_suite(self, suite): self.suite = suite self.listView.set_suite(suite) self.trait = Trait(self.conn, suite=suite)
class TraitMainWindow(BaseSplitWindow, BasePaellaWindow): def __init__(self, parent, suite): BaseSplitWindow.__init__(self, parent, TraitView, name='TraitMainWindow-%s' % suite) print 'in TraitMainWindow suite is', suite # from BasePaellaWindow self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.mainView.set_suite(suite) self.setCaption('%s traits' % suite) # these values should be in a configfile self.resize(500, 800) self.splitter.setSizes([100, 400]) self.trait = Trait(self.conn, suite=suite) self.refreshListView() # dialog pointers self._import_export_dirsel_dialog = None def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newTraitAction = KStdAction.openNew(self.newTrait, collection) self.importTraitAction = KStdAction.open(self.slotImportTrait, collection) self.exportTraitAction = KStdAction.saveAs(self.slotExportTrait, collection) def initMenus(self): mainmenu = KPopupMenu(self) menus = [mainmenu] menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) menubar.insertItem('&Help', self.helpMenu('')) self.newTraitAction.plug(mainmenu) self.importTraitAction.plug(mainmenu) self.importTraitAction.setText('Import trait') self.exportTraitAction.plug(mainmenu) self.exportTraitAction.setText('Export trait') self.quitAction.plug(mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newTraitAction.plug(toolbar) self.importTraitAction.plug(toolbar) self.exportTraitAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.addColumn('trait') def refreshListView(self): self.listView.clear() for trait in self.trait.get_trait_list(): item = KListViewItem(self.listView, trait) item.trait = trait def newTrait(self): win = NewTraitDialog(self) win.frame.text_label.setText('Add a new trait.') win.connect(win, SIGNAL('okClicked()'), self.insertNewTrait) win.show() self._new_trait_dialog = win def insertNewTrait(self): dialog = self._new_trait_dialog trait = dialog.getRecordData()['name'] self.trait.create_trait(trait) self.refreshListView() def slotImportTrait(self): self._select_import_export_directory('import') def slotExportTrait(self): self._select_import_export_directory('export') def _select_import_export_directory(self, action): default_path = path(self.app.cfg.get('database', 'default_path')).expand() win = KDirSelectDialog(default_path, False, self) win.connect(win, SIGNAL('okClicked()'), self._import_export_directory_selected) win.db_action = action win.show() self._import_export_dirsel_dialog = win def _import_export_directory_selected(self): win = self._import_export_dirsel_dialog if win is None: raise RuntimeError , "There is no import/export dialog" url = win.url() fullpath = str(url.path()) action = win.db_action if action == 'import': KMessageBox.information(self, "%s trait not implemented yet" % action) elif action == 'export': KMessageBox.information(self, "%s trait not implemented yet" % action) else: KMessageBox.error(self, "action %s is not supported" % action) def selectionChanged(self): item = self.listView.currentItem() self.mainView.set_trait(item.trait)
class TraitMainWindow(BaseSplitWindow, BasePaellaWindow): def __init__(self, parent, suite): BaseSplitWindow.__init__(self, parent, TraitView, name='TraitMainWindow-%s' % suite) print 'in TraitMainWindow suite is', suite # from BasePaellaWindow self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.mainView.set_suite(suite) self.setCaption('%s traits' % suite) # these values should be in a configfile self.resize(500, 800) self.splitter.setSizes([100, 400]) self.trait = Trait(self.conn, suite=suite) self.refreshListView() # dialog pointers self._import_export_dirsel_dialog = None def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newTraitAction = KStdAction.openNew(self.newTrait, collection) self.importTraitAction = KStdAction.open(self.slotImportTrait, collection) self.exportTraitAction = KStdAction.saveAs(self.slotExportTrait, collection) def initMenus(self): mainmenu = KPopupMenu(self) menus = [mainmenu] menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) menubar.insertItem('&Help', self.helpMenu('')) self.newTraitAction.plug(mainmenu) self.importTraitAction.plug(mainmenu) self.importTraitAction.setText('Import trait') self.exportTraitAction.plug(mainmenu) self.exportTraitAction.setText('Export trait') self.quitAction.plug(mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newTraitAction.plug(toolbar) self.importTraitAction.plug(toolbar) self.exportTraitAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.addColumn('trait') def refreshListView(self): self.listView.clear() for trait in self.trait.get_trait_list(): item = KListViewItem(self.listView, trait) item.trait = trait def newTrait(self): win = NewTraitDialog(self) win.frame.text_label.setText('Add a new trait.') win.connect(win, SIGNAL('okClicked()'), self.insertNewTrait) win.show() self._new_trait_dialog = win def insertNewTrait(self): dialog = self._new_trait_dialog trait = dialog.getRecordData()['name'] self.trait.create_trait(trait) self.refreshListView() def slotImportTrait(self): self._select_import_export_directory('import') def slotExportTrait(self): self._select_import_export_directory('export') def _select_import_export_directory(self, action): default_path = path(self.app.cfg.get('database', 'default_path')).expand() win = KDirSelectDialog(default_path, False, self) win.connect(win, SIGNAL('okClicked()'), self._import_export_directory_selected) win.db_action = action win.show() self._import_export_dirsel_dialog = win def _import_export_directory_selected(self): win = self._import_export_dirsel_dialog if win is None: raise RuntimeError, "There is no import/export dialog" url = win.url() fullpath = str(url.path()) action = win.db_action if action == 'import': KMessageBox.information(self, "%s trait not implemented yet" % action) elif action == 'export': KMessageBox.information(self, "%s trait not implemented yet" % action) else: KMessageBox.error(self, "action %s is not supported" % action) def selectionChanged(self): item = self.listView.currentItem() self.mainView.set_trait(item.trait)
def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn)
def change_suite(self, suite): self.suite = suite self.trait = Trait(self.conn, self.suite) self.reset_rows()
class InstallerTools(object): def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list(self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT']) def env(self): env = RefDict(self.tp.Environment()) env.update(self.pr.get_family_data()) env.update(self.pr.get_profile_data()) return env def set_trait(self, trait): self.trait = trait self.tp.set_trait(trait) self.tr.set_trait(trait) self.parents = self.tr.parents() self._envv = self.env() self.installer.set_trait(trait) self.packages = self.installer.traitpackage.packages() self.templates = self.installer.traittemplate.templates() def get(self, key): if self._envv is None: raise Error, 'need to set trait first' return self._envv.dereference(key) def install_modules(self, name): modules = str2list(self.get(name)) print 'installing modules', modules, 'to %s/etc/modules' % self.target setup_modules(self.target, modules) def remove_packages(self, packages=None): if packages is None: packages = self.packages if len(packages): if hasattr(packages[0], 'package'): packages = [p.package for p in packages] package_list = ' '.join(packages) command = 'apt-get -y remove %s' % package_list self.installer.run('remove', command, proc=True)
class InstallerTools(object): def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ["PAELLA_PROFILE"] self.target = path(os.environ["PAELLA_TARGET"]) self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list(self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) # self.installer = TraitInstaller(self.conn, self.suite) self.installer = ProfileInstaller(self.conn) self.installer.set_logfile() self.installer.set_profile(self.profile) self.installer.set_target(self.target) if os.environ.has_key("PAELLA_MACHINE"): self.machine = os.environ["PAELLA_MACHINE"] if os.environ.has_key("PAELLA_TRAIT"): self.set_trait(os.environ["PAELLA_TRAIT"]) # this needs updating for machine type data def env(self): env = TemplatedEnvironment(self.tp.Environment()) env.update(self.pr.get_family_data()) env.update(self.pr.get_profile_data()) return env def set_trait(self, trait): self.trait = trait self.tp.set_trait(trait) self.tr.set_trait(trait) self.parents = self.tr.parents() self._envv = self.env() tinstaller = self.installer.installer tinstaller.set_trait(trait) self.packages = tinstaller.traitpackage.packages() self.templates = tinstaller.traittemplate.templates() def get(self, key): if self._envv is None: raise Error, "need to set trait first" return self._envv.dereference(key) def lget(self, key): key = "_".join([self.trait, key]) return self.get(key) def install_modules(self, name): modules = str2list(self.get(name)) print "installing modules", modules, "to %s/etc/modules" % self.target setup_modules(self.target, modules) def remove_packages(self, packages=None): if packages is None: packages = self.packages if len(packages): if hasattr(packages[0], "package"): packages = [p.package for p in packages] package_list = " ".join(packages) command = "apt-get -y remove %s" % package_list self.installer.run("remove", command, proc=True) def chroot_command(self, cmd): return "chroot %s %s" % (self.target, cmd)
def set_profile(self, profile): self.profile.set_profile(profile) self.suite = self.profile.current.suite self.trait = Trait(self.conn, self.suite)
def set_suite(self, suite): self.doc.suite = suite self.doc.trait = Trait(self.app.conn, suite=suite)
class TraitMainWindow(SimpleSplitWindow): def __init__(self, app, parent, suite): SimpleSplitWindow.__init__(self, app, parent, TraitView, 'TraitMainWindow') self.app = app self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.suite = suite self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.trait = Trait(self.conn, suite=suite) self.refreshListView() self.view.set_suite(suite) self.resize(600, 800) self.setCaption('%s traits' % suite) def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newTraitAction = KStdAction.openNew(self.newTrait, collection) def initMenus(self): mainMenu = KPopupMenu(self) menus = [mainMenu] self.menuBar().insertItem('&Main', mainMenu) self.menuBar().insertItem('&Help', self.helpMenu('')) self.newTraitAction.plug(mainMenu) self.quitAction.plug(mainMenu) def initToolbar(self): toolbar = self.toolBar() self.newTraitAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.setRootIsDecorated(True) self.listView.addColumn('group') def refreshListView(self): self.listView.clear() trait_folder = KListViewItem(self.listView, 'traits') for trait in self.trait.get_trait_list(): item = KListViewItem(trait_folder, trait) item.trait = trait def newTrait(self): dialog = SimpleRecordDialog(self, ['trait']) dialog.connect(dialog, SIGNAL('okClicked()'), self.insertNewTrait) self._dialog = dialog def insertNewTrait(self): dialog = self._dialog data = dialog.getRecordData() trait = data['trait'] self.trait.create_trait(trait) self.refreshListView() def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'trait'): print 'trait is', current.trait self.view.set_trait(current.trait) if hasattr(current, 'suite'): print 'suite is', current.suite if hasattr(current, 'widget'): print 'widget is', current.widget
from useless.base.path import path from paella.base import PaellaConfig from paella.db import PaellaConnection from paella.db.trait import Trait from paella.db.family import Family from paella.db.profile import Profile from paella.db.machine import MachineHandler from paella.db.installer import InstallerManager from paella.db import DefaultEnvironment from paella.installer.toolkit import InstallerTools if __name__ == '__main__': cfg = PaellaConfig() conn = PaellaConnection() suite = 'bootstrap' t = Trait(conn, suite) f = Family(conn) p = Profile(conn) m = MachineHandler(conn) de = DefaultEnvironment(conn) im = InstallerManager(conn) #os.environ['PAELLA_MACHINE'] = 'testmachine' os.environ['PAELLA_PROFILE'] = 'default' os.environ['PAELLA_TARGET'] = path('/foo/bar') it = InstallerTools()
import os from paella.base import PaellaConfig from paella.db import PaellaConnection from paella.db.trait import Trait from paella.db.family import Family from paella.db.profile import Profile from paella.db.machine import MachineHandler from paella.db.installer import InstallerManager from paella.db import DefaultEnvironment from paella.installer.toolkit import InstallerTools if __name__ == '__main__': cfg = PaellaConfig() conn = PaellaConnection() t = Trait(conn) f = Family(conn) p = Profile(conn) m = MachineHandler(conn) de = DefaultEnvironment(conn) im = InstallerManager(conn)
def insertNewProfile(self): dialog = self._dialog data = dialog.getRecordData() if data['profile'] not in self.profile.get_profile_list(): #self.profile.insert(data=data) self.profile.copy_profile('skeleton', data['profile']) else: KMessageBox.information( self, 'profile %s already exists.' % data['profile']) #KMessageBox.information(self, 'Make new profile %s' % data['profile']) self.refreshListView() def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'profile'): self.view.set_profile(current.profile) if hasattr(current, 'trait'): print 'trait is', current.trait self.view.set_trait(current.trait) if hasattr(current, 'suite'): print 'suite is', current.suite if hasattr(current, 'widget'): print 'widget is', current.widget if __name__ == '__main__': cfg = PaellaConfig() conn = PaellaConnection(cfg) t = Trait(conn, suite='kudzu')