Esempio n. 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', '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)
Esempio n. 2
0
 def pkey_selected(self, listbox, row, column, event):
     value = listbox.get_selected_data()[0][0]
     self.current_value = value
     if value not in self.pages:
         rows  = self.rel.select(clause=Eq(self.pkey, value), order=self.pkey)
         rtable = ScrollCList(rcmenu=self.relmenu)
         rtable.set_rows(rows)
         self.append_page(rtable, value)
     self.set_current_page(value)
Esempio n. 3
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()
Esempio n. 4
0
 def pkey_selected(self, listbox, row, column, event):
     value = listbox.get_selected_data()[0][0]
     self.current_value = value
     if value not in self.pages:
         rows = self.rel.select(clause=Eq(self.pkey, value),
                                order=self.pkey)
         rtable = ScrollCList(rcmenu=self.relmenu)
         rtable.set_rows(rows)
         self.append_page(rtable, value)
     self.set_current_page(value)
Esempio n. 5
0
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)
Esempio n. 6
0
 def __init__(self, conn):
     self.menu = make_menu(['delete'], self.modify_family)
     ListNoteBook.__init__(self)
     self.conn = conn
     self.family = Family(self.conn)
     self.var_menu = make_menu(['edit', 'nothing', 'nothing', 'drop'],
                           self.var_menu_selected)
     self.parent_menu = make_menu(['drop'], self.modify_parent)
     self.reset_rows()
     self.append_page(ScrollCList(rcmenu=self.var_menu), 'environment')
     self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents')
     self.set_size_request(400, 300)
Esempio n. 7
0
 def __init__(self, conn, suite):
     self.menu = make_menu(['delete'], self.modify_trait)
     ListNoteBook.__init__(self)
     self.conn = conn
     self.suite = suite
     self.trait = Trait(self.conn, self.suite)
     self.package_menu = make_menu(['install', 'remove', 'purge', 'drop'],
                                   self.set_package)
     self.parent_menu = make_menu(['drop'], self.modify_parent)
     self.reset_rows()
     self.append_page(ScrollCList(rcmenu=self.package_menu), 'packages')
     self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents')
     self.set_size_request(400, 300)
Esempio n. 8
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)
Esempio n. 9
0
 def __init__(self, conn, name='ClientManager'):
     CommandBoxWindow.__init__(self)
     self.set_title('Client Manager')
     self.conn = conn
     self.cfg = PaellaConfig()
     client_cmds = ['import', 'export', 'remove']
     self.add_menu(client_cmds, 'client', self.menu_command)
     self.client_view = ScrollCList()
     self.vbox.add(self.client_view)
     self.client_path = self.cfg.get('management_gui', 'client_path')
     self.client_cfg = Configuration(
         files=[os.path.join(self.client_path, 'config')])
     self.clients = self.client_cfg.sections()
     self.client_view.set_rows(self.clients, ['client'])
     self.dialogs = {}.fromkeys(client_cmds)
Esempio n. 10
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)
Esempio n. 11
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',
             '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)
Esempio n. 12
0
 def __init__(self, conn, suites, name='ProfileBrowser'):
     self.menu = self.__make_mainmenu_(suites)
     ListNoteBook.__init__(self, name=name)
     self.conn = conn
     self.profiles = Profile(self.conn)
     self.profiletrait = ProfileTrait(self.conn)
     self.family = Family(self.conn)
     self.pfamily = StatementCursor(self.conn)
     self.pfamily.set_table('profile_family')
     self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
     self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
     self.family_menu = make_menu(['drop'], self.family_command)
     self.reset_rows()
     self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
     self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
     self.append_page(ScrollCList(rcmenu=self.family_menu), 'families')
     self.dialogs = {}.fromkeys(['order'])
Esempio n. 13
0
 def __init__(self, conn, suite=None):
     self.menu = make_menu(TRAITCMDS, self.trait_command)
     ListNoteBook.__init__(self)
     self.conn = conn
     self.suite = suite
     self.reset_rows()
     for page in ['parents', 'packages', 'templates', 'scripts']:
         self.append_page(ScrollCList(), page)
Esempio n. 14
0
 def select_trait(self, trait):
     self.trait = trait
     self.dc.set_trait(trait)
     if trait not in self.pages:
         newpage = ScrollCList()
         self.append_page(newpage, trait)
     self.set_current_page(trait)
     self.pages[trait].set_rows(self.dc.cmd.select())
