Example #1
0
 def __init__(self, cfg=None):
     if cfg is None:
         cfg = PaellaConfig()
     dsn = cfg.get_dsn()
     dsn['dbusername'] = '******'
     PaellaConnection.__init__(self, dsn)
     print 'installer connection made'
Example #2
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)
Example #3
0
 def __init__(self, cfg=None):
     if cfg is None:
         cfg = PaellaConfig()
     dsn = cfg.get_dsn()
     dsn['dbusername'] = '******'
     PaellaConnection.__init__(self, dsn)
     print 'installer connection made'
Example #4
0
 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
Example #5
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)
 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)
Example #7
0
class DatabaseManager(object):
    def __init__(self, conn):
        object.__init__(self)
        self.cfg = PaellaConfig()
        self.conn = conn
        self.import_dir = self.cfg.get('database', 'import_path')
        self.export_dir = self.cfg.get('database', 'export_path')

    def backup(self, path):
        if not os.path.isdir(path):
            raise Error, 'arguement needs to be a directory'
        pdb = PaellaDatabase(self.conn, path)
        pdb.backup(path)
        mdbpath = join(path, 'machine_database.xml')
        me = MachineDatabaseElement(self.conn)
        mdfile = file(mdbpath, 'w')
        mdfile.write(me.toprettyxml())
        mdfile.close()

    def restore(self, path):
        if not os.path.isdir(path):
            raise Error, 'arguement needs to be a directory'
        dbpath = join(path, 'database.xml')
        mdbpath = join(path, 'machine_database.xml')
        pp = PaellaProcessor(self.conn)
        pp.create(dbpath)
        mh = MachineHandler(self.conn)
        md = mh.parse_xmlfile(mdbpath)
        mh.insert_parsed_element(md)    
Example #8
0
class DatabaseManager(object):
    def __init__(self, conn):
        object.__init__(self)
        self.cfg = PaellaConfig()
        self.conn = conn
        self.import_dir = self.cfg.get('database', 'import_path')
        self.export_dir = self.cfg.get('database', 'export_path')

    def backup(self, path):
        if not os.path.isdir(path):
            raise Error, 'arguement needs to be a directory'
        pdb = PaellaDatabase(self.conn, path)
        pdb.backup(path)
        mdbpath = join(path, 'machine_database.xml')
        me = MachineDatabaseElement(self.conn)
        mdfile = file(mdbpath, 'w')
        mdfile.write(me.toprettyxml())
        mdfile.close()

    def restore(self, path):
        if not os.path.isdir(path):
            raise Error, 'arguement needs to be a directory'
        dbpath = join(path, 'database.xml')
        mdbpath = join(path, 'machine_database.xml')
        pp = PaellaProcessor(self.conn)
        pp.create(dbpath)
        mh = MachineHandler(self.conn)
        md = mh.parse_xmlfile(mdbpath)
        mh.insert_parsed_element(md)
Example #9
0
 def __init__(self):
     object.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = PaellaConnection()
     self.profile = os.environ['PAELLA_PROFILE']
     self.target = os.environ['PAELLA_TARGET']
     self.machine = None
     self.trait = None
     self.suite = get_suite(self.conn, self.profile)
     self.pr = Profile(self.conn)
     self.pr.set_profile(self.profile)
     self.traitlist = self.pr.make_traitlist()
     self.pe = ProfileEnvironment(self.conn, self.profile)
     self.tp = TraitParent(self.conn, self.suite)
     self.fm = Family(self.conn)
     self.tr = Trait(self.conn, self.suite)
     self.families = list(
         self.fm.get_related_families(self.pr.get_families()))
     self._envv = None
     self.default = DefaultEnvironment(self.conn)
     self.installer = TraitInstaller(self.conn, self.suite, self.cfg)
     if os.environ.has_key('PAELLA_MACHINE'):
         self.machine = os.environ['PAELLA_MACHINE']
     if os.environ.has_key('PAELLA_TRAIT'):
         self.set_trait(os.environ['PAELLA_TRAIT'])
Example #10
0
def make_image(target='/tmp/isotarget', kernel='kernel-image-2.6.2installer'):
    cfg = PaellaConfig()
    kpath = '/mirrors/debian/local/questron'
    setup_directory(target)
    isolinuxcfg(target)
    unpack_kernel(kernel, target)
    os.system('mkisofs -V "paella-nfsboot" -r -pad -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o nfsboot.iso %s' % target)
    os.system('rm %s -fr' % target)
Example #11
0
 def __init__(self):
     object.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = PaellaConnection()
     self.profile = os.environ['PAELLA_PROFILE']
     self.target = os.environ['PAELLA_TARGET']
     self.suite = get_suite(self.conn, self.profile)
     self.pe = ProfileEnvironment(self.conn, self.profile)
     self.tp = TraitParent(self.conn, self.suite)
Example #12
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()
Example #13
0
def restore(machine, basefile=None):
    raise Error, 'need to fix me'
    cfg = PaellaConfig()
    umcfg = get_machines_config(machine)
    conn = InstallerConnection(cfg)
    ui = UmlInstaller(conn, umcfg)
    if basefile is None:
        basefile = join(umcfg['base_path'], umcfg['basefile'])
    ui.restore_profile(machine, basefile)
