Esempio n. 1
0
 def __init__(self, conn):
     self.conn = conn
     self.cfg = PaellaConfig()
     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()
Esempio n. 2
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
Esempio n. 3
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. 4
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)
        mh = MachineHandler(self.conn)
        mh.export_machine_database(path)

    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, self.cfg)
        pp.create(dbpath)
        mh = MachineHandler(self.conn)
        #md = mh.parse_xmlfile(mdbpath)
        mh.restore_machine_database(path)
Esempio n. 5
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, self.cfg)
        pp.create(dbpath)
        mh = MachineHandler(self.conn)
        md = mh.parse_xmlfile(mdbpath)
        mh.insert_parsed_element(md)    
Esempio n. 6
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'])
Esempio n. 7
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)
Esempio n. 8
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
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 __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'])
Esempio n. 11
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)
Esempio n. 12
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()
Esempio n. 13
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. 14
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')
Esempio n. 15
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 in ['drop', 'real_templates', 'other_templates']:
            rows = self.get_selected_data()
            row = None
            print row, rows, len(rows)
            if len(rows):
                row = rows[0]
            else:
                dialogs.Message('a template must be selected')
                print row, rows
            if row:
                package, template = row.package, row.template
                print row, 'ifrow'
                if command == 'drop':
                    self.traittemplate.drop_template(package, template)
                    self.remove_page(template)
                elif command == 'real_templates':
                    self.traittemplate.prefix_template(package, template, type_='real')
                    print 'make it real_templates'
                elif command == 'other_templates':
                    self.traittemplate.prefix_template(package, template, type_='other')
                    print 'make it other_templates'
                self.reset_rows()
        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()
Esempio n. 16
0
class ClientManager(object):
    def __init__(self, conn):
        self.conn = conn
        self.cfg = PaellaConfig()
        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()

    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):
        machines = self.client_cfg.get_list('machines', client)
        return machines
        
    def export_client(self, client):
        cpath, ppath, fpath, tpath = self._cpaths_(client)
        makepaths(cpath)
        profiles, families, traits = self._client_schema(client) 
        machines = self._client_mdata(client)
        if not machines:
            machines = None
        element = ClientMachineDatabaseElement(self.conn, 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:
            importer = PaellaImporter(self.conn)
            importer.import_all_profiles(ppath)
        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)
        machines = self._client_mdata(client)
        cursor = StatementCursor(self.conn)
        for machine in machines:
            cursor.execute("select * from delete_machine('%s')" % machine)
        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. 17
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))
Esempio n. 18
0
from useless.sqlgen.clause import one_many, Eq, In, NotIn

from paella.db import PaellaConnection, PaellaConfig

from paella.db.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')
Esempio n. 19
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. 20
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))
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 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')
Esempio n. 24
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 in ['drop', 'real_templates', 'other_templates']:
            rows = self.get_selected_data()
            row = None
            print row, rows, len(rows)
            if len(rows):
                row = rows[0]
            else:
                dialogs.Message('a template must be selected')
                print row, rows
            if row:
                package, template = row.package, row.template
                print row, 'ifrow'
                if command == 'drop':
                    self.traittemplate.drop_template(package, template)
                    self.remove_page(template)
                elif command == 'real_templates':
                    self.traittemplate.prefix_template(package,
                                                       template,
                                                       type_='real')
                    print 'make it real_templates'
                elif command == 'other_templates':
                    self.traittemplate.prefix_template(package,
                                                       template,
                                                       type_='other')
                    print 'make it other_templates'
                self.reset_rows()
        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()
Esempio n. 25
0
            dialog = dialogs.CList('hi there', name='select profile')
            profiles = self.main.select(fields=['profile'],
                                        table='profiles',
                                        clause=Eq('suite', self.suite))
            dialog.set_rows(profiles)
            dialog.set_ok(self.profile_dialog_selected)
            dialog.set_cancel(self.destroy_dialog)
            self.dialogs['select profile'] = dialog

    def profile_dialog_selected(self, *args):
        profile = self.dialogs['select profile'].get_selected_data()[0][0]
        self.destroy_dialog(self.dialogs['select profile'])
        self.browser.trait_selection = profile
        self.browser.reset_rows()


if __name__ == '__main__':
    from useless.db.lowlevel import QuickConn
    g = PaellaConfig()
    conn = QuickConn(g)
    rconn = RepositoryConnection()
    #tb  = TemplateBrowser(conn)
    #tb.set_suite('woody')

    #win = MenuWindow()
    #win.vbox.add(tb)
    win = TemplateManager(conn, rconn)
    win.connect('destroy', mainquit)
    mainloop()
    pass
Esempio n. 26
0
 def __init__(self, conn):
     self.conn = conn
     self.cfg = PaellaConfig()
     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()