def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite
class TraitTemplateBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite def modify_trait(self, menuitem, action): if action == 'hello': dialogs.Message('hello') elif action in ['import', 'update']: filesel = select_a_file(action, self.tarball_path + '/', self.select_trait_tarball) elif action in ['updatedir', 'exportdir', 'importdir']: filesel = select_a_file(action, self.tarball_path + '/', self.select_traitdir) elif action == 'export': try: trait = self.listbox.get_selected_data()[0].trait #self.pages[trait].extract_packages() self.select_export_path(trait) except IndexError: dialogs.Message('no trait selected') elif action == 'extract': try: trait = self.listbox.get_selected_data()[0].trait self.pages[trait].extract_packages() except IndexError: dialogs.Message('no trait selected') def reset_rows(self): if self.trait_selection == '_all_traits_': rows = self.traits.select(fields=['trait']) self.set_rows(rows) else: clause = Eq('profile', self.trait_selection) rows = self.cursor.select(fields=['trait'], table='profile_trait', clause=clause) ptraits = [x.trait for x in rows] traits = self._parents.get_traitset(ptraits) self.set_rows(list(traits), [self.trait_selection]) 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): if trait not in self.pages: newpage = TemplateBrowser(self.conn, self.traits.suite, trait) self.append_page(newpage, trait) self.set_current_page(trait) def set_suite(self, suite): self.suite = suite self.traits.set_suite(suite) for page in self.pages: self.remove_page(page) self.reset_rows() def select_traitdir(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if not isdir(path): path = dirname(path) if not isdir(path): raise Error, '%s not found' % path if action in ['updatedir', 'importdir']: if action == 'updatedir': tcmd = 'update' elif action == 'importdir': tcmd = 'import' traits = [t.trait for t in self.traits.select()] if tcmd == 'update': ls = [ f for f in os.listdir(path) if f[-4:] == '.tar' and f[:-4] in traits ] for f in ls: self.importupdate(join(path, f), tcmd) elif tcmd == 'import': ls = [f for f in os.listdir(path) if f[-4:] == '.tar'] traits = [t[:-4] for t in ls] while len(traits): trait = traits[0] try: self.importupdate(join(path, trait + '.tar'), tcmd) except UnbornError: traits.append(trait) del traits[0] print 'processed', trait elif action == 'exportdir': self.select_export_path('_all_traits_') def select_trait_tarball(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() self.importupdate(path, action) 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 select_export_path(self, trait): filesel = select_a_file(trait, self.tarball_path + '/', self.export_path_selected) def export_path_selected(self, button, filesel): trait = filesel.get_data('action') path = dirname(filesel.get_filename()) filesel.destroy() if trait == '_all_traits_': traits = [t.trait for t in self.traits.select()] for t in traits: self.export_trait(t, path) else: self.export_trait(trait, path) def export_trait(self, trait, path=None): if path is None: path = self.tarball_path tt = TraitTemplate(self.conn, self.suite) tt.set_trait(trait) backup_trait(self.conn, self.suite, trait, path) dialogs.Message('%s exported to %s' % (trait, path))
class TraitTemplateBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite def modify_trait(self, menuitem, action): if action == 'hello': dialogs.Message('hello') elif action in ['import', 'update']: filesel = select_a_file(action, self.tarball_path + '/', self.select_trait_tarball) elif action in ['updatedir', 'exportdir', 'importdir']: filesel = select_a_file(action, self.tarball_path + '/', self.select_traitdir) elif action == 'export': try: trait = self.listbox.get_selected_data()[0].trait #self.pages[trait].extract_packages() self.select_export_path(trait) except IndexError: dialogs.Message('no trait selected') elif action == 'extract': try: trait = self.listbox.get_selected_data()[0].trait self.pages[trait].extract_packages() except IndexError: dialogs.Message('no trait selected') def reset_rows(self): if self.trait_selection == '_all_traits_': rows = self.traits.select(fields=['trait']) self.set_rows(rows) else: clause = Eq('profile', self.trait_selection) rows = self.cursor.select(fields=['trait'], table='profile_trait', clause=clause) ptraits = [x.trait for x in rows] traits = self._parents.get_traitset(ptraits) self.set_rows(list(traits), [self.trait_selection]) 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): if trait not in self.pages: newpage = TemplateBrowser(self.conn, self.traits.suite, trait) self.append_page(newpage, trait) self.set_current_page(trait) def set_suite(self, suite): self.suite = suite self.traits.set_suite(suite) for page in self.pages: self.remove_page(page) self.reset_rows() def select_traitdir(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if not isdir(path): path = dirname(path) if not isdir(path): raise Error, '%s not found' % path if action in ['updatedir', 'importdir']: if action == 'updatedir': tcmd = 'update' elif action == 'importdir': tcmd = 'import' traits = [t.trait for t in self.traits.select()] if tcmd == 'update': ls = [f for f in os.listdir(path) if f[-4:] == '.tar' and f[:-4] in traits] for f in ls: self.importupdate(join(path, f), tcmd) elif tcmd == 'import': ls = [f for f in os.listdir(path) if f[-4:] == '.tar'] traits = [t[:-4] for t in ls] while len(traits): trait = traits[0] try: self.importupdate(join(path, trait + '.tar'), tcmd) except UnbornError: traits.append(trait) del traits[0] print 'processed', trait elif action == 'exportdir': self.select_export_path('_all_traits_') def select_trait_tarball(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() self.importupdate(path, action) 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 select_export_path(self, trait): filesel = select_a_file(trait, self.tarball_path + '/', self.export_path_selected) def export_path_selected(self, button, filesel): trait = filesel.get_data('action') path = dirname(filesel.get_filename()) filesel.destroy() if trait == '_all_traits_': traits = [t.trait for t in self.traits.select()] for t in traits: self.export_trait(t, path) else: self.export_trait(trait, path) def export_trait(self, trait, path=None): if path is None: path = self.tarball_path tt = TraitTemplate(self.conn, self.suite) tt.set_trait(trait) backup_trait(self.conn, self.suite, trait, path) dialogs.Message('%s exported to %s' % (trait, path))