Example #14
0
 def __init__(self, conn, suite, trait):
     self.menu = make_menu(TEMPL_CMDS, self.template_command)
     self.conn = conn
     self.current_trait = trait
     self.traittemplate = TraitTemplate(self.conn, suite)
     self.traittemplate.set_trait(self.current_trait)
     self.traitpackage = TraitPackage(self.conn, suite)
     self.traitpackage.set_trait(self.current_trait)
     self.current_template = None
     self.cfg = PaellaConfig()
     self.template_path = '/nowhere'
     self._tmp_path = '/nowhere'
     self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path')
     ListNoteBook.__init__(self)
     self.set_suite(suite)
     self.extracted = None
     self.reset_rows()
     self.dialogs = {}.fromkeys(['attach', 'rootsel'])
Example #15
0
 def __init__(self, *args):
     KApplication.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = PaellaConnection(self.cfg)
     self.db = BaseDatabase(self.conn, 'paelladb', None)
     dirs = KStandardDirs()
     self.tmpdir = str(dirs.findResourceDir('tmp', '/'))
     self.datadir = str(dirs.findResourceDir('data', '/'))
     self.socketdir = str(dirs.findResourceDir('socket', '/'))
     dsn = {}
Example #16
0
 def __init__(self, conn, name='ProfileGenWin'):
     actions = ['create', 'copy', 'export', 'import']
     CommandBoxWindow.__init__(self, name=name)
     self.set_title(name)
     self.cfg = PaellaConfig()
     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.tbar.add_button('families', 'show all families',
                          self.families_window)
     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)
Example #17
0
 def __init__(self, conn, suite, cfg=None, name='SuiteManager'):
     if cfg is None:
         cfg = PaellaConfig()
     CommandBoxWindow.__init__(self, name=name)
     self.set_title('%s toolbar' % suite)
     self.cfg = cfg
     self.conn = conn
     self.suite = suite
     self.tbar.add_button('traits', 'trait manager', self.traitgen)
     self.tbar.add_button('templates', 'template manager', self.templates)
     self.tbar.add_button('environ', 'environment manager', self.environ)
     #self.tbar.add_button('debconf', 'debconf manager', self.debconf)
     self.tbar.add_button('scripts', 'script manager', self.scripts)
Example #18
0
 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
Example #19
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)
Example #20
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()
Example #21
0
 def __init__(self, conn, suite, trait):
     self.menu = make_menu(TEMPL_CMDS, self.template_command)
     self.conn = conn
     self.current_trait = trait
     self.traittemplate = TraitTemplate(self.conn, suite)
     self.traittemplate.set_trait(self.current_trait)
     self.traitpackage = TraitPackage(self.conn, suite)
     self.traitpackage.set_trait(self.current_trait)
     self.current_template = None
     self.cfg = PaellaConfig()
     self.template_path = '/nowhere'
     self._tmp_path = '/nowhere'
     self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path')
     ListNoteBook.__init__(self)
     self.set_suite(suite)
     self.extracted = None
     self.reset_rows()
     self.dialogs = {}.fromkeys(['attach', 'rootsel'])
Example #22
0
 def __init__(self, conn, name='ProfileGenWin'):
     actions = ['create', 'copy', 'export', 'import']
     CommandBoxWindow.__init__(self, name=name)
     self.set_title(name)
     self.cfg = PaellaConfig()
     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.tbar.add_button('families', 'show all families', self.families_window)
     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)
Example #23
0
 def __init__(self, conn):
     object.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = conn
     self.import_dir = self.cfg.get('database', 'import_path')
     self.export_dir = self.cfg.get('database', 'export_path')
Example #24
0
 def __init__(self, conn=None, cfg=None):
     self.conn = conn
     UmlChroot.__init__(self, cfg=cfg)
     self.options['paella_action'] = 'install'
     self.paellarc = PaellaConfig(files=[self.cfg['paellarc']])
Example #25
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']
        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)
        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()