Esempio n. 15
0
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()
Esempio n. 16
0
 def __init__(self, repos, dialogs, name='SourceView'):
     VPaned.__init__(self)
     self.repos = repos
     self.set_name(name)
     commands = [
         'update section lists', 'check for missing', 'check for corrupt'
     ]
     self.release_menu = make_menu(commands, self.release_command)
     self.release = ScrollCList(rcmenu=self.release_menu)
     self.add2(self.release)
     self.status = SourceStatus()
     self.add1(self.status)
     self.show()
     rp = self.repos
     sources_text = '\n'.join(map(str, [rp.remote_src, rp.local_src]))
     self.status.source_label.set_text(sources_text)
     if self.repos.check_local_release_file():
         self.reset_rows()
     self.dialogs = dialogs
Esempio n. 17
0
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()
Esempio n. 18
0
 def __init__(self, conn, name='ClientManager'):
     CommandBoxWindow.__init__(self)
     self.set_title('Client Manager')
     self.conn = conn
     self.cfg = PaellaConfig()
     client_cmds = ['import', 'export', 'remove']
     self.add_menu(client_cmds, 'client', self.menu_command)
     self.client_view = ScrollCList()
     self.vbox.add(self.client_view)
     self.client_path = self.cfg.get('management_gui', 'client_path')
     self.client_cfg = Configuration(files=[os.path.join(self.client_path, 'config')])
     self.clients = self.client_cfg.sections()
     self.client_view.set_rows(self.clients, ['client'])
     self.dialogs = {}.fromkeys(client_cmds)
Esempio n. 19
0
class Manager(CommandBoxWindow):
    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 edit_command(self, menuitem, name):
        if self.conn is None:
            dialogs.Message('Not Connected')
        else:
            if name == 'profiles':
                self.workspace['profiles'] = ProfileGenWin(self.conn, self.dbname)
            elif name in ['suitemanager']:
                if not self.dialogs[name]:
                    msg = 'select a suite'
                    self.dialogs[name] = dialogs.CList(msg, name=name)
                    lbox = self.dialogs[name]
                    lbox.set_rows(self.main.select(table='suites'))
                    lbox.set_ok(self.suite_selected)
                    lbox.set_cancel(self.destroy_dialog)
            else: self.run_tbar(None, name)
            

    def run_tbar(self, button=None, data=None):
        if data == 'profiles':
            self.workspace[data] = ProfileGenWin(self.conn, self.dbname)
        elif data == 'machines':
            self.workspace[data] = MainMachineWin(self.conn)
        elif data == 'traits':
            self.workspace[data] = TraitManagerWin(self.conn)
        elif data == 'families':
            self.workspace[data] = FamilyWin(self.conn)
        elif data == 'tdiff':
            self.workspace[data] = DifferWin(self.conn, 'template')
        elif data == 'sdiff':
            self.workspace[data] = DifferWin(self.conn, 'script')
        elif data == 'fdiff':
            self.workspace[data] = DifferWin(self.conn, 'family')
        elif data == 'default_environment':
            self.workspace[data] = DefEnvEditor(self.conn)
        elif data == 'clients':
            self.workspace[data] = ClientManager(self.conn)
        elif data == 'browser':
            self.workspace[data] = 'working'
            print data
            os.spawnlpe(os.P_NOWAIT, 'paella-kde-management',
                        '--display :0', os.environ)
            print data, 'running'
        else:
            dialogs.Message('bad command %s' % data)
        
    def database_command(self, menuitem, name):
        if name == 'connect':
            if self.conn is None and not self.dialogs['dbname']:
                msg = 'connect to which database?'
                dbname = self.dblist.get_selected_data()[0].datname
                self.dialogs['dbname']  = dialogs.Entry(msg, name='dbname')
                entry = self.dialogs['dbname']
                entry.set_ok(self.ok_dialog)
                entry.set_cancel(self.destroy_dialog)
                entry.set(dbname)
            else:
                dialogs.Message('no multiple connections yet')
        elif name == 'disconnect':
            if self.conn is not None:
                self.main.close()
                self.conn.close()
                self.conn = None
                self.dbname = None
            else:
                dialogs.Message('no connection to leave')
        elif name in ['backup', 'restore']:
            filesel = FileSelection(title='%s database' %name)
            filesel.cancel_button.connect('clicked',
                                          lambda x: filesel.destroy())
            filesel.show()
            bkup_path = self.cfg['import_path']
            filesel.set_filename(self._filepath_(bkup_path))
            filesel.ok_button.connect('clicked', self.ok_file, filesel)
            filesel.set_data('action', name)
        else:
            dialogs.Message('%s unimplemented'%name)

    def ok_file(self, button, filesel):
        path = filesel.get_filename()
        mdpath = join(dirname(path), 'machine_database.xml')
        action = filesel.get_data('action')
        filesel.destroy()
        dir = dirname(path)
        dbm = DatabaseManager(self.conn)
        if action == 'backup':
            dbm.backup(dir)
        elif action == 'restore':
            dbm.restore(dir)
            
    def suite_selected(self, button):
        name = button.get_name()
        row = self.dialogs[name].get_selected_data()[0]
        debug(row.suite)
        self.destroy_dialog(self.dialogs[name])
        SuiteManager(self.conn, row.suite)
        
        
    def _filepath_(self, path):
        return join(path, self.dbname + '.xml')
    
    def ok_dialog(self, button):
        name = button.get_name()
        if name == 'dbname':
            dbname = self.dialogs[name].get()
            self.dbconnect(dbname)
        self.destroy_dialog(self.dialogs[name])
        
    def dbconnect(self, dbname):
        self.cfg.change('database')
        dsn = self.cfg.get_dsn()
        dsn['dbname'] = dbname
        self.conn = PaellaConnection(dsn)
        self.main = StatementCursor(self.conn, 'mainManager')
        self.dbname = dbname
        dialogs.Message('connected to database %s' %dbname)

        
    def destroy_dialog(self, dying):
        name = dying.get_name()
        self.dialogs[name] = None
        dying.destroy()
