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 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, 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 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())
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)
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 __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)
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.traitdebconf = TraitDebconf(self.conn, suite)
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)
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 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, conn, name, type): self.conn = conn self.manager = RepositoryManager(self.conn) self.sources = StatementCursor(self.conn, 'Sources') self.sources.set_table('sources') self.release = ReleaseCursor(self.conn) self._section_ = PackageListCursor(self.conn) self.set_source(name, type)
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)
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, 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 __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): 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, 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)
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()
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, '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)
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 __init__(self, conn): self.conn = conn self.main = StatementCursor(self.conn, 'RepositoryMain') self.repos = StatementCursor(self.conn, 'Repository') self.repos.set_table('repository') self.sources = StatementCursor(self.conn, 'Sources') self.sources.set_table('sources') self.release = ReleaseCursor(self.conn) self.repsections = StatementCursor(self.conn, 'repos_section') self.repsections.set_table('repos_section') self.__init_db__()
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 _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, 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 start_schema(conn): cursor = StatementCursor(conn, 'start_schema') tables, mapping = primary_tables() map(cursor.create_table, tables) priorities_table = mapping['priorities'] insert_list(cursor, priorities_table.name, 'priority', PRIORITIES) insert_list(cursor, 'scriptnames', 'script', SCRIPTS) cursor.execute(grant_public([x.name for x in tables])) cursor.execute(grant_public(['current_environment'], 'ALL')) cursor.execute(grant_public(['partition_workspace'], 'ALL')) cursor.execute(plpgsql_delete_profile) cursor.execute(plpgsql_delete_trait)
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)
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): 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 __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 __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, 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 __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 __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)
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()
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'))
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 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 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]
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 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 TableBrowser(CList): def __init__(self, conn): self.cmd = StatementCursor(conn, name='TableBrowser') CList.__init__(self, 'Tables', name='TableBrowser') self.set_rows(self.cmd.tables(), ['table']) self.set_row_select(self.__hello__) self.statement = Statement('select') def __hello__(self, listbox, row, column, event): self.statement.table = listbox.get_selected_data()[0]['table'] table = self.statement.table tb = CList(table, name=table) rows = self.cmd.getall('*', table) cols = [] if len(rows): cols = rows[0].keys() tb.set_rows(rows, cols) tb.set_usize(400,200)
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 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, 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 __init__(self, dsn, name, parent=None, objname=None): QSqlDatabase.__init__(self, "QPSQL7", name, parent, objname) self.conn = BasicConnection(**dsn) self.setDatabaseName(dsn["dbname"]) self.setHostName(dsn["host"]) self.dbuser = dsn["user"] self.setUserName(self.dbuser) self.stmt = Statement() self.mcursor = StatementCursor(self.conn)
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)
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 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