Example #26
0
class TemplateBrowser(ListNoteBook):
    def __init__(self, conn, suite, trait):
        self.menu = make_menu(TEMPL_CMDS, self.template_command)
        self.conn = conn
        self.current_trait = trait
        self.traittemplate = TraitTemplate(self.conn, suite)
        self.traittemplate.set_trait(self.current_trait)
        self.traitpackage = TraitPackage(self.conn, suite)
        self.traitpackage.set_trait(self.current_trait)
        self.current_template = None
        self.cfg = PaellaConfig()
        self.template_path = '/nowhere'
        self._tmp_path = '/nowhere'
        self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path')
        ListNoteBook.__init__(self)
        self.set_suite(suite)
        self.extracted = None
        self.reset_rows()
        self.dialogs = {}.fromkeys(['attach', 'rootsel'])
        
    def reset_rows(self):
        rows = self.traittemplate.templates(fields=['template', 'package'])
        self.set_rows(rows)
        self.set_row_select(self.template_selected)
        self.templates = [r.template for r in rows]
            
    def template_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.set_template(row.package, row.template)
    
    def set_template(self, package, template):
        self.current_package = package
        self.current_template = template
        if template not in self.pages:
            trait = self.current_trait
            nbook = TemplateNotebook(self.conn, self.cfg, self.suite, trait,
                                     package, template, self.extracted)
            self.append_page(nbook, template)
        else:
            self.set_current_page(template)
            
    def template_filename(self, package, template):
        tpath = join(self.template_path, self.suite, self.current_trait)
        return join(tpath, package, template + '.template')
        

    def suite_template_path(self, filesel=False):
        path = join(self.template_path, self.suite)
        if filesel:
            path += '/'
        return path

    def trait_temp_path(self, filesel=False):
        path = join(self._tmp_path, self.suite, self.current_trait)
        if filesel:
            path += '/'
        return path
       
    def set_suite(self, suite):
        self.suite = suite

    def save_template(self):
        try:
            template = self.get_selected_data()[0].template
            self.pages[template].save_template()
        except IndexError:
            dialogs.Message('a template must be selected')
            

    def edit_template(self):
        try:
            template = self.get_selected_data()[0].template
            self.pages[template].edit_template()
        except IndexError:
            dialogs.Message('a template must be selected')
            
        
        
    def template_command(self, meuitem, command):
        if command in ['new']:
            path = self.trait_temp_path(filesel=True)
            select_a_file('new', path, self.fileselect_ok)
        elif command == 'diff':
            path = self.suite_template_path(filesel=True)
            select_a_file('load', path, self.fileselect_ok)
        elif command == 'save':
            self.save_template()
        elif command == 'load':
            path = self.suite_template_path(filesel=True)
            select_a_file('load', path, self.fileselect_ok)
        elif command == 'done':
            try:
                template = self.get_selected_data()[0].template
                self.remove_page(template)
            except IndexError:
                pass
        elif command == 'drop':
            print 'need to drop template'
            rows = self.get_selected_data()
            if len(rows):
                row = rows[0]
                self.traittemplate.drop_template(row.package, row.template)
                self.remove_page(row.template)
                self.reset_rows()
            else:
                dialogs.Message('a template must be selected')
        elif command == 'root':
            if self.dialogs['rootsel'] is None:
                path = self.tarball_path + '/'
                select_a_file('root', path, self.tarball_selected)
        elif command == 'edit':
            self.edit_template()
            
            


    def tarball_selected(self, button, fileselect):
        path = fileselect.get_filename()
        fileselect.destroy()
        self.dialogs['rootsel'] = select_from_tarfile('heydude', path, self.pull_from_tar)
        
    def pull_from_tar(self, button, fileselect):
        info, tfile = fileselect.extract_file()
        template = tfile.name
        action = 'attach'
        if self.dialogs[action] is None:
            msg = 'attach to which package?'
            self.dialogs[action] = dialogs.CList(msg, name=action)
            lbox = self.dialogs[action]
            lbox.set_rows(self.traitpackage.packages())
            lbox.set_ok(self.insert_new_template_from_tar)
            lbox.set_cancel(self.destroy_dialog)
            lbox.set_data('tarmember', (info, tfile))
            
    def insert_new_template_from_tar(self, button):
        lbox = self.dialogs['attach']
        rows = lbox.get_selected_data()
        if len(rows) == 1:
            package = rows[0].package
            info, tfile = lbox.get_data('tarmember')
            self.destroy_dialog(lbox)
            self._insert_new_template(package, info.name, tfile, info)
            
        
    def _insert_new_template(self, package, template, fileobj, info):
        fileobj.seek(0)
        filename = self.template_filename(package, template)
        data = dict(owner=info.uname, grp_owner=info.gname,
                    mode=oct(info.mode), package=package,
                    template=template)
        self.traittemplate.insert_template(data, fileobj)
        self.set_template(package, template)
        self.reset_rows()
        
        
            
    def insert_new_template(self, package, template, path):
        newfile = readfile(path)
        filename = self.template_filename(package, template)
        makepaths(dirname(filename))
        writefile(filename, newfile)
        try:
            self.traittemplate.insert_template(dict(package=package, template=template),
                                               file(path))
        except OperationalError:
            dialogs.Message('template already exists')
        self.set_template(package, template)
        self.reset_rows()

    def load_template(self, path):
        template, package = get_file_path(path, self.suite_template_path())
        if template[-9:] == '.template':
            template = template[:-9]
            if template not in self.templates:
                try:
                    orig = self.find_original(template)
                    self.insert_new_template(package, template, path)
                except NoExistError:
                    dialogs.Message('%s not in extracted packages' %template)


    def _diff(self, template, path):
        current_template = self.template_filename(template)
        os.popen2('meld %s %s' %(current_template, path))

    def fileselect_ok(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        if action == 'new':
            template, package = get_file_path(path, self.trait_temp_path())
            if template not in self.templates:
                self.insert_new_template(package, template, path)
            else:
                dialogs.Message('template already exists')
        elif action == 'diff':
            pass
        elif action == 'load':
            self.load_template(path)

    def set_extracted(self, extracted):
        self.extracted = extracted
        for page in self.pages.values():
            page.extracted = extracted

    def _extract_packages(self):
        dialogs.Message('deprecated(for now)')
        if False:
            if self.extracted is None:
                packages = [p.package for p in self.traitpackage.packages()]
                path = self.trait_temp_path()
                self.set_extracted(True)
                packs = ',\n'.join(packages)
                message = 'extracted packages:\n %s into:\n%s'%(packs, path)
                dialogs.Message(message)
            else:
                dialogs.Message('already extracted')

    def extract_packages(self):
        self._extract_packages()
Example #27
0
class Toolbar(QToolBox):
    pass


class ListNotebook(QSplitter):
    def __init__(self, parent=None):
        QSplitter.__init__(self, parent, 'hsplit')
        self.setOrientation(QSplitter.Horizontal)
        self.listbox = QListView(self)
        #self.insertWidget(self.listbox)
        self.notebook = QTabBar(self)
        #self.addWidget(self.notebook)


cfg = PaellaConfig('database')
conn = PaellaConnection()
cursor = StatementCursor(conn)
app = QApplication(sys.argv)
#lv = QListView(None)
#lv.addColumn('section')
#for s in cursor.tables():
#    lv.insertItem(QListViewItem(lv, s))
#lv.show()
hello = QLabel('<font color=blue>%s <i>Qt!</i></font>' % str(cfg.section),
               None)
#lb = Listbox(None, cursor.select(table='gunny_templates'))
ln = ListNotebook()
ln.show()
ln.listbox.addColumn('table')
for t in cursor.tables():
Example #28
0
class ProfileGenWin(CommandBoxWindow):
    def __init__(self, conn, name='ProfileGenWin'):
        actions = ['create', 'copy', 'export', 'import']
        CommandBoxWindow.__init__(self, name=name)
        self.set_title(name)
        self.cfg = PaellaConfig()
        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.tbar.add_button('families', 'show all families', self.families_window)
        self.add_menu(self.suites, 'traitgen', self.show_traitgen)
        self.browser = ProfileBrowser(self.conn, self.suites)
        self.vbox.add(self.browser)
        self.set_size_request(400, 300)
        
    def ask_dialog(self, button, data):
        if not self.dialogs[data]:
            if data == 'create':
                self.dialogs[data] = dialogs.Entry('create profile', name='create')
                self.dialogs[data].set_ok(self.create_profile)
            elif data == 'copy':
                self.dialogs[data] = dialogs.CList('copy profile', name='copy')
                dialog = self.dialogs[data]
                dialog.set_rows(self.profiles.select(fields='profile', order='profile'))
                dialog.set_ok(self.src_profile_selected)
            elif data == 'export':
                pdb = PaellaDatabase(self.conn)
                profiles = pdb.profiles
            self.dialogs[data].set_cancel(self.destroy_dialog)

    def destroy_dialog(self, dying):
        name = dying.get_name()
        self.dialogs[name] = None
        dying.destroy()

    def create_profile(self, button):
        name = button.get_name() 
        debug(name)
        if name == 'create':
            profile = self.dialogs[name].get()
            self.destroy_dialog(self.dialogs[name])
            profiles = [p.profile for p in self.profiles.select()]
            if profile not in profiles:
                skel_profile = self.cfg.get('management_gui', 'template_profile')
                if skel_profile in profiles:
                    p = Profile(self.conn)
                    p.set_profile(skel_profile)
                    p.copy_profile(skel_profile, profile)
                else:
                    suite  = self.cfg.get('management_gui', 'default_profile_suite')
                    self.profiles.insert(data={'profile' : profile,
                                               'suite' : suite})
                self.browser.reset_rows()
            else:
                dialogs.Dialog('there was a problem')
                
    def src_profile_selected(self, button):
        row = get_single_row(self.dialogs['copy'], 'profile')
        
    
    def show_packages(self, button, data):
        PackagesWindow(self.conn, data)

    def show_traits(self, button, data):
        TraitsWindow(self.conn, data)

    def show_traitgen(self, button, data):
            TraitGenWin(self.conn, data)

    def families_window(self, button, data):
        rows = self.browser.family.family_rows()
        FamiliesWindow(rows)
Example #29
0
 def __init__(self, name='SystemTarWindow', **kw):
     FileSelection.__init__(self, **kw)
     self.cfg = PaellaConfig()
     self.dialogs = {}.fromkeys(['dbname', 'traits', 'templates'])
     self.tar = SystemTar(None, self.cfg)
     self.show()
Example #30
0
class TraitTemplateBrowser(ListNoteBook):
    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 modify_trait(self, menuitem, action):
        if action == 'hello':
            dialogs.Message('hello')
        elif action in ['import', 'update']:
            filesel = select_a_file(action, self.tarball_path + '/', self.select_trait_tarball)
        elif action in ['updatedir', 'exportdir', 'importdir']:
            filesel = select_a_file(action, self.tarball_path + '/', self.select_traitdir)
        elif action == 'export':
            try:
                trait = self.listbox.get_selected_data()[0].trait
                #self.pages[trait].extract_packages()
                self.select_export_path(trait)
            except IndexError:
                dialogs.Message('no trait selected')
            
        elif action == 'extract':
            try:
                trait = self.listbox.get_selected_data()[0].trait
                self.pages[trait].extract_packages()
            except IndexError:
                dialogs.Message('no trait selected')
        
    def reset_rows(self):
        if self.trait_selection == '_all_traits_':
            rows = self.traits.select(fields=['trait'])
            self.set_rows(rows)
        else:
            clause = Eq('profile', self.trait_selection)
            rows = self.cursor.select(fields=['trait'],
                                      table='profile_trait',
                                      clause=clause)
            ptraits = [x.trait for x in rows]
            traits = self._parents.get_traitset(ptraits)
            self.set_rows(list(traits), [self.trait_selection])
        self.set_row_select(self.trait_selected)

    def trait_selected(self, listbox, row, column, event):
        trait = listbox.get_selected_data()[0][0]
        self.select_trait(trait)
        
    def select_trait(self, trait):
        if trait not in self.pages:
            newpage = TemplateBrowser(self.conn, self.traits.suite, trait)
            self.append_page(newpage, trait)
        self.set_current_page(trait)
            
    def set_suite(self, suite):
        self.suite = suite
        self.traits.set_suite(suite)
        for page in self.pages:
            self.remove_page(page)
        self.reset_rows()

    def select_traitdir(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        if not isdir(path):
            path = dirname(path)
        if not isdir(path):
            raise Error, '%s not found' % path
        if action in ['updatedir', 'importdir']:
            if action == 'updatedir':
                tcmd = 'update'
            elif action == 'importdir':
                tcmd = 'import'
            traits = [t.trait for t in self.traits.select()]
            if tcmd == 'update':
                ls = [f for f in os.listdir(path) if f[-4:] == '.tar' and f[:-4] in traits]
                for f in ls:
                    self.importupdate(join(path, f), tcmd)
            elif tcmd == 'import':
                ls = [f for f in os.listdir(path) if f[-4:] == '.tar']
                traits = [t[:-4] for t in ls]
                while len(traits):
                    trait = traits[0]
                    try:
                        self.importupdate(join(path, trait + '.tar'), tcmd)
                    except UnbornError:
                        traits.append(trait)
                    del traits[0]
                    print 'processed', trait
                    
        elif action == 'exportdir':
            self.select_export_path('_all_traits_')
            
    def select_trait_tarball(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        self.importupdate(path, action)
        
    def importupdate(self, path, action):
        tarball = TraitTarFile(path)
        trait = tarball.get_trait()
        traitdb = Trait(self.conn, self.suite)
        if action == 'import':
            traitdb.insert_trait(path, suite=self.suite)
        for info in tarball:
            if info.name[:10] == 'templates/':
                #tarball.extract(info, template_path)
                pass
        self.reset_rows()

    def select_export_path(self, trait):
        filesel = select_a_file(trait, self.tarball_path + '/', self.export_path_selected)
        
    def export_path_selected(self, button, filesel):
        trait = filesel.get_data('action')
        path = dirname(filesel.get_filename())
        filesel.destroy()
        if trait == '_all_traits_':
            traits = [t.trait for t in self.traits.select()]
            for t in traits:
                self.export_trait(t, path)
        else:
            self.export_trait(trait, path)
        
        
    def export_trait(self, trait, path=None):
        if path is None:
            path = self.tarball_path
        tt = TraitTemplate(self.conn, self.suite)
        tt.set_trait(trait)
        backup_trait(self.conn, self.suite, trait, path)
        dialogs.Message('%s exported to %s' % (trait, path))
Example #31
0
class TraitTemplateBrowser(ListNoteBook):
    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 modify_trait(self, menuitem, action):
        if action == 'hello':
            dialogs.Message('hello')
        elif action in ['import', 'update']:
            filesel = select_a_file(action, self.tarball_path + '/',
                                    self.select_trait_tarball)
        elif action in ['updatedir', 'exportdir', 'importdir']:
            filesel = select_a_file(action, self.tarball_path + '/',
                                    self.select_traitdir)
        elif action == 'export':
            try:
                trait = self.listbox.get_selected_data()[0].trait
                #self.pages[trait].extract_packages()
                self.select_export_path(trait)
            except IndexError:
                dialogs.Message('no trait selected')

        elif action == 'extract':
            try:
                trait = self.listbox.get_selected_data()[0].trait
                self.pages[trait].extract_packages()
            except IndexError:
                dialogs.Message('no trait selected')

    def reset_rows(self):
        if self.trait_selection == '_all_traits_':
            rows = self.traits.select(fields=['trait'])
            self.set_rows(rows)
        else:
            clause = Eq('profile', self.trait_selection)
            rows = self.cursor.select(fields=['trait'],
                                      table='profile_trait',
                                      clause=clause)
            ptraits = [x.trait for x in rows]
            traits = self._parents.get_traitset(ptraits)
            self.set_rows(list(traits), [self.trait_selection])
        self.set_row_select(self.trait_selected)

    def trait_selected(self, listbox, row, column, event):
        trait = listbox.get_selected_data()[0][0]
        self.select_trait(trait)

    def select_trait(self, trait):
        if trait not in self.pages:
            newpage = TemplateBrowser(self.conn, self.traits.suite, trait)
            self.append_page(newpage, trait)
        self.set_current_page(trait)

    def set_suite(self, suite):
        self.suite = suite
        self.traits.set_suite(suite)
        for page in self.pages:
            self.remove_page(page)
        self.reset_rows()

    def select_traitdir(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        if not isdir(path):
            path = dirname(path)
        if not isdir(path):
            raise Error, '%s not found' % path
        if action in ['updatedir', 'importdir']:
            if action == 'updatedir':
                tcmd = 'update'
            elif action == 'importdir':
                tcmd = 'import'
            traits = [t.trait for t in self.traits.select()]
            if tcmd == 'update':
                ls = [
                    f for f in os.listdir(path)
                    if f[-4:] == '.tar' and f[:-4] in traits
                ]
                for f in ls:
                    self.importupdate(join(path, f), tcmd)
            elif tcmd == 'import':
                ls = [f for f in os.listdir(path) if f[-4:] == '.tar']
                traits = [t[:-4] for t in ls]
                while len(traits):
                    trait = traits[0]
                    try:
                        self.importupdate(join(path, trait + '.tar'), tcmd)
                    except UnbornError:
                        traits.append(trait)
                    del traits[0]
                    print 'processed', trait

        elif action == 'exportdir':
            self.select_export_path('_all_traits_')

    def select_trait_tarball(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        self.importupdate(path, action)

    def importupdate(self, path, action):
        tarball = TraitTarFile(path)
        trait = tarball.get_trait()
        traitdb = Trait(self.conn, self.suite)
        if action == 'import':
            traitdb.insert_trait(path, suite=self.suite)
        for info in tarball:
            if info.name[:10] == 'templates/':
                #tarball.extract(info, template_path)
                pass
        self.reset_rows()

    def select_export_path(self, trait):
        filesel = select_a_file(trait, self.tarball_path + '/',
                                self.export_path_selected)

    def export_path_selected(self, button, filesel):
        trait = filesel.get_data('action')
        path = dirname(filesel.get_filename())
        filesel.destroy()
        if trait == '_all_traits_':
            traits = [t.trait for t in self.traits.select()]
            for t in traits:
                self.export_trait(t, path)
        else:
            self.export_trait(trait, path)

    def export_trait(self, trait, path=None):
        if path is None:
            path = self.tarball_path
        tt = TraitTemplate(self.conn, self.suite)
        tt.set_trait(trait)
        backup_trait(self.conn, self.suite, trait, path)
        dialogs.Message('%s exported to %s' % (trait, path))
Example #32
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()
Example #33
0
class TemplateBrowser(ListNoteBook):
    def __init__(self, conn, suite, trait):
        self.menu = make_menu(TEMPL_CMDS, self.template_command)
        self.conn = conn
        self.current_trait = trait
        self.traittemplate = TraitTemplate(self.conn, suite)
        self.traittemplate.set_trait(self.current_trait)
        self.traitpackage = TraitPackage(self.conn, suite)
        self.traitpackage.set_trait(self.current_trait)
        self.current_template = None
        self.cfg = PaellaConfig()
        self.template_path = '/nowhere'
        self._tmp_path = '/nowhere'
        self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path')
        ListNoteBook.__init__(self)
        self.set_suite(suite)
        self.extracted = None
        self.reset_rows()
        self.dialogs = {}.fromkeys(['attach', 'rootsel'])

    def reset_rows(self):
        rows = self.traittemplate.templates(fields=['template', 'package'])
        self.set_rows(rows)
        self.set_row_select(self.template_selected)
        self.templates = [r.template for r in rows]

    def template_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.set_template(row.package, row.template)

    def set_template(self, package, template):
        self.current_package = package
        self.current_template = template
        if template not in self.pages:
            trait = self.current_trait
            nbook = TemplateNotebook(self.conn, self.cfg, self.suite, trait,
                                     package, template, self.extracted)
            self.append_page(nbook, template)
        else:
            self.set_current_page(template)

    def template_filename(self, package, template):
        tpath = join(self.template_path, self.suite, self.current_trait)
        return join(tpath, package, template + '.template')

    def suite_template_path(self, filesel=False):
        path = join(self.template_path, self.suite)
        if filesel:
            path += '/'
        return path

    def trait_temp_path(self, filesel=False):
        path = join(self._tmp_path, self.suite, self.current_trait)
        if filesel:
            path += '/'
        return path

    def set_suite(self, suite):
        self.suite = suite

    def save_template(self):
        try:
            template = self.get_selected_data()[0].template
            self.pages[template].save_template()
        except IndexError:
            dialogs.Message('a template must be selected')

    def edit_template(self):
        try:
            template = self.get_selected_data()[0].template
            self.pages[template].edit_template()
        except IndexError:
            dialogs.Message('a template must be selected')

    def template_command(self, meuitem, command):
        if command in ['new']:
            path = self.trait_temp_path(filesel=True)
            select_a_file('new', path, self.fileselect_ok)
        elif command == 'diff':
            path = self.suite_template_path(filesel=True)
            select_a_file('load', path, self.fileselect_ok)
        elif command == 'save':
            self.save_template()
        elif command == 'load':
            path = self.suite_template_path(filesel=True)
            select_a_file('load', path, self.fileselect_ok)
        elif command == 'done':
            try:
                template = self.get_selected_data()[0].template
                self.remove_page(template)
            except IndexError:
                pass
        elif command == 'drop':
            print 'need to drop template'
            rows = self.get_selected_data()
            if len(rows):
                row = rows[0]
                self.traittemplate.drop_template(row.package, row.template)
                self.remove_page(row.template)
                self.reset_rows()
            else:
                dialogs.Message('a template must be selected')
        elif command == 'root':
            if self.dialogs['rootsel'] is None:
                path = self.tarball_path + '/'
                select_a_file('root', path, self.tarball_selected)
        elif command == 'edit':
            self.edit_template()

    def tarball_selected(self, button, fileselect):
        path = fileselect.get_filename()
        fileselect.destroy()
        self.dialogs['rootsel'] = select_from_tarfile('heydude', path,
                                                      self.pull_from_tar)

    def pull_from_tar(self, button, fileselect):
        info, tfile = fileselect.extract_file()
        template = tfile.name
        action = 'attach'
        if self.dialogs[action] is None:
            msg = 'attach to which package?'
            self.dialogs[action] = dialogs.CList(msg, name=action)
            lbox = self.dialogs[action]
            lbox.set_rows(self.traitpackage.packages())
            lbox.set_ok(self.insert_new_template_from_tar)
            lbox.set_cancel(self.destroy_dialog)
            lbox.set_data('tarmember', (info, tfile))

    def insert_new_template_from_tar(self, button):
        lbox = self.dialogs['attach']
        rows = lbox.get_selected_data()
        if len(rows) == 1:
            package = rows[0].package
            info, tfile = lbox.get_data('tarmember')
            self.destroy_dialog(lbox)
            self._insert_new_template(package, info.name, tfile, info)

    def _insert_new_template(self, package, template, fileobj, info):
        fileobj.seek(0)
        filename = self.template_filename(package, template)
        data = dict(owner=info.uname,
                    grp_owner=info.gname,
                    mode=oct(info.mode),
                    package=package,
                    template=template)
        self.traittemplate.insert_template(data, fileobj)
        self.set_template(package, template)
        self.reset_rows()

    def insert_new_template(self, package, template, path):
        newfile = readfile(path)
        filename = self.template_filename(package, template)
        makepaths(dirname(filename))
        writefile(filename, newfile)
        try:
            self.traittemplate.insert_template(
                dict(package=package, template=template), file(path))
        except OperationalError:
            dialogs.Message('template already exists')
        self.set_template(package, template)
        self.reset_rows()

    def load_template(self, path):
        template, package = get_file_path(path, self.suite_template_path())
        if template[-9:] == '.template':
            template = template[:-9]
            if template not in self.templates:
                try:
                    orig = self.find_original(template)
                    self.insert_new_template(package, template, path)
                except NoExistError:
                    dialogs.Message('%s not in extracted packages' % template)

    def _diff(self, template, path):
        current_template = self.template_filename(template)
        os.popen2('meld %s %s' % (current_template, path))

    def fileselect_ok(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        if action == 'new':
            template, package = get_file_path(path, self.trait_temp_path())
            if template not in self.templates:
                self.insert_new_template(package, template, path)
            else:
                dialogs.Message('template already exists')
        elif action == 'diff':
            pass
        elif action == 'load':
            self.load_template(path)

    def set_extracted(self, extracted):
        self.extracted = extracted
        for page in self.pages.values():
            page.extracted = extracted

    def _extract_packages(self):
        dialogs.Message('deprecated(for now)')
        if False:
            if self.extracted is None:
                packages = [p.package for p in self.traitpackage.packages()]
                path = self.trait_temp_path()
                self.set_extracted(True)
                packs = ',\n'.join(packages)
                message = 'extracted packages:\n %s into:\n%s' % (packs, path)
                dialogs.Message(message)
            else:
                dialogs.Message('already extracted')

    def extract_packages(self):
        self._extract_packages()
Example #34
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)
            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)
Example #35
0
class ProfileGenWin(CommandBoxWindow):
    def __init__(self, conn, name='ProfileGenWin'):
        actions = ['create', 'copy', 'export', 'import']
        CommandBoxWindow.__init__(self, name=name)
        self.set_title(name)
        self.cfg = PaellaConfig()
        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.tbar.add_button('families', 'show all families',
                             self.families_window)
        self.add_menu(self.suites, 'traitgen', self.show_traitgen)
        self.browser = ProfileBrowser(self.conn, self.suites)
        self.vbox.add(self.browser)
        self.set_size_request(400, 300)

    def ask_dialog(self, button, data):
        if not self.dialogs[data]:
            if data == 'create':
                self.dialogs[data] = dialogs.Entry('create profile',
                                                   name='create')
                self.dialogs[data].set_ok(self.create_profile)
            elif data == 'copy':
                self.dialogs[data] = dialogs.CList('copy profile', name='copy')
                dialog = self.dialogs[data]
                dialog.set_rows(
                    self.profiles.select(fields='profile', order='profile'))
                dialog.set_ok(self.src_profile_selected)
            elif data == 'export':
                pdb = PaellaDatabase(self.conn)
                profiles = pdb.profiles
            self.dialogs[data].set_cancel(self.destroy_dialog)

    def destroy_dialog(self, dying):
        name = dying.get_name()
        self.dialogs[name] = None
        dying.destroy()

    def create_profile(self, button):
        name = button.get_name()
        debug(name)
        if name == 'create':
            profile = self.dialogs[name].get()
            self.destroy_dialog(self.dialogs[name])
            profiles = [p.profile for p in self.profiles.select()]
            if profile not in profiles:
                skel_profile = self.cfg.get('management_gui',
                                            'template_profile')
                if skel_profile in profiles:
                    p = Profile(self.conn)
                    p.set_profile(skel_profile)
                    p.copy_profile(skel_profile, profile)
                else:
                    suite = self.cfg.get('management_gui',
                                         'default_profile_suite')
                    self.profiles.insert(data={
                        'profile': profile,
                        'suite': suite
                    })
                self.browser.reset_rows()
            else:
                dialogs.Dialog('there was a problem')

    def src_profile_selected(self, button):
        row = get_single_row(self.dialogs['copy'], 'profile')

    def show_packages(self, button, data):
        PackagesWindow(self.conn, data)

    def show_traits(self, button, data):
        TraitsWindow(self.conn, data)

    def show_traitgen(self, button, data):
        TraitGenWin(self.conn, data)

    def families_window(self, button, data):
        rows = self.browser.family.family_rows()
        FamiliesWindow(rows)
Example #36
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)
            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)
Example #37
0
 def __init__(self, conn):
     object.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = conn
     self.import_dir = self.cfg.get('database', 'import_path')
     self.export_dir = self.cfg.get('database', 'export_path')
Example #38
0
from paella.base.util import ujoin, makepaths
from paella.db.midlevel import StatementCursor, TableDict
from paella.sqlgen.statement import Statement
from paella.sqlgen.select import SimpleClause
from paella.sqlgen.clause import one_many, Eq, In, NotIn

from paella.profile.base import PaellaConnection, PaellaConfig
from paella.profile.trait import TraitPackage, TraitParent
from paella.profile.trait import Trait

def substring(field, substr):
    return 'substring(%s from 1 for %s)' %(field, len(substr))
def substring_clause(section):
    return "%s = '%s'" %(substring('section', section), section)

cfg = PaellaConfig('management_gui')
suites = [s.strip() for s in cfg['management_suites'].split(',')]
TARGETS = FlavoredTargets(23, ['trait', 'package'],
                          suites)
print TARGETS.flavors

class DragListWindow(dialogs.CList):
    def __init__(self, message, packer, rows, targets,
                      name='DragListWindow'):
        dialogs.CList.__init__(self, message, name=name, dnd=self.drag_rows,
                               targets=targets)
        self.set_rows(rows)
        self.__packer__ = packer
        self.set_select_mode('multi')

    def drag_rows(self, listbox, context, selection, targettype, time):
Example #39
0
class MachineDatabaseElement(Element):
    def __init__(self, conn):
        Element.__init__(self, 'machine_database')
        self.conn = conn
        self.filesystems = FilesystemsElement(conn)
        self.disks = DisksElement(conn)
        self.mounts = MountsElement(conn)
        self.mtypes = MachineTypesElement(conn)
        self.kernels = KernelsElement(conn)
        self.machines = MachinesElement(conn)

        for e in [
                self.machines, self.mtypes, self.disks, self.mounts,
                self.filesystems, self.kernels
        ]:
            self.appendChild(e)


if __name__ == '__main__':
    from paella.profile.base import PaellaConfig, PaellaConnection
    cfg = PaellaConfig()
    conn = PaellaConnection(cfg)
    #f = FilesystemElement('newfs', 'home', 5)
    filesystems = FilesystemsElement(conn)
    disks = DisksElement(conn)
    mounts = MountsElement(conn)
    mtypes = MachineTypesElement(conn)
    kernels = KernelsElement(conn)
    machines = MachinesElement(conn)
    md = MachineDatabaseElement(conn)
Example #40
0
class Manager(CommandBoxWindow):
    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()

    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)
            elif name == 'traitmanager':
                self.workspace['traitmanager'] = TraitManagerWin(self.conn)
            elif name == 'machines':
                self.workspace['machines'] = MainMachineWin(self.conn)

            else:
                raise Error, 'bad edit_command'

    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()
Example #41
0
class Toolbar(QToolBox):
    pass


class ListNotebook(QSplitter):
    def __init__(self, parent=None):
        QSplitter.__init__(self, parent, 'hsplit')
        self.setOrientation(QSplitter.Horizontal)
        self.listbox = QListView(self)
        #self.insertWidget(self.listbox)
        self.notebook = QTabBar(self)
        #self.addWidget(self.notebook)
        

cfg = PaellaConfig('database')
conn = PaellaConnection()
cursor = StatementCursor(conn)
app = QApplication(sys.argv)
#lv = QListView(None)
#lv.addColumn('section')
#for s in cursor.tables():
#    lv.insertItem(QListViewItem(lv, s))
#lv.show()
hello = QLabel('<font color=blue>%s <i>Qt!</i></font>' % str(cfg.section), None)
#lb = Listbox(None, cursor.select(table='gunny_templates'))
ln = ListNotebook()
ln.show()
ln.listbox.addColumn('table')
for t in cursor.tables():
    ln.listbox.insertItem(QListViewItem(ln.listbox, t))
Example #42
0
from useless.gtk.middle import ListNoteBook, FieldEntryVbox
from useless.gtk.middle import RecordBox
from useless.gtk.windows import MenuWindow
from useless.gtk.helpers import populate_menu, make_menu
from useless.gtk import dialogs

from useless.db.midlevel import StatementCursor, Environment

from paella.profile.base import PaellaConnection, TraitEnvironment
from paella.profile.base import get_suite, PaellaConfig
from paella.profile.trait import TraitParent
from paella.profile.profile import ProfileEnvironment

from gtk import TRUE, FALSE, mainquit, mainloop

config = PaellaConfig()


class _EnvironmentEditor(ListNoteBook):
    def __init__(self, conn, name='_EnvironmentEditor'):
        ListNoteBook.__init__(self, name=name)
        self.conn = conn
        self.main = StatementCursor(self.conn, name=name)
        self.append_page(RecordBox({}), 'Environment')
        self.menu = SimpleMenu()
        self.delimiters = DELIMITERS['out-arrows']
        self.dialogs = {}.fromkeys(['create', 'remove'])

    def box_pressed(self, widget, event=None):
        if right_click_pressed(event):
            self.menu.popup(None, None, None, event.button, event.time)