Esempio n. 20
0
class ClientManager(CommandBoxWindow):
    def __init__(self, conn, name='ClientManager'):
        CommandBoxWindow.__init__(self)
        self.set_title('Client Manager')
        self.conn = conn
        self.cfg = PaellaConfig()
        client_cmds = ['import', 'export', 'remove']
        self.add_menu(client_cmds, 'client', self.menu_command)
        self.client_view = ScrollCList()
        self.vbox.add(self.client_view)
        self.client_path = self.cfg.get('management_gui', 'client_path')
        self.client_cfg = Configuration(
            files=[os.path.join(self.client_path, 'config')])
        self.clients = self.client_cfg.sections()
        self.client_view.set_rows(self.clients, ['client'])
        self.dialogs = {}.fromkeys(client_cmds)

    def menu_command(self, menuitem, name):
        client = self.client_view.get_selected_data()[0][0]
        if name == 'export':
            self.export_client(client)
        elif name == 'import':
            self.import_client(client)
        elif name == 'remove':
            self.remove_client(client)
        else:
            dialogs.Message('%s %s' % (name, client))

    def _cpaths_(self, client):
        cpath = os.path.join(self.client_path, client)
        ppath = os.path.join(cpath, 'profiles')
        fpath = os.path.join(cpath, 'families')
        tpath = os.path.join(cpath, 'traits')
        return [cpath, ppath, fpath, tpath]

    def _client_schema(self, client):
        profiles = self.client_cfg.get_list('profiles', client)
        families = self.client_cfg.get_list('families', client)
        traits = self.client_cfg.get_list('traits', client)
        return [profiles, families, traits]

    def _client_mdata(self, client):
        disks = self.client_cfg.get_list('disks', client)
        mtypes = self.client_cfg.get_list('machine_types', client)
        machines = self.client_cfg.get_list('machines', client)
        return [disks, mtypes, machines]

    def export_client(self, client):
        cpath, ppath, fpath, tpath = self._cpaths_(client)
        makepaths(cpath)
        profiles, families, traits = self._client_schema(client)
        disks, mtypes, machines = self._client_mdata(client)
        if not disks:
            disks = None
        if not mtypes:
            mtypes = None
        if not machines:
            machines = None
        element = ClientMachineDatabaseElement(self.conn, disks, mtypes,
                                               machines)
        mdbpath = join(cpath, 'machine_database.xml')
        mdfile = file(mdbpath, 'w')
        mdfile.write(element.toprettyxml())
        mdfile.close()
        if profiles:
            makepaths(ppath)
            pp = PaellaProfiles(self.conn)
            for profile in profiles:
                pp.write_profile(profile, ppath)
        if families:
            makepaths(fpath)
            f = Family(self.conn)
            for family in families:
                f.write_family(family, fpath)
        if traits:
            makepaths(tpath)

    def import_client(self, client):
        cpath, ppath, fpath, tpath = self._cpaths_(client)
        profiles, families, traits = self._client_schema(client)
        mdbpath = join(cpath, 'machine_database.xml')
        if families:
            f = Family(self.conn)
            f.import_families(fpath)
        if profiles:
            pp = PaellaProcessor(self.conn, self.cfg)
            pp.main_path = cpath
            pp.insert_profiles()
        mh = MachineHandler(self.conn)
        md = mh.parse_xmlfile(mdbpath)
        mh.insert_parsed_element(md)

    def remove_client(self, client):
        profiles, families, traits = self._client_schema(client)
        disks, mtypes, machines = self._client_mdata(client)
        cursor = StatementCursor(self.conn)
        if machines:
            cursor.delete(table='machines', clause=In('machine', machines))
        for mtype in mtypes:
            cursor.execute("select * from delete_mtype('%s')" % mtype)
        for disk in disks:
            cursor.execute("select * from delete_disk('%s')" % disk)
        for profile in profiles:
            cursor.execute("select * from delete_profile('%s')" % profile)
        for family in families:
            cursor.execute("select * from delete_family('%s')" % family)
