class MachineTypesElement(Element): def __init__(self, conn, mtypes=None): Element.__init__(self, 'machine_types') self.conn = conn self.cursor = StatementCursor(self.conn) if mtypes is None: rows = self.cursor.select(table='machine_types', order='machine_type') mtypes = [r.machine_type for r in rows] self.machine_types = [] for mtype in mtypes: mtype_element = MachineTypeElement(mtype) clause = Eq('machine_type', mtype) mdisks = self.cursor.select(table='machine_disks', clause=clause, order='device') for m in mdisks: mtype_element.append_device(m.diskname, m.device) modules = self.cursor.select(table='machine_modules', clause=clause, order='ord') for m in modules: mtype_element.append_module(m.module, str(m.ord)) self.machine_types.append(mtype_element) self.appendChild(mtype_element)
class PaellaProfiles(Element): def __init__(self, conn): Element.__init__(self, 'profiles') self.conn = conn self.stmt = StatementCursor(self.conn) self.env = ProfileEnvironment(self.conn) self.profiletraits = ProfileTrait(self.conn) self._profiles = {} for row in self.stmt.select(table='profiles', order='profile'): self._append_profile(row.profile, row.suite) def _append_profile(self, profile, suite): element = self.export_profile(profile, suite) self._profiles[profile] = element self.appendChild(self._profiles[profile]) def export_profile(self, profile, suite=None): if suite is None: row = self.stmt.select_row(table='profiles',clause=Eq('profile', profile)) suite = row['suite'] suite = str(suite) profile = str(profile) self.env.set_profile(profile) element = ProfileElement(profile, suite) element.append_traits(self.profiletraits.trait_rows(profile)) element.append_variables(self.env.get_rows()) return element def insert_profile(self, profile): idata = {'profile' : profile.name, 'suite' : profile.suite} self.stmt.insert(table='profiles', data=idata) idata = {'profile' : profile.name, 'trait' : None, 'ord' : 0} for trait, ord in profile.traits: print trait, ord idata['trait'] = trait idata['ord'] = ord #str(ord) self.stmt.insert(table='profile_trait', data=idata) idata = {'profile' : profile.name, 'trait' : None, 'name' : None, 'value': None} for trait, name, value in profile.vars: idata['trait'] = trait idata['name'] = name idata['value'] = value self.stmt.insert(table='profile_variables', data=idata) def export_profiles(self, path): rows = self.stmt.select(fields='profile', table='profiles', clause=None) for row in rows: self.write_profile(row.profile, path) def write_profile(self, profile, path): xmlfile = file(join(path, '%s.xml' % profile), 'w') data = self.export_profile(profile) data.writexml(xmlfile, indent='\t', newl='\n', addindent='\t') xmlfile.close()
class TableEditor(ListWin): def __init__(self, conn, table, pkey=None, fields=[], command_data=dict(new='new entry', edit='edit entry')): ListWin.__init__(self) self.conn = conn self.cursor = StatementCursor(self.conn) self.cursor.set_table(table) self._cdata = command_data self.tbar.add_button('new', self._cdata['new'], self.toolbar_button_pressed) self.tbar.add_button('edit', self._cdata['edit'], self.toolbar_button_pressed) if pkey is None: print get_pkey_info(StatementCursor(conn), table) self._pkey = pkey self.reset_rows() self._fields = fields self.fields = [pkey] + self._fields self.dialogs = {}.fromkeys(self._cdata.keys()) def reset_rows(self): self.set_rows(self.cursor.select(order=self._pkey)) def toolbar_button_pressed(self, button, data): row = None if data == 'new': if self.dialogs['new'] is None: row = self.cursor.select()[0] self._make_dialog('new', row, self.add_new_record) elif data == 'edit': if self.dialogs['edit'] is None: row = get_single_row(self.listbox, self._pkey) if row is not None: self._make_dialog('edit', row, self.edit_record, row[self._pkey]) def _make_dialog(self, name, row, okfun, pkey=None): if name == 'edit': fields = self._fields else: fields = self.fields make_record_dialog(self, name, row, okfun, pkey, fields, self._cdata) def add_new_record(self, *args): dialog = self.dialogs['new'] self.cursor.insert(data=dict(dialog.items())) self.destroy_dialog(dialog) self.reset_rows() def edit_record(self, *args): dialog = self.dialogs['edit'] clause = Eq(self._pkey, dialog.pkey) data = dict(dialog.items()) self.cursor.update(data=data, clause=clause) self.destroy_dialog(dialog) self.reset_rows()
class BaseDiffer(VBox): def __init__(self, conn, name='BaseDiffer'): VBox.__init__(self) self.set_name(name) self.conn = conn self.view = TwinScrollCList(name=name) self.cursor = StatementCursor(self.conn) suites = [ r.suite for r in self.cursor.select(table='suites', order='suite') ] self.suite_bar = SuiteBar(suites, name=name) self.trait_bar = TraitBar(name=name) self.pack_end(self.suite_bar, 0, 0, 0) self.pack_end(self.trait_bar, 0, 0, 0) self.add(self.view) self.suite_bar.show() self.show() def update_lists(self, fields, suffix): self.lsuite = self.suite_bar.lcombo.get() self.rsuite = self.suite_bar.rcombo.get() self.cursor.set_fields(fields) clause = None ltrait = self.trait_bar.lcombo.get() if ltrait: clause = Eq('trait', ltrait) table = '%s_%s' % (self.lsuite, suffix) rows = self.cursor.select(table=table, clause=clause, order=fields) self.view.lbox.set_rows(rows) clause = None rtrait = self.trait_bar.rcombo.get() if rtrait: clause = Eq('trait', rtrait) table = '%s_%s' % (self.rsuite, suffix) rows = self.cursor.select(table=table, clause=clause, order=fields) self.view.rbox.set_rows(rows) fields = ['trait'] self.cursor.set_fields(fields) rows = self.cursor.select(table='%s_traits' % self.lsuite, order=fields) ltraits = [r.trait for r in rows] rows = self.cursor.select(table='%s_traits' % self.rsuite, order=fields) rtraits = [r.trait for r in rows] self.trait_bar.lcombo.fill(ltraits) self.trait_bar.rcombo.fill(rtraits) if ltrait and ltrait in ltraits: self.trait_bar.lcombo.set(ltrait) else: self.trait_bar.lcombo.set('') if rtrait and rtrait in rtraits: self.trait_bar.rcombo.set(rtrait) else: self.trait_bar.rcombo.set('')
class BaseDiffer(VBox): def __init__(self, conn, name='BaseDiffer'): VBox.__init__(self) self.set_name(name) self.conn = conn self.view = TwinScrollCList(name=name) self.cursor = StatementCursor(self.conn) suites = [r.suite for r in self.cursor.select(table='suites', order='suite')] self.suite_bar = SuiteBar(suites, name=name) self.trait_bar = TraitBar(name=name) self.pack_end(self.suite_bar, 0, 0, 0) self.pack_end(self.trait_bar, 0, 0, 0) self.add(self.view) self.suite_bar.show() self.show() def update_lists(self, fields, suffix): self.lsuite = self.suite_bar.lcombo.get() self.rsuite = self.suite_bar.rcombo.get() self.cursor.set_fields(fields) clause = None ltrait = self.trait_bar.lcombo.get() if ltrait: clause = Eq('trait', ltrait) table = '%s_%s' % (self.lsuite, suffix) rows = self.cursor.select(table=table, clause=clause, order=fields) self.view.lbox.set_rows(rows) clause = None rtrait = self.trait_bar.rcombo.get() if rtrait: clause = Eq('trait', rtrait) table = '%s_%s' % (self.rsuite, suffix) rows = self.cursor.select(table=table, clause=clause, order=fields) self.view.rbox.set_rows(rows) fields = ['trait'] self.cursor.set_fields(fields) rows = self.cursor.select(table='%s_traits' % self.lsuite, order=fields) ltraits = [r.trait for r in rows] rows = self.cursor.select(table='%s_traits' % self.rsuite, order=fields) rtraits = [r.trait for r in rows] self.trait_bar.lcombo.fill(ltraits) self.trait_bar.rcombo.fill(rtraits) if ltrait and ltrait in ltraits: self.trait_bar.lcombo.set(ltrait) else: self.trait_bar.lcombo.set('') if rtrait and rtrait in rtraits: self.trait_bar.rcombo.set(rtrait) else: self.trait_bar.rcombo.set('')
class Family(object): def __init__(self, conn): object.__init__(self) self.conn = conn self.cursor = StatementCursor(self.conn) self.current = None self.parent = SimpleRelation(self.conn, 'family_parent', 'family') self.env = Environment(self.conn, 'family_environment', 'family') def set_family(self, family): self.current = family self.parent.set_current(family) self.env.set_main(family) def add_family(self, family, type='general'): pass def get_families(self, families=[]): rows = self.cursor.select(table='family_parent') graph = kjGraph([(r.family, r.parent) for r in rows]) dfamilies = Set() for fam in families: dfamilies |= Set([fam]) | Set(graph.reachable(fam).items()) return dfamilies def parents(self, family=None): if family is None: family = self.current self.parent.set_clause(family) rows = self.parent.cmd.select(fields=['parent'], order='parent') self.parent.reset_clause() return [x.parent for x in rows]
def __init__(self, name='Manager'): CommandBoxWindow.__init__(self) self.cfg = PaellaConfig('database') self.dialogs = {}.fromkeys(['dbname', 'suitemanager']) apps = [ 'profiles', 'families', 'suitemanager', 'traitmanager', 'machines', 'traits', 'tdiff', 'sdiff', 'fdiff', 'default_environment', 'clients' ] self.workspace = {}.fromkeys(apps) self.add_menu(dbcommands, 'database', self.database_command) self.add_menu(self.workspace.keys(), 'edit', self.edit_command) self.set_size_request(150, 200) self.conn = None self.dbname = None self.dblist = ScrollCList() self.vbox.add(self.dblist) conn = PaellaConnection(self.cfg) cursor = StatementCursor(conn, 'quicky') self.dblist.set_rows(cursor.select(table='pg_database')) cursor.close() conn.close() self.tbar.add_button('profiles', 'profile manager', self.run_tbar) self.tbar.add_button('families', 'family manager', self.run_tbar) self.tbar.add_button('machines', 'machine manager', self.run_tbar) self.tbar.add_button('traits', 'trait manager', self.run_tbar) self.tbar.add_button('tdiff', 'template differ', self.run_tbar) self.tbar.add_button('sdiff', 'script differ', self.run_tbar) self.tbar.add_button('fdiff', 'family differ', self.run_tbar)
class DisksElement(Element): def __init__(self, conn): Element.__init__(self, 'disks') self.conn = conn self.cursor = StatementCursor(self.conn) disks = [r.diskname for r in self.cursor.select(table='disks', order='diskname')] self.disks = [] for diskname in disks: disk_element = DiskElement(diskname) clause = Eq('diskname', diskname) partitions = self.cursor.select(table='partitions', clause=clause, order='partition') for p in partitions: disk_element.append_partition(p.partition, p.start, p.size, p.id) self.disks.append(disk_element) self.appendChild(disk_element)
def __init__(self, name='Manager'): CommandBoxWindow.__init__(self) self.cfg = PaellaConfig('database') self.dialogs = {}.fromkeys(['dbname', 'suitemanager']) apps = ['profiles', 'families', 'suitemanager', 'traitmanager', 'machines', 'traits', 'tdiff', 'sdiff', 'fdiff', 'default_environment', 'clients'] self.workspace = {}.fromkeys(apps) self.add_menu(dbcommands, 'database', self.database_command) self.add_menu(self.workspace.keys(), 'edit', self.edit_command) self.set_size_request(150,200) self.conn = None self.dbname = None self.dblist = ScrollCList() self.vbox.add(self.dblist) conn = PaellaConnection(self.cfg) cursor = StatementCursor(conn, 'quicky') self.dblist.set_rows(cursor.select(table='pg_database')) cursor.close() conn.close() self.tbar.add_button('profiles', 'profile manager', self.run_tbar) self.tbar.add_button('families', 'family manager', self.run_tbar) self.tbar.add_button('machines', 'machine manager', self.run_tbar) self.tbar.add_button('traits', 'trait manager', self.run_tbar) self.tbar.add_button('tdiff', 'template differ', self.run_tbar) self.tbar.add_button('sdiff', 'script differ', self.run_tbar) self.tbar.add_button('fdiff', 'family differ', self.run_tbar)
class MachinesElement(Element): def __init__(self, conn, machines=None): Element.__init__(self, 'machines') self.conn = conn self.cursor = StatementCursor(self.conn) self.machines = [] if machines is None: machines = self.cursor.select(table='machines', order='machine') else: clause = In('machine', machines) machines = self.cursor.select(table='machines', clause=clause, order='machine') for m in machines: machine_element = MachineElement(m.machine, m.machine_type, m.kernel, m.profile, m.filesystem) self.machines.append(machine_element) self.appendChild(machine_element)
class MachineTypesElement(Element): def __init__(self, conn): Element.__init__(self, 'machine_types') self.conn = conn self.cursor = StatementCursor(self.conn) rows = self.cursor.select(table='machine_types', order='machine_type') mtypes = [r.machine_type for r in rows] self.machine_types = [] for mtype in mtypes: mtype_element = MachineTypeElement(mtype) clause = Eq('machine_type', mtype) mdisks = self.cursor.select(table='machine_disks', clause=clause, order='device') for m in mdisks: mtype_element.append_device(m.diskname, m.device) self.machine_types.append(mtype_element) self.appendChild(mtype_element)
class TraitsWindow(DragListWindow): def __init__(self, conn, suite, name='TraitsWindow'): self.cmd = StatementCursor(conn, name=name) self.cmd.set_table(ujoin(suite, 'traits')) rows = self.cmd.select() packer = lambda x : rowpacker('trait', x) DragListWindow.__init__(self, '%s traits' % suite, packer, rows, TARGETS.get('trait', suite), name=name) self.set_size_request(400, 300)
class EnvironmentList(KListView): def __init__(self, app, parent, etype='default', name='EnvironmentList'): KListView.__init__(self, parent, name) dbwidget(self, app) self.etype = etype self.environ = ETYPE[self.etype](self.conn) self.cursor = StatementCursor(self.conn) self.cursor.set_table('%s_environment' % self.etype) self.setRootIsDecorated(True) for field in ['section', 'option', 'value']: self.addColumn(field) def refreshlistView(self): self.clear() if self.etype == 'default': fields = ['section', 'option', 'value'] rows = self.cursor.select(fields=fields, order=['section', 'option']) if self.etype == 'current': fields = ['hostname', 'name', 'value'] rows = self.cursor.select(fields=fields, order=['hostname', 'name']) for row in rows: KListViewItem(self, *row) def file_selected(self, filesel): filename = str(filesel.selectedFile()) print filename, filesel.actiontype action = filesel.actiontype if action == 'save': self.environ.write(file(filename, 'w')) elif action == 'load': newcfg = RawConfigParser() newcfg.read(filename) self._update_environ(newcfg) def _update_environ(self, newcfg): self.environ.update(newcfg) self.environ = ETYPE[self.etype](self.conn) self.refreshlistView() def slotEdit(self): newcfg = self.environ.edit() self._update_environ(newcfg)
class PaellaDatabase(Element): def __init__(self, conn, path='/'): Element.__init__(self, 'paelladatabase') self.conn = conn self.stmt = StatementCursor(self.conn) self._profile_traits_ = ProfileTrait(self.conn) self.path = path self.suites = SuitesElement() self.appendChild(self.suites) for row in self._suite_rows(): args = map( str, [row.suite, row.nonus, row.updates, row.local, row.common]) element = SuiteElement(*args) self.suites.appendChild(element) self.profiles = PaellaProfiles(self.conn) self.family = Family(self.conn) suites = [x.suite for x in self._suite_rows()] for suite in suites: self.appendChild(TraitsElement(self.conn, suite)) def _suite_rows(self): return self.stmt.select(table='suites', order='suite') def write(self, filename): path = join(self.path, filename) xmlfile = file(path, 'w') self.writexml(xmlfile, indent='\t', newl='\n', addindent='\t') def backup(self, path=None): if path is None: path = self.path if not isdir(path): raise Error, '%s not a directory' % path dbfile = file(join(path, 'database.xml'), 'w') self.writexml(dbfile, indent='\t', newl='\n', addindent='\t') dbfile.close() self.backup_profiles(path) self.backup_families(path) suites = [x.suite for x in self._suite_rows()] for suite in suites: makepaths(join(path, suite)) trait = Trait(self.conn, suite) for t in trait.get_trait_list(): trait.set_trait(t) trait.backup_trait(join(path, suite)) def backup_profiles(self, path=None): profiles_dir = join(path, 'profiles') makepaths(profiles_dir) self.profiles.export_profiles(profiles_dir) def backup_families(self, path=None): fpath = join(path, 'families') makepaths(fpath) self.family.export_families(fpath)
class EnvironmentList(KListView): def __init__(self, app, parent, etype='default', name='EnvironmentList'): KListView.__init__(self, parent, name) dbwidget(self, app) self.etype = etype self.environ = ETYPE[self.etype](self.conn) self.cursor = StatementCursor(self.conn) self.cursor.set_table('%s_environment' % self.etype) self.setRootIsDecorated(True) for field in ['section', 'option', 'value']: self.addColumn(field) def refreshlistView(self): self.clear() if self.etype == 'default': fields = ['section', 'option', 'value'] rows = self.cursor.select(fields=fields, order=['section', 'option']) if self.etype == 'current': fields = ['hostname', 'name', 'value'] rows = self.cursor.select(fields=fields, order=['hostname', 'name']) for row in rows: KListViewItem(self, *row) def file_selected(self, filesel): filename = str(filesel.selectedFile()) print filename, filesel.actiontype action = filesel.actiontype if action == 'save': self.environ.write(file(filename, 'w')) elif action == 'load': newcfg = RawConfigParser() newcfg.read(filename) self._update_environ(newcfg) def _update_environ(self, newcfg): self.environ.update(newcfg) self.environ = ETYPE[self.etype] (self.conn) self.refreshlistView() def slotEdit(self): newcfg = self.environ.edit() self._update_environ(newcfg)
class Select(object): def __init__(self, conn): self.conn = conn self.win = MenuWindow() self.scroll = ScrollCList() self.win.vbox.add(self.scroll) self.s = StatementCursor(self.conn) def select(self, *args, **kw): rows = self.s.select(*args, **kw) self.scroll.set_rows(rows)
class PaellaDatabase(Element): def __init__(self, conn, path='/'): Element.__init__(self, 'paelladatabase') self.conn = conn self.stmt = StatementCursor(self.conn) self._profile_traits_ = ProfileTrait(self.conn) self.path = path self.suites = SuitesElement() self.appendChild(self.suites) for row in self._suite_rows(): args = map(str, [row.suite, row.nonus, row.updates, row.local, row.common]) element = SuiteElement(*args) self.suites.appendChild(element) self.profiles = PaellaProfiles(self.conn) self.family = Family(self.conn) suites = [x.suite for x in self._suite_rows()] for suite in suites: self.appendChild(TraitsElement(self.conn, suite)) def _suite_rows(self): return self.stmt.select(table='suites', order='suite') def write(self, filename): path = join(self.path, filename) xmlfile = file(path, 'w') self.writexml(xmlfile, indent='\t', newl='\n', addindent='\t') def backup(self, path=None): if path is None: path = self.path if not isdir(path): raise Error, '%s not a directory' % path dbfile = file(join(path, 'database.xml'), 'w') self.writexml(dbfile, indent='\t', newl='\n', addindent='\t') dbfile.close() self.backup_profiles(path) self.backup_families(path) suites = [x.suite for x in self._suite_rows()] for suite in suites: makepaths(join(path, suite)) trait = Trait(self.conn, suite) for t in trait.get_trait_list(): trait.set_trait(t) trait.backup_trait(join(path, suite)) def backup_profiles(self, path=None): profiles_dir = join(path, 'profiles') makepaths(profiles_dir) self.profiles.export_profiles(profiles_dir) def backup_families(self, path=None): fpath = join(path, 'families') makepaths(fpath) self.family.export_families(fpath)
class KernelsElement(Element): def __init__(self, conn): Element.__init__(self, 'kernels') self.conn = conn self.cursor = StatementCursor(self.conn) self.kernels = [] kernels = [r.kernel for r in self.cursor.select(table='kernels', order='kernel')] for k in kernels: k_element = KernelElement(k) self.kernels.append(k_element) self.appendChild(k_element)
class DisksElement(Element): def __init__(self, conn): Element.__init__(self, 'disks') self.conn = conn self.cursor = StatementCursor(self.conn) disks = [ r.diskname for r in self.cursor.select(table='disks', order='diskname') ] self.disks = [] for diskname in disks: disk_element = DiskElement(diskname) clause = Eq('diskname', diskname) partitions = self.cursor.select(table='partitions', clause=clause, order='partition') for p in partitions: disk_element.append_partition(p.partition, p.start, p.size, p.id) self.disks.append(disk_element) self.appendChild(disk_element)
class FilesystemsElement(Element): def __init__(self, conn): Element.__init__(self, 'filesystems') self.conn = conn self.cursor = StatementCursor(self.conn) filesystems = [r.filesystem for r in self.cursor.select(table='filesystems', order='filesystem')] self.filesystems = [] for filesystem in filesystems: fs_element = FilesystemElement(self.conn, filesystem) self.filesystems.append(fs_element) self.appendChild(fs_element)
class MachinesElement(Element): def __init__(self, conn): Element.__init__(self, 'machines') self.conn = conn self.cursor = StatementCursor(self.conn) self.machines = [] machines = self.cursor.select(table='machines', order='machine') for m in machines: machine_element = MachineElement(m.machine, m.machine_type, m.kernel, m.profile, m.filesystem) self.machines.append(machine_element) self.appendChild(machine_element)
class TextFileBrowser(ListTextView): def __init__(self, conn, name='TextFileBrowser'): ListTextView.__init__(self, name=name) self.conn = conn self.cursor = StatementCursor(self.conn) self.cursor.set_table('textfiles') def reset_rows(self): self.set_rows(self.cursor.select(fields=['fileid'])) self.set_row_select(self.fileid_selected) def fileid_selected(self, listbox, row, column, event): pass
class FilesystemsElement(Element): def __init__(self, conn): Element.__init__(self, 'filesystems') self.conn = conn self.cursor = StatementCursor(self.conn) filesystems = [ r.filesystem for r in self.cursor.select(table='filesystems', order='filesystem') ] self.filesystems = [] for filesystem in filesystems: fs_element = FilesystemElement(self.conn, filesystem) self.filesystems.append(fs_element) self.appendChild(fs_element)
class KernelsElement(Element): def __init__(self, conn): Element.__init__(self, 'kernels') self.conn = conn self.cursor = StatementCursor(self.conn) self.kernels = [] kernels = [ r.kernel for r in self.cursor.select(table='kernels', order='kernel') ] for k in kernels: k_element = KernelElement(k) self.kernels.append(k_element) self.appendChild(k_element)
class PackagesWindow(DragListWindow): def __init__(self, conn, suite, name='PackagesWindow'): self.cmd = StatementCursor(conn, name=name) table = ujoin(suite, 'packages') self.cmd.set_table(table) section_query ='select distinct section from %s' % table sections = [x.section for x in self.cmd.get(section_query)] self.section_combo = MyCombo(sections) self.section_combo.set(sections[0]) rows = self.cmd.select(clause="section = '%s'" % sections[0]) packer = lambda x : rowpacker('package', x) DragListWindow.__init__(self, '%s packages' % suite, packer, rows, TARGETS.get('package', suite), name=name) self.vbox.pack_start(self.section_combo,0,0,0) self.set_size_request(400, 300) self.set_ok(self.set_packages) def set_packages(self, *args): section = self.section_combo.get() fields = ['package', 'priority', 'version', 'installedsize', 'maintainer', 'size'] rows = self.cmd.select(fields=fields, clause=Eq('section', section)) self.set_rows(rows) self.set_select_mode('multi')
class BaseRelationalBrowser(ListNoteBook, HasDialogs): def __init__(self, conn, maintable, pkey): self.menu = make_menu(['insert', 'update', 'done'], self.pkey_command) ListNoteBook.__init__(self) self.conn = conn self.main = StatementCursor(self.conn) self.main.set_table(maintable) self.pkey = pkey self.dialogs = {}.fromkeys(['insert', 'update', 'delete']) self.relations = {} def reset_rows(self): self.set_rows(self.main.select(order=self.pkey)) self.set_row_select(self.pkey_selected) def pkey_selected(self, listbox, row, column, event): print listbox.get_selected_data()[0][0] def pkey_command(self, menuitem, command): if command == 'insert': if self.dialogs['insert'] is None: dialog = dialogs.Entry('insert a %s' % self.pkey, name='insert') dialog.set_ok(self.pkey_insert_ok) dialog.set_cancel(self.destroy_dialog) self.dialogs['insert'] = dialog elif command == 'update': dialogs.Message('need to set update to cascade in db') elif command == 'done': value = None try: value = self.listbox.get_selected_data()[0][0] except IndexError: dialogs.Message('need to select %s first' % self.pkey) if value is not None: dialogs.Message('ok, i am done.') def append_relation(self, table, fields=[], fkeyname=None): if table not in self.relations: if not fields: if fkeyname is None: fkeyname = self.pkey fields = [f for f in self.main.fields(table) if f != fkeyname] if fkeyname is None: fkeyname = self.pkey self.relations[table] = fkeyname, fields else: raise Error, "relation already exists %s" % table
class BaseRelationalBrowser(ListNoteBook, HasDialogs): def __init__(self, conn, maintable, pkey): self.menu = make_menu(["insert", "update", "done"], self.pkey_command) ListNoteBook.__init__(self) self.conn = conn self.main = StatementCursor(self.conn) self.main.set_table(maintable) self.pkey = pkey self.dialogs = {}.fromkeys(["insert", "update", "delete"]) self.relations = {} def reset_rows(self): self.set_rows(self.main.select(order=self.pkey)) self.set_row_select(self.pkey_selected) def pkey_selected(self, listbox, row, column, event): print listbox.get_selected_data()[0][0] def pkey_command(self, menuitem, command): if command == "insert": if self.dialogs["insert"] is None: dialog = dialogs.Entry("insert a %s" % self.pkey, name="insert") dialog.set_ok(self.pkey_insert_ok) dialog.set_cancel(self.destroy_dialog) self.dialogs["insert"] = dialog elif command == "update": dialogs.Message("need to set update to cascade in db") elif command == "done": value = None try: value = self.listbox.get_selected_data()[0][0] except IndexError: dialogs.Message("need to select %s first" % self.pkey) if value is not None: dialogs.Message("ok, i am done.") def append_relation(self, table, fields=[], fkeyname=None): if table not in self.relations: if not fields: if fkeyname is None: fkeyname = self.pkey fields = [f for f in self.main.fields(table) if f != fkeyname] if fkeyname is None: fkeyname = self.pkey self.relations[table] = fkeyname, fields else: raise Error, "relation already exists %s" % table
def __init__(self, name='Manager'): CommandBoxWindow.__init__(self) self.cfg = PaellaConfig('database') self.dialogs = {}.fromkeys(['dbname', 'suitemanager']) self.workspace = {}.fromkeys(['profiles', 'suitemanager', 'traitmanager', 'machines']) self.add_menu(dbcommands, 'database', self.database_command) self.add_menu(self.workspace.keys(), 'edit', self.edit_command) self.set_size_request(150,200) self.conn = None self.dbname = None self.dblist = ScrollCList() self.vbox.add(self.dblist) conn = PaellaConnection(self.cfg) cursor = StatementCursor(conn, 'quicky') self.dblist.set_rows(cursor.select(table='pg_database')) cursor.close() conn.close()
class MountsElement(Element): def __init__(self, conn): Element.__init__(self, 'mounts') self.conn = conn self.cursor = StatementCursor(self.conn) self.cursor.set_table('mounts') self.mounts = [] rows = self.cursor.select(order='mnt_name') for r in rows: self.append_mount(r.mnt_name, r.mnt_point, r.fstype, r.mnt_opts, r.dump, r['pass']) def append_mount(self, mnt_name, mnt_point, fstype, mnt_opts, dump, pass_): mnt_element = MountElement(mnt_name, mnt_point, fstype, mnt_opts, dump, pass_) self.mounts.append(mnt_element) self.appendChild(mnt_element)
def __init__(self, name='Manager'): CommandBoxWindow.__init__(self) self.cfg = PaellaConfig('database') self.dialogs = {}.fromkeys(['dbname', 'suitemanager']) self.workspace = {}.fromkeys( ['profiles', 'suitemanager', 'traitmanager', 'machines']) self.add_menu(dbcommands, 'database', self.database_command) self.add_menu(self.workspace.keys(), 'edit', self.edit_command) self.set_size_request(150, 200) self.conn = None self.dbname = None self.dblist = ScrollCList() self.vbox.add(self.dblist) conn = PaellaConnection(self.cfg) cursor = StatementCursor(conn, 'quicky') self.dblist.set_rows(cursor.select(table='pg_database')) cursor.close() conn.close()
class PackageDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.suite = None self.cursor = StatementCursor(self.conn) def set_suite(self, suite): self.suite = suite self.cursor.set_table('%s_packages' % self.suite) def set_clause(self, clause): print 'clause---->', clause, type(clause) self.cursor.clause = clause self.clear_body() title = SimpleTitleElement('%s Packages' % self.suite, bgcolor='IndianRed', width='100%') self.body.appendChild(title) for row in self.cursor.select(clause=clause): self.body.appendChild(PackageFieldTable(row, bgcolor='MistyRose2')) self.body.appendChild(HR())
class DefEnvEditor(CommandBoxWindow): def __init__(self, conn): CommandBoxWindow.__init__(self) self.conn = conn self.defenv = DefaultEnvironment(self.conn) self.add_menu(['load', 'edit', 'save'], 'main', self.main_menu_selected) self.cursor = StatementCursor(self.conn) self.cursor.set_table('default_environment') self.view = ScrollCList() self.vbox.add(self.view) self.reset_rows() def reset_rows(self): self.view.set_rows(self.cursor.select(order=['section', 'option'])) def main_menu_selected(self, menuitem, name): if name == 'edit': newcfg = self.defenv.edit() self._update_dfenv(newcfg) elif name in ['load', 'save']: filesel = FileSelection(title='%s Default Environment' % name) filesel.cancel_button.connect('clicked', lambda x: filesel.destroy()) filesel.show() filesel.ok_button.connect('clicked', self.ok_filesel, filesel) filesel.set_data('action', name) def ok_filesel(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if action == 'save': self.defenv.write(file(path, 'w')) elif action == 'load': newcfg = RawConfigParser() newcfg.read(path) self._update_dfenv(newcfg) def _update_dfenv(self, newcfg): self.defenv.update(newcfg) self.defenv = DefaultEnvironment(self.conn) self.reset_rows()
class TraitsElement(Element): def __init__(self, conn, suite): Element.__init__(self, 'traits') self.conn = conn self.suite = suite self.setAttribute('suite', self.suite) self._traits_ = StatementCursor(self.conn, 'Traits') self._traits_.set_table(ujoin(self.suite, 'traits')) self.traitnames = [row.trait for row in self._traits_.select(order='trait')] for t in self.traitnames: t_element = Element('trait') t_element.setAttribute('name', t) self.appendChild(t_element) def make_trait(self, trait): t_element = TraitElement(self.conn, self.suite) t_element.set(trait) return t_element
class Profile(StatementCursor): 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 drop_profile(self, profile): self.delete(clause=Eq('profile', profile)) def set_profile(self, profile): self.clause = Eq('profile', profile) self.current = self.select_row(clause=self.clause) self._traits.set_profile(profile) self._env.set_profile(profile) def get_profile_data(self): return self._env.ProfileData() def get_family_data(self): families = self.get_families() return self._fam.FamilyData(families) def make_traitlist(self, log=None): tp = TraitParent(self.conn, self.current.suite) listed = [x.trait for x in self._traits.trait_rows()] all = list(tp.get_traitset(listed)) setfun = tp.set_trait parfun = tp.parents return make_deplist(listed, all, setfun, parfun, log) def family_rows(self, profile=None): if profile is None: profile = self.current.profile return self._pfam.select(clause=Eq('profile', profile)) def get_families(self, profile=None): return [r.family for r in self.family_rows(profile)]
class FilesystemElement(Element): def __init__(self, conn, filesystem): Element.__init__(self, 'filesystem') self.conn = conn self.cursor = StatementCursor(self.conn) self.cursor.set_table('filesystem_mounts') self.setAttribute('name', filesystem) self.mounts = [] self.filesystem = filesystem clause = Eq('filesystem', filesystem) rows = self.cursor.select(clause=clause, order='mnt_name') for r in rows: self.append_fs_mount(r.mnt_name, r.ord, r.partition) def append_fs_mount(self, mnt_name, ord, partition): fs_mount_element = FilesystemMountElement(mnt_name, str(ord), str(partition)) self.mounts.append(fs_mount_element) self.appendChild(fs_mount_element)
class ScriptBrowser(ListNoteBook): def __init__(self, conn, suite, trait): self.conn = conn self.suite = suite self.trait = trait self.cursor = StatementCursor(self.conn) self.cursor.set_table('%s_scripts' % self.suite) self.edit_menu = make_menu(SCRIPTS, self.modify_trait, name='edit') self.diff_menu = make_menu(SCRIPTS, self.modify_trait, name='diff') self.menu = make_menu(['edit', 'diff'], self.modify_trait) self.menu['edit'].set_submenu(self.edit_menu) self.menu['diff'].set_submenu(self.diff_menu) self.menu.set_name('main') ListNoteBook.__init__(self) self.reset_rows() def reset_rows(self): rows = self.cursor.select(fields=['script'], clause=self._trait_clause()) self.set_rows(rows) self.set_row_select(self.script_selected) def modify_trait(self, menuitem, action): parent = menuitem.get_parent().get_name() if parent == '_none_': print 'ack ack ack' elif parent != 'main': print parent, action def _trait_clause(self): return Eq('trait', self.trait) def script_selected(self, listbox, row, column, event): script = listbox.get_selected_data()[0].script self.select_script(script) def select_script(self, script): if script not in self.pages: newpage = ScriptText(self.conn, self.suite, self.trait, script) self.append_page(newpage, script) self.set_current_page(script)
class VariablesConfig(RawConfigParser): def __init__(self, conn, table, section, mainfield=None, mainvalue=None, option='name', value='value'): self.conn = conn self.cursor = StatementCursor(self.conn) self.cursor.set_table(table) self._secfield = section bothnone = mainfield is None and mainvalue is None bothset = mainfield and mainvalue if not bothnone and not bothset: raise Error, 'both mainfield and mainvalue need to be set/unset' self._mainclause = None if bothset: self._mainclause = Eq(mainfield, mainvalue) self._fields = [self._secfield, option, value] RawConfigParser.__init__(self) for row in self.cursor.select(fields=self._fields, clause=self._mainclause): if row[0] not in self.sections(): self.add_section(row[0]) self.set(*row) def write(self, cfile): sections = self.sections() sections.sort() for section in sections: cfile.write('[%s]\n' % section) keys = self.options(section) keys.sort() for k in keys: if k != '__name__': v = str(self.get(section, k)).replace('\n', '\n\t') cfile.write('%s:\t%s\n' % (k, v)) cfile.write('\n') def edit(self): tmp, path = tempfile.mkstemp('variables', 'config') tmp = file(path, 'w') self.write(tmp) tmp.close() os.system('$EDITOR %s' % path) tmp = file(path, 'r') newconfig = RawConfigParser() newconfig.readfp(tmp) tmp.close() os.remove(path) return newconfig def diff(self, other): ltmp, lpath = tempfile.mkstemp('variables', 'config') ltmp = file(lpath, 'w') self.write(ltmp) ltmp.close() rtmp, rpath = tempfile.mkstemp('variables', 'config') rtmp = file(rpath, 'w') other.write(rtmp) rtmp.close() os.system('xxdiff %s %s' % (lpath, rpath)) ltmp, rtmp = file(lpath, 'r'), file(rpath, 'r') lcfg, rcfg = RawConfigParser(), RawConfigParser() lcfg.readfp(ltmp) rcfg.readfp(rtmp) ltmp.close() rtmp.close() self.update(lcfg) other.update(rcfg) def update(self, newconfig): removed = [x for x in self.sections() if x not in newconfig.sections()] for section in removed: print 'removing', section sclause = Eq(self._secfield, section) if self._mainclause: sclause &= self._mainclause self.cursor.delete(clause=sclause) for section in newconfig.sections(): print section sclause = Eq(self._secfield, section) if self._mainclause: sclause = self._mainclause & Eq(self._secfield, section) if not self.has_section(section): for k,v in newconfig.items(section): idata = dict(zip(self._fields, [section, k, v])) if self._mainclause: idata[self._mainclause.left] = self._mainclause.right print idata self.cursor.insert(data=idata) else: for name, value in newconfig.items(section): nclause = sclause & Eq(self._fields[1], name) #print 'nclause', nclause #print 'value', self.get(section, name) if self.has_option(section, name): if value != self.get(section, name): #print 'updating' self.cursor.update(data={self._fields[2] : value}, clause=nclause) else: idata = dict(zip(self._fields, [section, name, value])) if self._mainclause: idata[self._mainclause.left] = self._mainclause.right self.cursor.insert(data=idata) if self.has_section(section): for name, value in self.items(section): if not newconfig.has_option(section, name): clause = sclause & Eq(self._fields[1], name) #print 'dclause', clause self.cursor.delete(clause=clause)
def get_suite(conn, profile): cursor = StatementCursor(conn) cursor.set_table('profiles') cursor.set_clause([('profile', profile)]) return [r.suite for r in cursor.select()][0]
class Profile(StatementCursor): 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 drop_profile(self, profile): self.delete(clause=Eq('profile', profile)) def set_profile(self, profile): self.clause = Eq('profile', profile) self.current = self.select_row(clause=self.clause) self._traits.set_profile(profile) self._env.set_profile(profile) def get_profile_data(self): return self._env.ProfileData() def get_family_data(self): families = self.get_families() return self._fam.FamilyData(families) def make_traitlist(self, log=None): tp = TraitParent(self.conn, self.current.suite) listed = [x.trait for x in self._traits.trait_rows()] all = list(tp.get_traitset(listed)) setfun = tp.set_trait parfun = tp.parents return make_deplist(listed, all, setfun, parfun, log) def family_rows(self, profile=None): if profile is None: profile = self.current.profile return self._pfam.select(clause=Eq('profile', profile), order='family') def get_families(self, profile=None): return [r.family for r in self.family_rows(profile)] def get_trait_rows(self): return self._traits.trait_rows() def append_family(self, family): if family not in self.get_families(): self._pfam.insert( data=dict(profile=self.current.profile, family=family)) def append_trait(self, trait, ord): self._traits.insert_trait(trait, ord) def set_suite(self, suite): clause = Eq('profile', self.current.profile) self.update(data=dict(suite=suite), clause=clause) self.set_profile(self.current.profile) def copy_profile(self, src, dest): current = self.current self.set_profile(src) pfield = "'%s' as profile" % dest pclause = Eq('profile', src) pcursor = self tcursor = self._traits.cmd fcusor = self._pfam vcursor = self._env.env.cursor cursors = [pcursor, tcursor, fcusor, vcursor] for cursor in cursors: sel = str( cursor.stmt.select(fields=[pfield] + cursor.fields()[1:], clause=pclause)) cursor.execute('insert into %s (%s)' % (cursor.stmt.table, sel)) self.set_profile(current.profile)
class ProfileGenWin(CommandBoxWindow): def __init__(self, conn, name='ProfileGenWin'): actions = ['create', 'copy', 'export', 'import'] CommandBoxWindow.__init__(self, name=name) self.set_title(name) self.conn = conn self.cmd = StatementCursor(conn, name) self.suites = [x.suite for x in self.cmd.select(table='suites')] self.profiles = StatementCursor(conn, 'profiles') self.profiles.set_table('profiles') self.menu_bar = SimpleMenuBar() self.vbox.pack_start(self.menu_bar, 0, 0, 0) self.dialogs = {}.fromkeys(actions) self.add_menu(actions, 'main', self.ask_dialog) self.add_menu(self.suites, 'traits', self.show_traits) self.add_menu(self.suites, 'traitgen', self.show_traitgen) self.browser = ProfileBrowser(self.conn, self.suites) self.vbox.add(self.browser) self.set_size_request(400, 300) def ask_dialog(self, button, data): if not self.dialogs[data]: if data == 'create': self.dialogs[data] = dialogs.Entry('create profile', name='create') self.dialogs[data].set_ok(self.create_profile) elif data == 'copy': self.dialogs[data] = dialogs.CList('copy profile', name='copy') dialog = self.dialogs[data] dialog.set_rows(self.profiles.select(fields='profile', order='profile')) dialog.set_ok(self.src_profile_selected) elif data == 'export': pdb = PaellaDatabase(self.conn) profiles = pdb.profiles self.dialogs[data].set_cancel(self.destroy_dialog) def destroy_dialog(self, dying): name = dying.get_name() self.dialogs[name] = None dying.destroy() def create_profile(self, button): name = button.get_name() debug(name) if name == 'create': profile = self.dialogs[name].get() if profile not in [p.profile for p in self.profiles.select()]: self.profiles.insert(data={'profile' : profile, 'suite' : 'woody'}) self.destroy_dialog(self.dialogs[name]) self.browser.reset_rows() else: dialogs.Dialog('there was a problem') def src_profile_selected(self, button): row = get_single_row(self.dialogs['copy'], 'profile') def show_packages(self, button, data): PackagesWindow(self.conn, data) def show_traits(self, button, data): TraitsWindow(self.conn, data) def show_traitgen(self, button, data): TraitGenWin(self.conn, data)
class PaellaProfiles(Element): def __init__(self, conn): Element.__init__(self, 'profiles') self.conn = conn self.stmt = StatementCursor(self.conn) self.env = ProfileEnvironment(self.conn) self.profiletraits = ProfileTrait(self.conn) self._profiles = {} self._profile = Profile(self.conn) for row in self.stmt.select(table='profiles', order='profile'): self._append_profile(row.profile, row.suite) def _append_profile(self, profile, suite): element = self.export_profile(profile, suite) self._profiles[profile] = element self.appendChild(self._profiles[profile]) def export_profile(self, profile, suite=None): if suite is None: row = self.stmt.select_row(table='profiles', clause=Eq('profile', profile)) suite = row['suite'] suite = str(suite) profile = str(profile) self.env.set_profile(profile) element = ProfileElement(profile, suite) element.append_traits(self.profiletraits.trait_rows(profile)) element.append_families(self._profile.family_rows(profile)) element.append_variables(self.env.get_rows()) return element def insert_profile(self, profile): idata = {'profile': profile.name, 'suite': profile.suite} self.stmt.insert(table='profiles', data=idata) idata = {'profile': profile.name, 'trait': None, 'ord': 0} for trait, ord in profile.traits: print trait, ord idata['trait'] = trait idata['ord'] = ord #str(ord) self.stmt.insert(table='profile_trait', data=idata) idata = { 'profile': profile.name, 'trait': None, 'name': None, 'value': None } idata = dict(profile=profile.name) for family in profile.families: idata['family'] = family self.stmt.insert(table='profile_family', data=idata) idata = dict(profile=profile.name) for trait, name, value in profile.vars: idata['trait'] = trait idata['name'] = name idata['value'] = value self.stmt.insert(table='profile_variables', data=idata) def export_profiles(self, path): rows = self.stmt.select(fields='profile', table='profiles', clause=None) for row in rows: self.write_profile(row.profile, path) def write_profile(self, profile, path): xmlfile = file(join(path, '%s.xml' % profile), 'w') data = self.export_profile(profile) data.writexml(xmlfile, indent='\t', newl='\n', addindent='\t') xmlfile.close()
class Family(object): def __init__(self, conn): object.__init__(self) self.conn = conn self.suites = Suites(conn).list() self.cursor = StatementCursor(self.conn) self.current = None self.parent = SimpleRelation(self.conn, 'family_parent', 'family') self.env = FamilyEnvironment(self.conn) def set_family(self, family): self.current = family self.parent.set_current(family) self.env.set_family(family) def add_family(self, family, type='general'): pass def get_related_families(self, families=[]): rows = self.cursor.select(table='family_parent') graph = kjGraph([(r.family, r.parent) for r in rows]) dfamilies = Set() for fam in families: dfamilies |= Set([fam]) | Set(graph.reachable(fam).items()) return dfamilies def parent_rows(self, family=None): if family is None: family = self.current self.parent.set_clause(family) rows = self.parent.cmd.select(fields=['parent'], order='parent') self.parent.reset_clause() return rows def parents(self, family=None): rows = self.parent_rows(family) return [x.parent for x in rows] def environment_rows(self, family=None): if family is None: family = self.current clause = Eq('family', family) args = dict(fields=['trait', 'name', 'value'], clause=clause, order=['trait', 'name']) return self.env.cursor.select(**args) def family_rows(self): return self.cursor.select(fields=['family'], table='families', order='family') def all_families(self): return [r.family for r in self.family_rows()] def get_all_defaults(self): stmt = select_multisuite_union(self.suites, 'variables') print stmt self.cursor.execute(stmt) return self.cursor.fetchall() def create_family(self, family): if family not in self.all_families(): self.cursor.insert(table='families', data=dict(family=family)) else: raise ExistsError, '%s already exists' % family def insert_parents(self, parents): self.parent.insert('parent', parents) def FamilyData(self, families=[]): if families is None: families = [self.current] all = self.make_familylist(families) superdict = {} for f in all: superdict.update(self.env.make_tagdict(f)) return superdict def make_familylist(self, families): deps = families all = list(self.get_related_families(families)) setfun = self.set_family parfun = self.parents return make_deplist(deps, all, setfun, parfun) def export_family(self, family=None): if family is None: family = self.current element = FamilyElement(family) element.append_parents(self.parents(family)) element.append_variables(self.environment_rows(family)) return element def write_family(self, family, path): fxml = file(join(path, '%s.xml' % family), 'w') data = self.export_family(family) data.writexml(fxml, indent='\t', newl='\n', addindent='\t') fxml.close() def export_families(self, path): families = self.all_families() for f in families: self.write_family(f, path) def import_family(self, element): parsed = FamilyParser(element) print 'inserting family', parsed.name all = self.all_families() for p in parsed.parents: if p not in all: print 'insertion failed for', parsed.name raise UnbornError self.create_family(parsed.name) self.set_family(parsed.name) self.insert_parents(parsed.parents) row = dict(family=parsed.name) for var in parsed.environ: row.update(var) self.cursor.insert(table='family_environment', data=row) def import_families(self, path): xmlfiles = [ join(path, x) for x in os.listdir(path) if x[-4:] == '.xml' ] families = [] for f in xmlfiles: xml = parse_file(f) elements = xml.getElementsByTagName('family') if len(elements) != 1: raise Error, 'bad number of family tags %s' % len(elements) element = elements[0] families.append(element) while len(families): f = families[0] try: self.import_family(f) except UnbornError: families.append(f) del families[0] print len(families), 'families inserted'
class ColorThingyWindow(CommandBoxWindow): def __init__(self, rgb, conn, name='ColorThingyWindow'): CommandBoxWindow.__init__(self, name=name) self.browser = ColorThingy(rgb) self.rgb = rgb self.cmd = StatementCursor(conn, 'themer') self.theme = None self.vbox.add(self.browser) self.tbar.add_button('import', 'import', self.__ask_import__) self.tbar.add_button('insert', 'insert', self.__ask_insert__) self.tbar.add_button('update', 'update', self.__update_theme__) self.tbar.add_button('save', 'save', self.__save_files__) self._insert_box = None self._import_box = None def __ask_import__(self, *args): if not self._import_box: #print args #print '__import__' themes = self.cmd.getall(['theme'], 'themes') self._import_box = CList('hello') self._import_box.set_rows(themes) self._import_box.set_ok(self.__import_ok__) def __import_ok__(self, *args): theme = self._import_box.listbox.get_selected_data()[0]['theme'] self._import_box.destroy() self._import_box = None rows = self.cmd.select(table=theme) b = self.browser b._style.quick_set(rows) for e, sb in b._elements.items(): for s in sb.keys(): color = b._style.elements[e][s] sb[s] = color.name _bg_widget(sb[s].button, color) self.theme = theme def __ask_insert__(self, *args): if not self._import_box: self._insert_box = EntryDialog('please insert name') self._insert_box.set_ok(self.__insert_ok__) def __insert_ok__(self, *args): style = self.browser._style tname = self._insert_box.get() self.theme = tname table = ThemeTable(tname) self.cmd.create_table(table) self.cmd.insert('themes', {'theme': tname}) for row in style.to_irows(): self.cmd.insert(tname, row) def __update_theme__(self, *args): if self.theme: for element, states in self.browser._style.to_urows(): self.cmd.update(self.theme, states, "element = '%s'" % element) def __save_files__(self, *args): colordict = Rgbdb() tmpl = GtkrcTemplate(self.theme, theme_base, self.browser._style) tmpl.write_files()
class ProfileGenWin(CommandBoxWindow): def __init__(self, conn, name='ProfileGenWin'): actions = ['create', 'copy', 'export', 'import'] CommandBoxWindow.__init__(self, name=name) self.set_title(name) self.conn = conn self.cmd = StatementCursor(conn, name) self.suites = [x.suite for x in self.cmd.select(table='suites')] self.profiles = StatementCursor(conn, 'profiles') self.profiles.set_table('profiles') self.menu_bar = SimpleMenuBar() self.vbox.pack_start(self.menu_bar, 0, 0, 0) self.dialogs = {}.fromkeys(actions) self.add_menu(actions, 'main', self.ask_dialog) self.add_menu(self.suites, 'traits', self.show_traits) self.add_menu(self.suites, 'traitgen', self.show_traitgen) self.browser = ProfileBrowser(self.conn, self.suites) self.vbox.add(self.browser) self.set_size_request(400, 300) def ask_dialog(self, button, data): if not self.dialogs[data]: if data == 'create': self.dialogs[data] = dialogs.Entry('create profile', name='create') self.dialogs[data].set_ok(self.create_profile) elif data == 'copy': self.dialogs[data] = dialogs.CList('copy profile', name='copy') dialog = self.dialogs[data] dialog.set_rows( self.profiles.select(fields='profile', order='profile')) dialog.set_ok(self.src_profile_selected) elif data == 'export': pdb = PaellaDatabase(self.conn) profiles = pdb.profiles self.dialogs[data].set_cancel(self.destroy_dialog) def destroy_dialog(self, dying): name = dying.get_name() self.dialogs[name] = None dying.destroy() def create_profile(self, button): name = button.get_name() debug(name) if name == 'create': profile = self.dialogs[name].get() if profile not in [p.profile for p in self.profiles.select()]: self.profiles.insert(data={ 'profile': profile, 'suite': 'woody' }) self.destroy_dialog(self.dialogs[name]) self.browser.reset_rows() else: dialogs.Dialog('there was a problem') def src_profile_selected(self, button): row = get_single_row(self.dialogs['copy'], 'profile') def show_packages(self, button, data): PackagesWindow(self.conn, data) def show_traits(self, button, data): TraitsWindow(self.conn, data) def show_traitgen(self, button, data): TraitGenWin(self.conn, data)
class NewInstaller(object): def __init__(self, conn, cfg): object.__init__(self) self.conn = conn self.cfg = cfg self.machine = MachineHandler(self.conn) self.cursor = StatementCursor(self.conn) self.target = None self.installer = None self._mounted = None self._bootstrapped = None self.debmirror = self.cfg.get('debrepos', 'http_mirror') def _check_target(self): if not self.target: raise Error, 'no target specified' def _check_installer(self): if not self.installer: raise Error, 'no installer available' def _check_mounted(self): self._check_target() if not self._mounted: raise Error, 'target not mounted' def _check_bootstrap(self): self._check_mounted() if not self._bootstrapped: raise Error, 'target not bootstrapped' def set_machine(self, machine): self.machine.set_machine(machine) try: logfile = os.environ['LOGFILE'] except KeyError: logfile = '/paellalog/paella-install-%s.log' % machine os.environ['LOGFILE'] = logfile os.environ['PAELLA_MACHINE'] = machine def make_filesystems(self): device = self.machine.array_hack(self.machine.current.machine_type) all_fsmounts = self.machine.get_installable_fsmounts() env = CurrentEnvironment(self.conn, self.machine.current.machine) for row in all_fsmounts: pdev = device + str(row.partition) if row.mnt_name in env.keys(): print '%s held' % row.mnt_name else: print 'making filesystem for', row.mnt_name make_filesystem(pdev, row.fstype) def set_target(self, target): self.target = target def _pdev(self, device, partition): return device + str(partition) def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq('filesystem', self.machine.current.filesystem) clause &= Gt('partition', '0') table = 'filesystem_mounts natural join mounts' mounts = self.cursor.select(table=table, clause=clause, order='mnt_point') if mounts[0].mnt_point != '/': raise Error, 'bad set of mounts', mounts pdev = self._pdev(device, mounts[0].partition) print 'mounting target', pdev, self.target runlog('mount %s %s' % (pdev, self.target)) for mnt in mounts[1:]: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) pdev = self._pdev(device, mnt.partition) runlog('mount %s %s' % (pdev, tpath)) self._mounted = True def setup_installer(self): profile = self.machine.current.profile self.installer = ProfileInstaller(self.conn, self.cfg) self.installer.set_profile(profile) self.suite = self.installer.suite def organize_disks(self): return self.machine.check_machine_disks(self.machine.current.machine_type) def partition_disks(self): disks = self.organize_disks() for diskname in disks: for device in disks[diskname]: self._partition_disk(diskname, device) if len(disks[diskname]) > 1: ndev = len(disks[diskname]) print 'doing raid setup on %s' % diskname fs = self.machine.current.filesystem print fs pnums = [r.partition for r in self.machine.get_installable_fsmounts(fs)] for p in pnums: mdadm = 'mdadm --create /dev/md%d' % p mdadm = '%s --force -l1 -n%d ' % (mdadm, ndev) devices = ['%s%s' % (d, p) for d in disks[diskname]] command = mdadm + ' '.join(devices) print command yesman = 'bash -c "yes | %s"' % command print yesman os.system(yesman) print 'doing raid setup on %s' % str(disks[diskname]) mdstat = file('/proc/mdstat').read() while mdstat.find('resync') > -1: sleep(10) mdstat = file('/proc/mdstat').read() def _partition_disk(self, diskname, device): print 'partitioning', diskname, device dump = self.machine.make_partition_dump(diskname, device) i, o = os.popen2('sfdisk %s' % device) i.write(dump) i.close() def bootstrap_target(self): self._check_mounted() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True def ready_base_for_install(self): self._check_bootstrap() self._check_installer() fstab = self.machine.make_fstab() ready_base_for_install(self.target, self.cfg, self.suite, fstab) def install_to_target(self): os.environ['DEBIAN_FRONTEND'] = 'noninteractive' self._check_target() self._check_installer() self.installer.set_target(self.target) self.installer.process() def post_install(self): print 'post_install' modules = self.machine.get_modules() print 'installing modules', modules setup_modules(self.target, modules) print 'modules installed' kernel = self.machine.current.kernel print 'installing kernel', kernel install_kernel(kernel, self.target) print 'kernel installed' def install(self, machine, target): self.set_machine(machine) self.partition_disks() self.make_filesystems() self.setup_installer() self.set_target(target) self.ready_target() self.bootstrap_target() self.ready_base_for_install() self.install_to_target() self.post_install()