class TraitAssigner(BaseAssigner): def __init__(self, app, parent, profile): self.profile = Profile(app.conn) self.profile.set_profile(profile) BaseAssigner.__init__(self, app, parent, name='TraitAssigner', udbuttons=True) self.connect(self, SIGNAL('okClicked()'), self.slotInsertNewTraits) def initView(self): app = self.app self.db = app.db self.suite = self.profile.current.suite self.traits = StatementCursor(app.conn) self.traits.set_table('%s_traits' % self.suite) ptrows = self.profile.get_trait_rows() pt = [r.trait for r in ptrows] all_trows = self.traits.select(fields=['trait'], order=['trait']) trows = [r for r in all_trows if r.trait not in pt] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for row in ptrows: r = QListBoxText(sbox, row.trait) r.trait = row.trait for row in trows: r = QListBoxText(abox, row.trait) r.trait = row.trait def slotInsertNewTraits(self): sbox = self.listBox.selectedListBox() traits = [sbox.item(n).trait for n in range(sbox.numRows())] self.profile.insert_new_traits(traits)
def __init__(self, conn, table, keyfield): StatementCursor.__init__(self, conn, name='AllTraits') self.set_table(table) self.textfiles = TextFileManager(conn) self._keyfield = keyfield self._jtable = '%s as s join textfiles as t ' % table self._jtable += 'on s.scriptfile = t.fileid'
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', 'browser'] 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)
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', 'browser' ] 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 DpkgDb(object): def __init__(self, name, conn): object.__init__(self) self.name = name self.cmd = StatementCursor(conn, 'DpkgDb') def _table(self, table): return ujoin(self.name, table) def get_available(self, fields, **args): return self.cmd.getall(fields, self._table('available'), **args) def get_status(self, fields, **args): return self.cmd.getall(fields, self._table('status'), **args) def create(self, config): print 'making status' sttable = StatusTable(self._table('status')) create_and_insert(self.cmd, sttable, config.get_status()) print 'making available' avtable = AvailableTable(self._table('available')) create_and_insert(self.cmd, avtable, config.get_available()) print 'making filelist' fltable = FilelistTable(self._table('files')) mk_filelist_table(self.cmd, fltable, config.get_files()) print 'making conffiles' cftable = FilelistTable(self._table('conffiles')) mk_filelist_table(self.cmd, cftable, config.get_conffiles()) print 'making md5sums' mdtable = Md5sumsTable(self._table('md5sums')) mk_md5sums_table(self.cmd, mdtable, config.get_md5sums()) print 'making current' cutable = Md5sumsTable(self._table('current')) mk_current_table(self.cmd, cutable, config.get_files())
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 = FamilyEnvironment(self.conn)
def initlistView(self): self.cursor = StatementCursor(self.app.conn) table = 'machines' rows = self.cursor.select(table='machine_types') self.listView.addColumn('machine_type') for row in rows: KListViewItem(self.listView, row.machine_type)
def initlistView(self): self.cursor = StatementCursor(self.app.conn) table = 'filesystems' rows = self.cursor.select(table=table) self.listView.addColumn('filesystem') for row in rows: KListViewItem(self.listView, row.filesystem)
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)
class TraitAssigner(BaseAssigner): def __init__(self, app, parent, profile): self.profile = Profile(app.conn) self.profile.set_profile(profile) BaseAssigner.__init__(self, app, parent, name='TraitAssigner', udbuttons=True) self.connect(self, SIGNAL('okClicked()'), self.slotLaughAtMe) def initView(self): app = self.app self.db = app.db self.suite = self.profile.current.suite self.traits = StatementCursor(app.conn) self.traits.set_table('%s_traits' % self.suite) ptrows = self.profile.get_trait_rows() pt = [r.trait for r in ptrows] all_trows = self.traits.select(fields=['trait'], order=['trait']) trows = [r for r in all_trows if r.trait not in pt] abox = self.listBox.availableListBox() sbox = self.listBox.selectedListBox() for row in ptrows: r = QListBoxText(sbox, row.trait) r.trait = row.trait for row in trows: r = QListBoxText(abox, row.trait) r.trait = row.trait def slotLaughAtMe(self): sbox = self.listBox.selectedListBox() traits = [sbox.item(n).trait for n in range(sbox.numRows())] print 'laughing out loud', traits
def make_a_machine(conn, machine, mtype, profile, fs): cursor = StatementCursor(conn) data = dict(machine=machine, machine_type=mtype, profile=profile, filesystem=fs) cursor.insert(table='machines', data=data)
def __set_suite_cursors__(self, suite): self.traits = StatementCursor(self.conn, 'traits') self.traits.set_table(ujoin(suite, 'traits')) self.traitparent = TraitParent(self.conn, suite) self.traitpackage = TraitPackage(self.conn, suite) self.traittemplate = TraitTemplate(self.conn, suite) self.family = Family(self.conn)
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')
def add_mount_to_filesystem(conn, mnt_name, filesystem, ord, partition): cursor = StatementCursor(conn) data = dict(mnt_name=mnt_name, filesystem=filesystem, ord=str(ord), partition=partition) cursor.insert(table='filesystem_mounts', data=data)
def __init__(self, conn, cfg): self.conn = conn self.cfg = cfg self.cursor = StatementCursor(self.conn) self.http_mirror = 'http://%s' % self.cfg.get('debrepos', 'repos_host') self.local_mirror = 'file:/tmp/paellamirror' self.suite = None self.sources_rows = []
def add_new_mount(conn, name, mtpt, fstype, opts, dump='0', pass_='0'): cursor = StatementCursor(conn) data = dict(mnt_name=name, mnt_point=mtpt, fstype=fstype, mnt_opts=opts, dump=dump) data['pass'] = pass_ cursor.insert(table='mounts', data=data)
def __init__(self, parent, name='ScriptNameComboBox'): KComboBox.__init__(self, parent, name) self.app = get_application_pointer() self.cursor = StatementCursor(self.app.conn) self.scriptnames = [ row.script for row in self.cursor.select(table='scriptnames') ] self.insertStrList(self.scriptnames)
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, 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 = {}
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)
def __init__(self, conn): object.__init__(self) self.conn = conn #self.suites = Suites(conn).list() self.cursor = StatementCursor(self.conn) self.suites = [r.suite for r in self.cursor.select(table='suites')] self.current = None self.parent = SimpleRelation(self.conn, 'family_parent', 'family') self.env = FamilyEnvironment(self.conn)
def __init__(self, parent, type, name='ScriptNameComboBox'): KComboBox.__init__(self, parent, name) self.app = get_application_pointer() self.cursor = StatementCursor(self.app.conn) clause = In('type', ['both', type]) rows = self.cursor.select(table='scriptnames', clause=clause) #self.scriptnames = [row.script for row in self.cursor.select(table='scriptnames')] self.scriptnames = [row.script for row in rows] self.insertStrList(self.scriptnames)
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 __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)
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 __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 __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)
def create_database(cfg, default_traits): dsn = cfg.get_dsn() dsn['dbname'] = 'mishmash' conn = QuickConn(dsn) cmd = StatementCursor(conn, 'create_database') for table in cmd.tables(): cmd.execute('drop table %s' % table) start_schema(conn, default_traits) make_suites(conn) cmd.execute(grant_public(cmd.tables())) cmd.execute(grant_public(['current_environment'], 'ALL'))
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 __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, r.size)
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)
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)
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
def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite
def _connect(self, dbname): if self.connections.has_key(dbname): dialogs.Message('connection already exists for %s' % dbname) else: conn = BaseConnection(user=self._dbuser, host=self._dbhost, dbname=dbname, passwd=self._dbpasswd) self.connections[dbname] = conn cursor = StatementCursor(self.connections[dbname]) rows = cursor.tables() tables = ScrollCList(rcmenu=self.table_edit_menu) tables.set_rows(rows, columns=['table']) self.append_page(tables, dbname) self.set_current_page(dbname)
def __init__(self, conn, maintable, reltable, pkey, fields): 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.rel = StatementCursor(self.conn) self.rel.set_table(reltable) self.pkey = pkey self._fields = fields self.fields = [self.pkey] + self._fields self.reset_rows() self.dialogs = {}.fromkeys(['insert', 'update', 'delete']) self.relmenu = make_menu(['insert', 'update', 'delete'], self.relmenu_command)
def create_database(cfg, default_traits): dsn = cfg.get_dsn() dsn['dbname'] = 'mishmash' conn = QuickConn(dsn) cmd = StatementCursor(conn, 'create_database') for table in cmd.tables(): cmd.execute('drop table %s' %table) start_schema(conn, default_traits) make_suites(conn) cmd.execute(grant_public(cmd.tables())) cmd.execute(grant_public(['current_environment'], 'ALL'))
def find_missing_packages(self, traitxml): all_packages = [] missing = [] cursor = StatementCursor(self.conn) suite = traitxml.suite ptable = '%s_packages' % suite for package, action in traitxml.packages: if package not in all_packages: all_packages.append(package) for package in all_packages: try: row = cursor.select_row(table=ptable, clause=Eq('package', package)) except NoExistError: missing.append(package) return missing
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)
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)
def initlistView(self): self.cursor = StatementCursor(self.app.conn) table='machines' rows = self.cursor.select(table='machines') self.listView.addColumn('machine') for row in rows: KListViewItem(self.listView, row.machine)
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.aptsources = AptSourceListElement() self.appendChild(self.aptsources) if 'apt_sources' in self.stmt.tables(): for row in self.stmt.select(table='apt_sources', order=['apt_id']): element = AptSourceElement(row.apt_id, row.uri, row.dist, row.sections, row.local_path) self.aptsources.appendChild(element) 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) for suiteapt in self.stmt.select(table='suite_apt_sources', order=['ord'], clause=Eq('suite', row.suite)): element.appendChild(SuiteAptElement(row.suite, suiteapt.apt_id, str(suiteapt.ord))) self.suites.appendChild(element) else: print 'WARNING, apt_sources table does not exist, backing up anyway' 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 __init__(self, conn=None): if conn is None: self.conn = KonsultantConnection() else: self.conn = conn self.stmt = Statement() self.mcursor = StatementCursor(self.conn)
class ScriptNameComboBox(KComboBox): def __init__(self, parent, name='ScriptNameComboBox'): KComboBox.__init__(self, parent, name) self.app = get_application_pointer() self.cursor = StatementCursor(self.app.conn) self.scriptnames = [row.script for row in self.cursor.select(table='scriptnames')] self.insertStrList(self.scriptnames)
def initlistView(self): self.cursor = StatementCursor(self.app.conn) table='filesystems' rows = self.cursor.select(table=table) self.listView.addColumn('filesystem') for row in rows: KListViewItem(self.listView, row.filesystem)
class DisksElement(Element): def __init__(self, conn, disks=None): Element.__init__(self, "disks") self.conn = conn self.cursor = StatementCursor(self.conn) if disks is None: 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 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 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('')
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"])
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, r.size) def append_fs_mount(self, mnt_name, ord, partition, size): fs_mount_element = FilesystemMountElement(mnt_name, str(ord), str(partition), str(size)) self.mounts.append(fs_mount_element) self.appendChild(fs_mount_element)
def __init__(self, parent, type, name='ScriptNameComboBox'): KComboBox.__init__(self, parent, name) self.app = get_application_pointer() self.cursor = StatementCursor(self.app.conn) clause=In('type', ['both', type]) rows = self.cursor.select(table='scriptnames', clause=clause) #self.scriptnames = [row.script for row in self.cursor.select(table='scriptnames')] self.scriptnames = [row.script for row in rows] self.insertStrList(self.scriptnames)