Esempio n. 21
0
class ClientManager(CommandBoxWindow):
    def __init__(self, conn, name='ClientManager'):
        CommandBoxWindow.__init__(self)
        self.set_title('Client Manager')
        self.conn = conn
        self.cfg = PaellaConfig()
        client_cmds = ['import', 'export', 'remove']
        self.add_menu(client_cmds, 'client', self.menu_command)
        self.client_view = ScrollCList()
        self.vbox.add(self.client_view)
        self.client_path = self.cfg.get('management_gui', 'client_path')
        self.client_cfg = Configuration(files=[os.path.join(self.client_path, 'config')])
        self.clients = self.client_cfg.sections()
        self.client_view.set_rows(self.clients, ['client'])
        self.dialogs = {}.fromkeys(client_cmds)
        
    def menu_command(self, menuitem, name):
        client = self.client_view.get_selected_data()[0][0]
        if name == 'export':
            self.export_client(client)
        elif name == 'import':
            self.import_client(client)
        elif name == 'remove':
            self.remove_client(client)
        else:
            dialogs.Message('%s %s' % (name, client))
            
    def _cpaths_(self, client):
        cpath = os.path.join(self.client_path, client)
        ppath = os.path.join(cpath, 'profiles')
        fpath = os.path.join(cpath, 'families')
        tpath = os.path.join(cpath, 'traits')
        return [cpath, ppath, fpath, tpath]

    def _client_schema(self, client):
        profiles = self.client_cfg.get_list('profiles', client)
        families = self.client_cfg.get_list('families', client)
        traits = self.client_cfg.get_list('traits', client)
        return [profiles, families, traits]
    
    def _client_mdata(self, client):
        disks = self.client_cfg.get_list('disks', client)
        mtypes = self.client_cfg.get_list('machine_types', client)
        machines = self.client_cfg.get_list('machines', client)
        return [disks, mtypes, machines]
    
    def export_client(self, client):
        cpath, ppath, fpath, tpath = self._cpaths_(client)
        makepaths(cpath)
        profiles, families, traits = self._client_schema(client) 
        disks, mtypes, machines = self._client_mdata(client)
        if not disks:
            disks = None
        if not mtypes:
            mtypes = None
        if not machines:
            machines = None
        element = ClientMachineDatabaseElement(self.conn, disks, mtypes, machines)
        mdbpath = join(cpath, 'machine_database.xml')
        mdfile = file(mdbpath, 'w')
        mdfile.write(element.toprettyxml())
        mdfile.close()
        if profiles:
            makepaths(ppath)
            pp = PaellaProfiles(self.conn)
            for profile in profiles:
                pp.write_profile(profile, ppath)
        if families:
            makepaths(fpath)
            f = Family(self.conn)
            for family in families:
                f.write_family(family, fpath)
        if traits:
            makepaths(tpath)

    def import_client(self, client):
        cpath, ppath, fpath, tpath = self._cpaths_(client)
        profiles, families, traits = self._client_schema(client)
        mdbpath = join(cpath, 'machine_database.xml')
        if families:
            f = Family(self.conn)
            f.import_families(fpath)
        if profiles:
            pp = PaellaProcessor(self.conn, self.cfg)
            pp.main_path = cpath
            pp.insert_profiles()
        mh = MachineHandler(self.conn)
        md = mh.parse_xmlfile(mdbpath)
        mh.insert_parsed_element(md)    
        
            
    def remove_client(self, client):
        profiles, families, traits = self._client_schema(client)
        disks, mtypes, machines = self._client_mdata(client)
        cursor = StatementCursor(self.conn)
        if machines:
            cursor.delete(table='machines', clause=In('machine', machines))
        for mtype in mtypes:
            cursor.execute("select * from delete_mtype('%s')" % mtype)
        for disk in disks:
            cursor.execute("select * from delete_disk('%s')" % disk)
        for profile in profiles:
            cursor.execute("select * from delete_profile('%s')" % profile)
        for family in families:
            cursor.execute("select * from delete_family('%s')" % family)
