def export_client(self, client): cpath, ppath, fpath, tpath = self._cpaths_(client) makepaths(cpath) profiles, families, traits = self._client_schema(client) disks, mtypes, machines = self._client_mdata(client) if not disks: disks = None if not mtypes: mtypes = None if not machines: machines = None element = ClientMachineDatabaseElement(self.conn, disks, mtypes, machines) mdbpath = join(cpath, 'machine_database.xml') mdfile = file(mdbpath, 'w') mdfile.write(element.toprettyxml()) mdfile.close() if profiles: makepaths(ppath) pp = PaellaProfiles(self.conn) for profile in profiles: pp.write_profile(profile, ppath) if families: makepaths(fpath) f = Family(self.conn) for family in families: f.write_family(family, fpath) if traits: makepaths(tpath)
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'])
def __init__(self, conn): BaseMachineTypeHandler.__init__(self, conn) self._parents = MachineTypeParent(self.conn) self._mtfam = MachineTypeFamily(self.conn) self._fam = Family(self.conn) self._mtscript = MachineTypeScript(self.conn) self.parent = None
class FamilyDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.family = Family(self.conn) def set_family(self, family): self.family.set_family(family) parents = self.family.parents() erows = self.family.environment_rows() self.clear_body() title = SectionTitle('Family: %s' % family) title['bgcolor'] = 'IndianRed' title['width'] = '100%' self.body.append(title) parent_anchor = Anchor('Parents', href='edit.parents.%s' % family) self.body.append(SectionTitle(parent_anchor)) if len(parents): plist = UnorderedList() for p in parents: plist.append(ListItem(p)) self.body.append(plist) vtitle = Anchor('Variables', href='edit.variables.%s' % self.family.current) self.body.append(SectionTitle(vtitle)) if len(erows): self.body.append(PVarTable(erows, bgcolor='MistyRose2')) self.body.append(Ruler()) del_anchor = Anchor('delete', href='delete.family.%s' % family) self.body.append(del_anchor)
def __init__(self, app, parent, name='FamilyList'): KListView.__init__(self, parent, name) dbwidget(self, app) self.family = Family(self.conn) self.setRootIsDecorated(True) self.addColumn('family') self.refreshlistView()
def __init__(self, conn): StatementCursor.__init__(self, conn) self.conn = conn self.set_table('profiles') self._traits = ProfileTrait(conn) self._env = ProfileEnvironment(conn) self._pfam = StatementCursor(conn) self._pfam.set_table('profile_family') self._fam = Family(conn)
def __init__(self, parent, name='FamilyList'): KListView.__init__(self, parent, name) self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) self.setRootIsDecorated(True) self.addColumn('family') self.refreshlistView()
def __init__(self, parent, family): self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) self.family.set_family(family) BaseAssigner.__init__(self, parent, name='FamilyParentAssigner', udbuttons=False) self.connect(self, SIGNAL('okClicked()'), self.slotAssignParents)
def initView(self): self.suite = self.profile.current.suite self.family = Family(self.conn) all_fams = self.family.all_families() pfams = self.profile.get_families() fams = [f for f in all_fams if f not in pfams] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for family in pfams: self._add_family_to_listbox(sbox, family) for family in fams: self._add_family_to_listbox(abox, family)
def __init__(self, conn): self.menu = make_menu(['delete'], self.modify_family) ListNoteBook.__init__(self) self.conn = conn self.family = Family(self.conn) self.var_menu = make_menu(['edit', 'nothing', 'nothing', 'drop'], self.var_menu_selected) self.parent_menu = make_menu(['drop'], self.modify_parent) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.var_menu), 'environment') self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents') self.set_size_request(400, 300)
def import_client(self, client): cpath, ppath, fpath, tpath = self._cpaths_(client) profiles, families, traits = self._client_schema(client) mdbpath = join(cpath, 'machine_database.xml') if families: f = Family(self.conn) f.import_families(fpath) if profiles: importer = PaellaImporter(self.conn) importer.import_all_profiles(ppath) mh = MachineHandler(self.conn) md = mh.parse_xmlfile(mdbpath) mh.insert_parsed_element(md)
class FamilyParentAssigner(BaseAssigner): def __init__(self, parent, family): self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) self.family.set_family(family) BaseAssigner.__init__(self, parent, name='FamilyParentAssigner', udbuttons=False) self.connect(self, SIGNAL('okClicked()'), self.slotAssignParents) def initView(self): family = self.family.current all_fams = self.family.all_families() assigned_parents = self.family.parents() avail_parents = [f for f in all_fams if f not in assigned_parents + [family]] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for family in assigned_parents: self._add_family_to_listbox(sbox, family) for family in avail_parents: self._add_family_to_listbox(abox, family) self.already_assigned = assigned_parents def _add_family_to_listbox(self, box, family): item = QListBoxText(box, family) item.family = family def slotAssignParents(self): sbox = self.listBox.selectedListBox() families =[str(sbox.item(n).text()) for n in range(sbox.numRows())] # since we're using a SimpleRelation class for # family.parents, we don't need to worry about # inserting families that are already there self.family.delete_parents() self.family.insert_parents(families)
def __init__(self, parent): BaseSplitWindow.__init__(self, parent, FamilyView, name='FamilyMainWindow') self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.cursor = self.conn.cursor(statement=True) self.family = Family(self.conn) self.refreshListView() self.resize(600, 800) self.splitter.setSizes([100, 500]) self.setCaption('Paella Families') self._new_family_dialog = None
def import_client(self, client): cpath, ppath, fpath, tpath = self._cpaths_(client) profiles, families, traits = self._client_schema(client) mdbpath = join(cpath, 'machine_database.xml') if families: f = Family(self.conn) f.import_families(fpath) if profiles: pp = PaellaProcessor(self.conn, self.cfg) pp.main_path = cpath pp.insert_profiles() mh = MachineHandler(self.conn) md = mh.parse_xmlfile(mdbpath) mh.insert_parsed_element(md)
def __init__(self, conn, name='FamilyDiffer'): VBox.__init__(self) self.set_name(name) self.conn = conn self.view = TwinScrollCList(name=name) self.cursor = StatementCursor(self.conn) self.lfamily = Family(self.conn) self.rfamily = Family(self.conn) self.add(self.view) self.udbar = UDBar() self.pack_end(self.udbar, 0, 0, 0) self.show() self.udbar.ubutton.connect('clicked', self.update_pressed) self.udbar.dbutton.connect('clicked', self.diff_selection)
def __init__(self, app, parent): SimpleSplitWindow.__init__(self, app, parent, FamilyView, 'FamilyMainWindow') self.app = app self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.family = Family(self.conn) self.refreshListView() self.resize(600, 800) self.setCaption('paella families')
class FamilyAssigner(BaseAssigner): def __init__(self, parent, profile): self.app = get_application_pointer() self.conn = self.app.conn self.profile = Profile(self.conn) self.profile.set_profile(profile) BaseAssigner.__init__(self, parent, name="FamilyAssigner", udbuttons=True) self.connect(self, SIGNAL("okClicked()"), self.slotInsertNewFamilies) def initView(self): self.suite = self.profile.current.suite self.family = Family(self.conn) all_fams = self.family.all_families() pfams = self.profile.get_families() fams = [f for f in all_fams if f not in pfams] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for family in pfams: self._add_family_to_listbox(sbox, family) for family in fams: self._add_family_to_listbox(abox, family) def _add_family_to_listbox(self, box, family): r = QListBoxText(box, family) r.family = family def slotInsertNewFamilies(self): sbox = self.listBox.selectedListBox() families = [str(sbox.item(n).text()) for n in range(sbox.numRows())] self.profile.delete_all_families() for family in families: self.profile.append_family(family)
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 __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"])
class FamilyList(KListView): def __init__(self, parent, name='FamilyList'): KListView.__init__(self, parent, name) self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) self.setRootIsDecorated(True) self.addColumn('family') self.refreshlistView() def refreshlistView(self): self.clear() rows = self.family.family_rows() for row in rows: item = KListViewItem(self, row.family) item.family = row.family def getData(self): item = self.currentItem() return FamilyVariablesConfig(self.conn, item.family) def updateData(self, data): raise MethodNotImplementedError(self, 'FamilyList.updateData')
class FamilyDiffer(VBox): def __init__(self, conn, name='FamilyDiffer'): VBox.__init__(self) self.set_name(name) self.conn = conn self.view = TwinScrollCList(name=name) self.cursor = StatementCursor(self.conn) self.lfamily = Family(self.conn) self.rfamily = Family(self.conn) self.add(self.view) self.udbar = UDBar() self.pack_end(self.udbar, 0, 0, 0) self.show() self.udbar.ubutton.connect('clicked', self.update_pressed) self.udbar.dbutton.connect('clicked', self.diff_selection) def update_pressed(self, button): self.update_lists() def update_lists(self): rows = self.lfamily.family_rows() self.view.lbox.set_rows(rows) self.view.rbox.set_rows(rows) def diff_selection(self, *args): lrow = self.view.lbox.get_selected_data()[0] rrow = self.view.rbox.get_selected_data()[0] lfam, rfam = lrow.family, rrow.family lcfg = FamilyVariablesConfig(self.conn, lfam) rcfg = FamilyVariablesConfig(self.conn, rfam) lcfg.diff(rcfg)
def __init__(self, conn): BaseMachineHandler.__init__(self, conn) self.relation = MachineRelations(self.conn) self.family = Family(self.conn) self.parent = None self.diskconfig = None self.kernel = None
class FamilyAssigner(BaseAssigner): def __init__(self, parent, profile): self.app = get_application_pointer() self.conn = self.app.conn self.profile = Profile(self.conn) self.profile.set_profile(profile) BaseAssigner.__init__(self, parent, name='FamilyAssigner', udbuttons=True) self.connect(self, SIGNAL('okClicked()'), self.slotInsertNewFamilies) def initView(self): self.suite = self.profile.current.suite self.family = Family(self.conn) all_fams = self.family.all_families() pfams = self.profile.get_families() fams = [f for f in all_fams if f not in pfams] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for family in pfams: self._add_family_to_listbox(sbox, family) for family in fams: self._add_family_to_listbox(abox, family) def _add_family_to_listbox(self, box, family): r = QListBoxText(box, family) r.family = family def slotInsertNewFamilies(self): sbox = self.listBox.selectedListBox() families =[str(sbox.item(n).text()) for n in range(sbox.numRows())] self.profile.delete_all_families() for family in families: self.profile.append_family(family)
def __init__(self, conn): BaseMachineDbObject.__init__(self, conn, table='machines') self.parents = MachineParents(self.conn) self.scripts = MachineScripts(self.conn) self.family = MachineFamily(self.conn) self.environment = MachineEnvironment(self.conn) self.config = None # These aren't really actual relations in the # same sense that the above objects are # but they are objects the the machines # table relates to, and should fit nicely in this # class. self.diskconfig = DiskConfigHandler(self.conn) self.kernels = Table_cursor(self.conn, 'kernels') # This is the main family class self.mainfamily = Family(self.conn)
class FamilyView(ViewBrowser): def __init__(self, parent): ViewBrowser.__init__(self, parent, FamilyDoc) self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) def set_family(self, family): self.doc.set_family(family) self.setText(self.doc.output()) self.family.set_family(family) def resetView(self): self.set_family(self.family.current) def setSource(self, url): action, context, ident = split_url(url) if action == 'edit': if context == 'variables': config = self.family.getVariablesConfig(self.family.current) newconfig = config.edit() config.update(newconfig) self.set_family(ident) elif context == 'parents': dialog = FamilyParentAssigner(self, ident) dialog.connect(dialog, SIGNAL('okClicked()'), self.resetView) dialog.show() else: KMessageBox.error(self, 'unable to edit %s for family' % context) elif action == 'delete': if context == 'family': #KMessageBox.information(self, 'delete family %s is unimplemented' % ident) msg = "Really delete family %s" % ident answer = KMessageBox.questionYesNo(self, msg) if answer == KMessageBox.Yes: self.family.delete_family(ident) msg = "family %s deleted" % ident KMessageBox.information(self, msg) self.parent().parent().refreshListView() self.setText('') else: KMessageBox.error(self, 'unable to delete %s for family' % context) else: KMessageBox.error(self, 'action %s unimpletmented' % url)
class FamilyView(ViewBrowser): def __init__(self, parent): ViewBrowser.__init__(self, parent, FamilyDoc) self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) def set_family(self, family): self.doc.set_family(family) self.setText(self.doc.output()) self.family.set_family(family) def setSource(self, url): action, context, ident = split_url(url) if action == 'edit': config = self.family.getVariablesConfig(self.family.current) newconfig = config.edit() config.update(newconfig) self.set_family(ident) else: KMessageBox.error(self, 'action %s unimpletmented' % url)
class FamilyView(ViewBrowser): def __init__(self, app, parent): ViewBrowser.__init__(self, app, parent, FamilyDoc) self.family = Family(self.app.conn) def set_family(self, family): self.doc.set_family(family) self.setText(self.doc.toxml()) self.family.set_family(family) def setSource(self, url): action, context, id = str(url).split('.') if action == 'show': if context == 'parent': win = TraitMainWindow(self.app, self.parent(), self.doc.suite) win.view.set_trait(id) elif context == 'template': fid = id.replace(',', '.') package, template = fid.split('...') win = ViewWindow(self.app, self.parent(), SimpleEdit, 'TemplateView') templatefile = self.doc.trait._templates.templatedata( package, template) win.view.setText(templatefile) win.resize(600, 800) elif context == 'script': scriptfile = self.doc.trait._scripts.scriptdata(id) win = ViewWindow(self.app, self.parent(), SimpleEdit, 'ScriptView') win.view.setText(scriptfile) win.resize(600, 800) elif action == 'edit': #KMessageBox.information(self, 'edit the family %s ' % id) config = self.family.getVariablesConfig(self.family.current) newconfig = config.edit() config.update(newconfig) self.set_family(id) else: KMessageBox.information(self, 'called %s' % url)
class FamilyDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.family = Family(self.conn) def set_family(self, family): self.family.set_family(family) parents = self.family.parents() erows = self.family.environment_rows() self.clear_body() title = SimpleTitleElement("Family: %s" % family, bgcolor="IndianRed", width="100%") self.body.appendChild(title) self.body.appendChild(SectionTitle("Parents")) if len(parents): plist = UnorderedList() for p in parents: plist.appendChild(ListItem(p)) self.body.appendChild(plist) vtitle = Anchor("edit.variables.%s" % self.family.current, "Variables") self.body.appendChild(SectionTitle(vtitle)) if len(erows): self.body.appendChild(PVarTable(erows, bgcolor="MistyRose2"))
class FamilyView(ViewBrowser): def __init__(self, app, parent): ViewBrowser.__init__(self, app, parent, FamilyDoc) self.family = Family(self.app.conn) def set_family(self, family): self.doc.set_family(family) self.setText(self.doc.toxml()) self.family.set_family(family) def setSource(self, url): action, context, id = str(url).split('.') if action == 'show': if context == 'parent': win = TraitMainWindow(self.app, self.parent(), self.doc.suite) win.view.set_trait(id) elif context == 'template': fid = id.replace(',', '.') package, template = fid.split('...') win = ViewWindow(self.app, self.parent(), SimpleEdit, 'TemplateView') templatefile = self.doc.trait._templates.templatedata(package, template) win.view.setText(templatefile) win.resize(600, 800) elif context == 'script': scriptfile = self.doc.trait._scripts.scriptdata(id) win = ViewWindow(self.app, self.parent(), SimpleEdit, 'ScriptView') win.view.setText(scriptfile) win.resize(600, 800) elif action == 'edit': #KMessageBox.information(self, 'edit the family %s ' % id) config = self.family.getVariablesConfig(self.family.current) newconfig = config.edit() config.update(newconfig) self.set_family(id) else: KMessageBox.information(self, 'called %s' % url)
class FamilyDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.family = Family(self.conn) def set_family(self, family): self.family.set_family(family) parents = self.family.parents() erows = self.family.environment_rows() self.clear_body() title = SimpleTitleElement('Family: %s' % family, bgcolor='IndianRed', width='100%') self.body.appendChild(title) self.body.appendChild(SectionTitle('Parents')) if len(parents): plist = UnorderedList() for p in parents: plist.appendChild(ListItem(p)) self.body.appendChild(plist) vtitle = Anchor('edit.variables.%s' % self.family.current, 'Variables') self.body.appendChild(SectionTitle(vtitle)) if len(erows): self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
def __init__(self, conn, suites, name='ProfileBrowser'): self.menu = self.__make_mainmenu_(suites) ListNoteBook.__init__(self, name=name) self.conn = conn self.profiles = Profile(self.conn) self.profiletrait = ProfileTrait(self.conn) self.family = Family(self.conn) self.pfamily = StatementCursor(self.conn) self.pfamily.set_table('profile_family') self.trait_menu = make_menu(['drop', 'order'], self.trait_command) self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command) self.family_menu = make_menu(['drop'], self.family_command) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits') self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables') self.append_page(ScrollCList(rcmenu=self.family_menu), 'families') self.dialogs = {}.fromkeys(['order'])
class FamilyParentAssigner(BaseAssigner): def __init__(self, parent, family): self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn) self.family.set_family(family) BaseAssigner.__init__(self, parent, name='FamilyParentAssigner', udbuttons=False) self.connect(self, SIGNAL('okClicked()'), self.slotAssignParents) def initView(self): family = self.family.current all_fams = self.family.all_families() assigned_parents = self.family.parents() avail_parents = [ f for f in all_fams if f not in assigned_parents + [family] ] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for family in assigned_parents: self._add_family_to_listbox(sbox, family) for family in avail_parents: self._add_family_to_listbox(abox, family) self.already_assigned = assigned_parents def _add_family_to_listbox(self, box, family): item = QListBoxText(box, family) item.family = family def slotAssignParents(self): sbox = self.listBox.selectedListBox() families = [str(sbox.item(n).text()) for n in range(sbox.numRows())] # since we're using a SimpleRelation class for # family.parents, we don't need to worry about # inserting families that are already there self.family.delete_parents() self.family.insert_parents(families)
class FamilyList(KListView): def __init__(self, app, parent, name='FamilyList'): KListView.__init__(self, parent, name) dbwidget(self, app) self.family = Family(self.conn) self.setRootIsDecorated(True) self.addColumn('family') self.refreshlistView() def refreshlistView(self): self.clear() rows = self.family.family_rows() for row in rows: item = KListViewItem(self, row.family) item.family = row.family def getData(self): item = self.currentItem() return FamilyVariablesConfig(self.conn, item.family) def updateData(self, data): pass
def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.family = Family(self.conn)
def __init__(self, parent): ViewBrowser.__init__(self, parent, FamilyDoc) self.app = get_application_pointer() self.conn = self.app.conn self.family = Family(self.conn)
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()
class FamilyBrowser(ListNoteBook): def __init__(self, conn): self.menu = make_menu(['delete'], self.modify_family) ListNoteBook.__init__(self) self.conn = conn self.family = Family(self.conn) self.var_menu = make_menu(['edit', 'nothing', 'nothing', 'drop'], self.var_menu_selected) self.parent_menu = make_menu(['drop'], self.modify_parent) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.var_menu), 'environment') 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', 'family') self.trait.delete_parents(parents) self.__set_pages(self.current_family) def modify_family(self, menuitem, action): if action == 'delete': trait = self.listbox.get_selected_data()[0].family self.trait.delete_family(family) self.reset_rows() def reset_rows(self): self.set_rows(self.family.family_rows()) self.set_row_select(self.family_selected) def __set_droptargets__(self, pages): set_receive_targets(pages['environment'].listbox, self.drop_variable, TARGETS.get('variable', 'flavor')) set_receive_targets(pages['parents'].listbox, self.drop_family, TARGETS.get('family', 'flavor')) def set_package(self, menu_item, action): raise Error, 'this call (set_package) is not needed in Family' packages = self._get_listbox_col_('packages', 'package') trait = self.current_family self.trait.set_action(action, packages) self.__set_pages(self.current_trait) def var_menu_selected(self, menu_item, action): if action == 'edit': config = self.family.getVariablesConfig(self.current_family) newconfig = config.edit() config.update(newconfig) self.select_family(self.current_family) elif action == 'drop': pages = dict(self.pages) listbox = pages['environment'].listbox rows = listbox.get_selected_data() for row in rows: self.family.deleteVariable(row.trait, row.name, self.current_family) def pop_mymenu(self, widget, event, menu): if right_click_pressed(event): menu.popup(None, None, None, event.button, event.time) def family_selected(self, listbox, row, column, event): family = listbox.get_selected_data()[0].family self.select_family(family) def select_family(self, family): self.current_family = family self.family.set_family(family) self.__set_pages(self.current_family) def __set_pages(self, family): pages = dict(self.pages) pages['environment'].set_rows(self.family.environment_rows()) pages['environment'].set_select_mode('multi') pages['parents'].set_rows(self.family.parents(), ['family']) pages['parents'].set_select_mode('multi') self.__set_droptargets__(pages) def drop_family(self, listbox, context, x, y, selection, targettype, time): families = Set(selection.data.split('^&^')) self.family.insert_parents(families) self.__set_pages(self.current_family) def drop_variable(self, listbox, context, x, y, selection, targettype, time): table = 'family_environment' trips = [x.split('<=>') for x in selection.data.split('^&^')] rows = [dict(trait=x[0], name=x[1], value=x[2]) for x in trips] for r in trips: trait, name, value = r self.family.insertVariable(trait, name, value, family=self.current_family) self.__set_pages(self.current_family) def _get_listbox_col_(self, page, field): pages = dict(self.pages) return [row[field] for row in pages[page].listbox.get_selected_data()] def make_families_window(self): rows = self.family.family_rows() FamiliesWindow(rows) def make_variables_window(self): rows = self.family.get_all_defaults() VariablesWindow(rows)
def __init__(self, app, parent): ViewBrowser.__init__(self, app, parent, FamilyDoc) self.family = Family(self.app.conn)
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 FamilyMainWindow(BaseSplitWindow, BasePaellaWindow): def __init__(self, parent): BaseSplitWindow.__init__(self, parent, FamilyView, name='FamilyMainWindow') self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.cursor = self.conn.cursor(statement=True) self.family = Family(self.conn) self.refreshListView() self.resize(600, 800) self.splitter.setSizes([100, 500]) self.setCaption('Paella Families') self._new_family_dialog = None def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newFamilyAction = KStdAction.openNew(self.newFamily, collection) self.importFamilyAction = KStdAction.open(self.slotImportFamily, collection) self.exportFamilyAction = KStdAction.saveAs(self.slotExportFamily, collection) def initMenus(self): mainmenu = KPopupMenu(self) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) menubar.insertItem('&Help', self.helpMenu('')) self.newFamilyAction.plug(mainmenu) self.importFamilyAction.plug(mainmenu) self.exportFamilyAction.plug(mainmenu) self.quitAction.plug(mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newFamilyAction.plug(toolbar) self.importFamilyAction.plug(toolbar) self.exportFamilyAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.setRootIsDecorated(False) self.listView.addColumn('family') def refreshListView(self): self.listView.clear() for row in self.family.family_rows(): item = KListViewItem(self.listView, row.family) item.family = row.family def selectionChanged(self): item = self.listView.currentItem() self.mainView.set_family(item.family) def newFamily(self): win = NewFamilyDialog(self) win.frame.text_label.setText('Add a new family.') win.connect(win, SIGNAL('okClicked()'), self.insertNewFamily) win.show() self._new_family_dialog = win def insertNewFamily(self): win = self._new_family_dialog family = win.getRecordData()['name'] self.family.create_family(family) self.refreshListView() self._new_family_dialog = None def slotImportFamily(self): KMessageBox.information(self, 'Import unimplemented') def slotExportFamily(self): KMessageBox.information(self, 'Export unimplemented')
class MachineTypeHandler(BaseMachineTypeHandler): def __init__(self, conn): BaseMachineTypeHandler.__init__(self, conn) self._mtfam = MachineTypeFamily(self.conn) self._fam = Family(self.conn) self._mtscript = MachineTypeScript(self.conn) def set_machine_type(self, machine_type): BaseMachineTypeHandler.set_machine_type(self, machine_type) self._mtenv = MachineTypeEnvironment(self.conn, machine_type) self._mtcfg = MachineTypeVariablesConfig(self.conn, machine_type) self._mtscript.set_machine_type(machine_type) def family_rows(self): clause = self._mtype_clause() return self._mtfam.select(clause=clause, order='family') def _family_clause(self, family): return self._mtype_clause() & Eq('family', family) def append_family(self, family): if family not in self.get_families(): data = dict(machine_type=self.current, family=family) self._mtfam.insert(data=data) def delete_family(self, family): clause = self._family_clause(family) self._mtfam.delete(clause=clause) def update_family(self, oldfam, newfam): clause = self._family_clause(oldfam) self._mtfam.update(data=dict(family=newfam), clause=clause) def append_variable(self, trait, name, value): data = dict(trait=trait, name=name, value=value, machine_type=self.current) self._mtenv.cursor.insert(data=data) def _variable_clause(self, trait, name): return self._mtype_clause() & Eq('trait', trait) & Eq('name', name) def delete_variable(self, trait, name): clause = self._variable_clause(trait, name) self._mtenv.cursor.delete(clause=clause) def update_variable(self, trait, name, value): clause = self._variable_clause(trait, name) self._mtenv.update(data=dict(value=value), clause=clause) def edit_variables(self): newvars = self._mtcfg.edit() self._mtcfg.update(newvars) def edit_script(self, name): script = self.get_script(name) if script is not None: data = edit_dbfile(name, script.read(), 'script') if data is not None: self._mtscript.save_script(name, strfile(data)) print 'need to update' def get_families(self): return [r.family for r in self.family_rows()] def get_family_data(self): families = self.get_families() return self._fam.FamilyData(families) def get_machine_type_data(self): data = self.get_family_data() data.update(self.MachineTypeData()) return data def MachineTypeData(self): return self._mtenv._make_superdict_() def get_script(self, name): return self._mtscript.get(name) def insert_script(self, name, scriptfile): self._mtscript.insert_script(name, scriptfile) def delete_script(self, name): self._mtscript.delete_script(name) def insert_parsed_element(self, mtype_element, path): mtype = mtype_element.mtype self.add_new_type(mtype.name) self.set_machine_type(mtype.name) mdisktable = 'machine_disks' for mdisk in mtype.disks: mdisk['machine_type'] = mtype.name self.insert(table=mdisktable, data=mdisk) mod_items = zip(range(len(mtype.modules)), mtype.modules) data = dict(machine_type=mtype.name) for i in range(len(mtype.modules)): data['ord'] = str(i) data['module'] = mtype.modules[i] self.insert(table='machine_modules', data=data) data = dict(machine_type=mtype.name) for f in mtype.families: data['family'] = f self.insert(table='machine_type_family', data=data) for s, d in mtype.scripts: scriptfile = file(join(path, 'script-%s' % s)) self._mtscript.insert_script(s, scriptfile) print 'imported %s' % s for trait, name, value in mtype.variables: data = dict(machine_type=mtype.name, trait=trait, name=name, value=value) self.insert(table='machine_type_variables', data=data) def import_machine_type_ignore(self, name, mtypepath): path = join(mtypepath, name) def import_machine_type(self, element, name): path = join(element.mtypepath, name) element = parseString(file(join(path, 'machine_type.xml')).read()) parsed = MachineTypeParser(element.firstChild) self.insert_parsed_element(parsed, path) def export_machine_type(self, mtype, mtypepath): path = join(mtypepath, mtype) element = MachineTypeElement(self.conn, mtype) element.export(mtypepath) self._mtscript.export_scripts(path)
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)
class FamilyMainWindow(SimpleSplitWindow): def __init__(self, app, parent): SimpleSplitWindow.__init__(self, app, parent, FamilyView, 'FamilyMainWindow') self.app = app self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.family = Family(self.conn) self.refreshListView() self.resize(600, 800) self.setCaption('paella families') def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newFamilyAction = KStdAction.openNew(self.newFamily, collection) def initMenus(self): mainMenu = KPopupMenu(self) menus = [mainMenu] self.menuBar().insertItem('&Main', mainMenu) self.menuBar().insertItem('&Help', self.helpMenu('')) self.newFamilyAction.plug(mainMenu) self.quitAction.plug(mainMenu) def initToolbar(self): toolbar = self.toolBar() self.newFamilyAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.setRootIsDecorated(True) self.listView.addColumn('group') def refreshListView(self): self.listView.clear() for row in self.family.family_rows(): item = KListViewItem(self.listView, row.family) item.family = row.family def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'family'): self.view.set_family(current.family) 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 def newFamily(self): dialog = SimpleRecordDialog(self, ['family']) dialog.connect(dialog, SIGNAL('okClicked()'), self.insertNewFamily) self._dialog = dialog def insertNewFamily(self): dialog = self._dialog data = dialog.getRecordData() family = data['family'] if family not in self.family.all_families(): self.family.create_family(family) else: KMessageBox.information(self, '%s already exists.' % family) self.refreshListView()