示例#1
0
 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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
 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)
示例#5
0
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 __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__()
示例#7
0
 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)
示例#8
0
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
示例#9
0
 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)
示例#10
0
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'))
示例#11
0
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)
示例#12
0
 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')
示例#13
0
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]
示例#14
0
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)
示例#15
0
 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)
示例#16
0
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)
示例#17
0
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
示例#18
0
 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)
示例#19
0
 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()
示例#20
0
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)
示例#21
0
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)
示例#22
0
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('')
示例#23
0
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()
示例#24
0
 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)
示例#25
0
 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)
示例#26
0
 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)
示例#27
0
 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 = {}
示例#28
0
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())
示例#29
0
 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()
示例#30
0
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