Esempio n. 22
0
class Manager(CommandBoxWindow):
    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 edit_command(self, menuitem, name):
        if self.conn is None:
            dialogs.Message('Not Connected')
        else:
            if name == 'profiles':
                self.workspace['profiles'] = ProfileGenWin(
                    self.conn, self.dbname)
            elif name in ['suitemanager']:
                if not self.dialogs[name]:
                    msg = 'select a suite'
                    self.dialogs[name] = dialogs.CList(msg, name=name)
                    lbox = self.dialogs[name]
                    lbox.set_rows(self.main.select(table='suites'))
                    lbox.set_ok(self.suite_selected)
                    lbox.set_cancel(self.destroy_dialog)
            else:
                self.run_tbar(None, name)

    def run_tbar(self, button=None, data=None):
        if data == 'profiles':
            self.workspace[data] = ProfileGenWin(self.conn, self.dbname)
        elif data == 'machines':
            self.workspace[data] = MainMachineWin(self.conn)
        elif data == 'traits':
            self.workspace[data] = TraitManagerWin(self.conn)
        elif data == 'families':
            self.workspace[data] = FamilyWin(self.conn)
        elif data == 'tdiff':
            self.workspace[data] = DifferWin(self.conn, 'template')
        elif data == 'sdiff':
            self.workspace[data] = DifferWin(self.conn, 'script')
        elif data == 'fdiff':
            self.workspace[data] = DifferWin(self.conn, 'family')
        elif data == 'default_environment':
            self.workspace[data] = DefEnvEditor(self.conn)
        elif data == 'clients':
            self.workspace[data] = ClientManager(self.conn)
        elif data == 'browser':
            self.workspace[data] = 'working'
            print data
            os.spawnlpe(os.P_NOWAIT,
                        '/home/umeboshi/bin/paella-kde-management',
                        '--display :0', os.environ)
            print data, 'running'
        else:
            dialogs.Message('bad command %s' % data)

    def database_command(self, menuitem, name):
        if name == 'connect':
            if self.conn is None and not self.dialogs['dbname']:
                msg = 'connect to which database?'
                dbname = self.dblist.get_selected_data()[0].datname
                self.dialogs['dbname'] = dialogs.Entry(msg, name='dbname')
                entry = self.dialogs['dbname']
                entry.set_ok(self.ok_dialog)
                entry.set_cancel(self.destroy_dialog)
                entry.set(dbname)
            else:
                dialogs.Message('no multiple connections yet')
        elif name == 'disconnect':
            if self.conn is not None:
                self.main.close()
                self.conn.close()
                self.conn = None
                self.dbname = None
            else:
                dialogs.Message('no connection to leave')
        elif name in ['backup', 'restore']:
            filesel = FileSelection(title='%s database' % name)
            filesel.cancel_button.connect('clicked',
                                          lambda x: filesel.destroy())
            filesel.show()
            bkup_path = self.cfg['import_path']
            filesel.set_filename(self._filepath_(bkup_path))
            filesel.ok_button.connect('clicked', self.ok_file, filesel)
            filesel.set_data('action', name)
        else:
            dialogs.Message('%s unimplemented' % name)

    def ok_file(self, button, filesel):
        path = filesel.get_filename()
        mdpath = join(dirname(path), 'machine_database.xml')
        action = filesel.get_data('action')
        filesel.destroy()
        dir = dirname(path)
        dbm = DatabaseManager(self.conn)
        if action == 'backup':
            dbm.backup(dir)
        elif action == 'restore':
            dbm.restore(dir)

    def suite_selected(self, button):
        name = button.get_name()
        row = self.dialogs[name].get_selected_data()[0]
        debug(row.suite)
        self.destroy_dialog(self.dialogs[name])
        SuiteManager(self.conn, row.suite)

    def _filepath_(self, path):
        return join(path, self.dbname + '.xml')

    def ok_dialog(self, button):
        name = button.get_name()
        if name == 'dbname':
            dbname = self.dialogs[name].get()
            self.dbconnect(dbname)
        self.destroy_dialog(self.dialogs[name])

    def dbconnect(self, dbname):
        self.cfg.change('database')
        dsn = self.cfg.get_dsn()
        dsn['dbname'] = dbname
        self.conn = PaellaConnection(dsn)
        self.main = StatementCursor(self.conn, 'mainManager')
        self.dbname = dbname
        dialogs.Message('connected to database %s' % dbname)

    def destroy_dialog(self, dying):
        name = dying.get_name()
        self.dialogs[name] = None
        dying.destroy()
Esempio n. 23
0
 def __init__(self, conn):
     self.conn = conn
     self.win = MenuWindow()
     self.scroll = ScrollCList()
     self.win.vbox.add(self.scroll)
     self.s = StatementCursor(self.conn)
Esempio n. 24
0
class SourceView(VPaned, HasDialogs):
    def __init__(self, repos, dialogs, name='SourceView'):
        VPaned.__init__(self)
        self.repos = repos
        self.set_name(name)
        commands = [
            'update section lists', 'check for missing', 'check for corrupt'
        ]
        self.release_menu = make_menu(commands, self.release_command)
        self.release = ScrollCList(rcmenu=self.release_menu)
        self.add2(self.release)
        self.status = SourceStatus()
        self.add1(self.status)
        self.show()
        rp = self.repos
        sources_text = '\n'.join(map(str, [rp.remote_src, rp.local_src]))
        self.status.source_label.set_text(sources_text)
        if self.repos.check_local_release_file():
            self.reset_rows()
        self.dialogs = dialogs

    def release_command(self, menuitem, action):
        print action
        if action == 'update section lists':
            rows = self.repos.local.check_all_dist_sections()
            dl = dialogs.CList('section lists status')
            dl.set_rows(rows)
            dl.set_usize(500, 300)
            bad_rows = [
                row for row in rows if row.status in ['missing', 'corrupt']
            ]
            jobs = [[self.repos.fulldistpath(row.path), row.full_path]
                    for row in bad_rows]
            if self.dialogs['downloads'] is None:
                self.dialogs['downloads'] = DownloadWindow()
                self.dialogs['downloads'].connect('destroy',
                                                  self.destroy_dialog)
            if self.dialogs['downloads'] is not None:
                for url, path in jobs:
                    self.dialogs['downloads'].pool.put(url, path)

        elif action == 'check for missing':
            status_rows = self.repos.local.check_all_sections()
            status_rows = [
                row for row in status_rows if row.status == 'missing'
            ]
            dl = dialogs.CList('status')
            dl.set_rows(status_rows)
            dl.set_usize(500, 300)
        elif action == 'check for corrupt':
            status_rows = self.repos.local.check_all_sections(quick=False)
            status_rows = [
                row for row in status_rows if row.status == 'corrupt'
            ]
            dl = dialogs.CList('status')
            dl.set_rows(status_rows)
            dl.set_usize(500, 300)
        self.reset_rows()

    def reset_rows_orig(self):
        section_files = self.repos.release.select()
        rowdesc = ['name', 'type', 'section', 'path', 'status']
        rows = []
        for rfile in section_files:
            section, release = self.repos.release.parse_path(rfile.path)
            status = self.repos.local.check_dist_section(section, release)
            rowvals = [rfile.name, rfile.type, section, rfile.path, status]
            rows.append(DbBaseRow(rowdesc, rowvals))
        self.release.set_rows(rows)

    def reset_rows(self):
        section_files = self.repos.release.select()
        rows = self.repos.local.check_all_dist_sections()
        self.release.set_rows(rows)