Exemple #1
0
class ProfileBrowser(ListNoteBook, HasDialogs):
    def __init__(self, conn, suites, name='ProfileBrowser'):
        self.menu = self.__make_mainmenu_(suites)
        ListNoteBook.__init__(self, name=name)
        self.conn = conn
        self.profiles = Profile(self.conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.family = Family(self.conn)
        self.pfamily = StatementCursor(self.conn)
        self.pfamily.set_table('profile_family')
        self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
        self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
        self.family_menu = make_menu(['drop'], self.family_command)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
        self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
        self.append_page(ScrollCList(rcmenu=self.family_menu), 'families')
        self.dialogs = {}.fromkeys(['order'])

    def __make_mainmenu_(self, suites):
        suite_commands = ['change to %s' % suite for suite in suites]
        profile_commands = ['drop', 'set defaults', 'append defaults']
        commands = suite_commands + profile_commands
        return make_menu(commands, self.profile_command)

    def reset_rows(self):
        self.set_rows(
            self.profiles.select(fields=['profile', 'suite'], order='profile'))
        self.set_row_select(self.profile_selected)

    def profile_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.current = row
        self.select_profile(self.current.profile)

    def select_profile(self, profile):
        self.variables = ProfileEnvironment(self.conn, profile)
        self.profiletrait.set_profile(profile)
        self.__set_pages(profile)

    def __set_pages(self, profile):
        pages = dict(self.pages)
        #set traits for profile
        pages['traits'].set_rows(self.profiletrait.trait_rows())
        pages['traits'].set_select_mode('multi')
        clause = Eq('profile', self.current.profile)
        cursor = self.variables.env.cursor
        pages['variables'].set_rows(cursor.select(clause=clause), ['trait'])
        pages['variables'].set_select_mode('multi')
        pfrows = self.pfamily.select(fields=['family'], clause=clause)
        pages['families'].set_rows(pfrows)
        pages['families'].set_select_mode('multi')
        self.__set_droptargets__(pages)

    def __set_droptargets__(self, pages):
        set_receive_targets(pages['traits'].listbox, self.drop_trait,
                            TARGETS.get('trait', self.current.suite))
        set_receive_targets(pages['families'].listbox, self.drop_families,
                            FTargets.get('family', 'flavor'))

    def trait_command(self, menuitem, action):
        traits = self._get_listbox('traits', 'trait')
        if action == 'drop':
            clause = In('trait', traits) & Eq('profile', self.current.profile)
            self.profiletrait.cmd.delete(clause=clause)
            self.__set_pages(self.current.profile)
        elif action == 'order':
            if not self.dialogs['order']:
                self.dialogs['order'] = dialogs.Entry('enter order',
                                                      name='order')
                self.dialogs['order'].set_ok(self.set_order)
                self.dialogs['order'].set_cancel(self.destroy_dialog)

    def variable_command(self, menuitem, action):
        rows = self.pages['variables'].get_selected_data()
        cursor = self.variables.env.cursor
        if action == 'drop':
            for row in rows:
                clause = Eq('profile', self.current.profile) & Eq(
                    'trait', row.trait)
                clause &= Eq('name', row.name)
                cursor.delete(clause=clause)
        elif action == 'edit':
            self.edit_profilevars()

    def family_command(self, menuitem, action):
        print action
        families = [x[0] for x in self.pages['families'].get_selected_data()]
        if action == 'drop':
            clause = Eq('profile', self.current.profile) & In(
                'family', families)
            self.pfamily.delete(clause=clause)

    def edit_profilevars(self):
        config = ProfileVariablesConfig(self.conn, self.current.profile)
        newconfig = config.edit()
        config.update(newconfig)
        self.select_profile(self.current.profile)

    def set_order(self, button):
        dialog = self.dialogs['order']
        ord = dialog.get()
        rows = self.pages['traits'].get_selected_data()
        pclause = Eq('profile', self.current.profile)
        for row in rows:
            clause = pclause & Eq('trait', row.trait)
            self.profiletrait.update(data=dict(ord=ord), clause=clause)

    def drop_trait(self, listbox, context, x, y, selection, targettype, time):
        traits = keysplitter(selection)
        self.profiletrait.insert_traits(traits)
        self.__set_pages(self.current.profile)

    def drop_families(self, listbox, context, x, y, selection, targettype,
                      time):
        families = keysplitter(selection)
        clause = Eq('profile', self.current.profile)
        data = dict(profile=self.current.profile)
        current = [x.family for x in self.pfamily.select(clause=clause)]
        for f in families:
            if f not in current:
                data['family'] = f
                self.pfamily.insert(data=data)
        self.__set_pages(self.current.profile)

    def _get_listbox(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def profile_command(self, menu, command):
        if command[:10] == 'change to ':
            self.change_suite(command[10:])
        elif command == 'drop':
            self.profiletrait.drop_profile(self.current.profile)
            self.profiles.drop_profile(self.current.profile)
            self.current = None
            self.reset_rows()
        elif command == 'set defaults':
            self.variables.set_defaults()
        elif command == 'append defaults':
            self.variables.append_defaults()
        else:
            raise Error, 'bad command %s' % command

    def change_suite(self, suite):
        clause = Eq('profile', self.current.profile)
        self.profiles.update(data={'suite': suite}, clause=clause)
        print 'changing suite to ', suite
        self.current_suite = suite
        self.reset_rows()
class ProfileBrowser(ListNoteBook, HasDialogs):
    def __init__(self, conn, suites, name='ProfileBrowser'):
        self.menu = self.__make_mainmenu_(suites)
        ListNoteBook.__init__(self, name=name)
        self.conn = conn
        self.profiles = Profiles(self.conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
        self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
        self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
        self.dialogs = {}.fromkeys(['order'])
        
    def __make_mainmenu_(self, suites):
        suite_commands = ['change to %s' %suite for suite in suites]
        profile_commands = ['drop', 'set defaults', 'append defaults']
        commands = suite_commands + profile_commands
        return make_menu(commands, self.profile_command)

    def reset_rows(self):
        self.set_rows(self.profiles.select(fields=['profile', 'suite'], order='profile'))
        self.set_row_select(self.profile_selected)

    def profile_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.current = row
        self.select_profile(self.current.profile)

    def select_profile(self, profile):
        self.variables = ProfileEnvironment(self.conn, profile)
        self.profiletrait.set_profile(profile)
        self.__set_pages(profile)

    def __set_pages(self, profile):
        pages = dict(self.pages)
        #set traits for profile
        pages['traits'].set_rows(self.profiletrait.trait_rows())
        pages['traits'].set_select_mode('multi')
        self.__set_droptargets__(pages)
        clause = Eq('profile', self.current.profile)
        cursor = self.variables.env.cursor
        pages['variables'].set_rows(cursor.select(clause=clause), ['trait'])
        pages['variables'].set_select_mode('multi')

    def __set_droptargets__(self, pages):
        set_receive_targets(pages['traits'].listbox,
                            self.drop_trait, TARGETS.get('trait', self.current.suite))
                    

    def trait_command(self, menuitem, action):
        traits = self._get_listbox('traits', 'trait')
        if action == 'drop':
            clause = In('trait', traits) & Eq('profile', self.current.profile)
            self.profiletrait.cmd.delete(clause=clause)
            self.__set_pages(self.current.profile)
        elif action == 'order':
            if not self.dialogs['order']:
                self.dialogs['order'] = dialogs.Entry('enter order', name='order')
                self.dialogs['order'].set_ok(self.set_order)
                self.dialogs['order'].set_cancel(self.destroy_dialog)


    def variable_command(self, menuitem, action):
        rows = self.pages['variables'].get_selected_data()
        cursor = self.variables.env.cursor
        if action == 'drop':
            for row in rows:
                clause = Eq('profile', self.current.profile) & Eq('trait', row.trait)
                clause &= Eq('name', row.name)
                cursor.delete(clause=clause)
        elif action == 'edit':
            self.edit_profilevars()

    def edit_profilevars(self):
        config = ProfileVariablesConfig(self.conn, self.current.profile)
        tmp, path = tempfile.mkstemp('variable', 'paella')
        tmp = file(path, 'w')
        config.write(tmp)
        tmp.close()
        os.system('$EDITOR %s' %path)
        tmp = file(path, 'r')
        newconfig = RawConfigParser()
        newconfig.readfp(tmp)
        tmp.close()
        os.remove(path)
        cursor = self.variables.env.cursor
        pclause = Eq('profile', self.current.profile)
        for trait in config.sections():
            tclause = pclause & Eq('trait', trait)
            if not newconfig.has_section(trait):
                cursor.delete(clause=tclause)
            else:
                for name, value in newconfig.items(trait):
                    nclause = tclause & Eq('name', name)
                    if config.has_option(trait, name):
                        if value != config.get(trait, name):
                            cursor.update(data={'value' : value}, clause=nclause)
                    else:
                        idata = { 'profile' : self.current.profile,
                                  'trait' : trait,
                                  'name' : name,
                                  'value' : value}
                        cursor.insert(data=idata)
                    if config.has_section(trait):
                        for name, value in config.items(trait):
                            if not newconfig.has_option(trait, name):
                                cursor.delete(clause=tclause & Eq('name', name))
        self.select_profile(self.current.profile)
        
                            
    def set_order(self, button):
        dialog = self.dialogs['order']
        ord = dialog.get()
        rows = self.pages['traits'].get_selected_data()
        pclause = Eq('profile', self.current.profile)
        for row in rows:
            clause = pclause & Eq('trait', row.trait)
            self.profiletrait.update(data=dict(ord=ord), clause=clause)
        
    def drop_trait(self, listbox, context, x, y, selection,
                   targettype, time):
        traits = keysplitter(selection)
        self.profiletrait.insert_traits(traits)
        self.__set_pages(self.current.profile)

    def _get_listbox(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def profile_command(self, menu, command):
        if command[:10] == 'change to ':
            self.change_suite(command[10:])
        elif command == 'drop':
            self.profiletrait.drop_profile(self.current.profile)
            self.profiles.drop_profile(self.current.profile)
            self.current = None
            self.reset_rows()
        elif command == 'set defaults':
            self.variables.set_defaults()
        elif command == 'append defaults':
            self.variables.append_defaults()
        else:
            raise Error, 'bad command %s' %command
            
    def change_suite(self, suite):
        clause = Eq('profile', self.current.profile)
        self.profiles.update(data={'suite' : suite}, clause=clause)        
        print 'changing suite to ', suite
        self.current_suite = suite
        self.reset_rows()
Exemple #3
0
class ProfileBrowser(ListNoteBook, HasDialogs):
    def __init__(self, conn, suites, name='ProfileBrowser'):
        self.menu = self.__make_mainmenu_(suites)
        ListNoteBook.__init__(self, name=name)
        self.conn = conn
        self.profiles = Profiles(self.conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
        self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
        self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
        self.dialogs = {}.fromkeys(['order'])

    def __make_mainmenu_(self, suites):
        suite_commands = ['change to %s' % suite for suite in suites]
        profile_commands = ['drop', 'set defaults', 'append defaults']
        commands = suite_commands + profile_commands
        return make_menu(commands, self.profile_command)

    def reset_rows(self):
        self.set_rows(
            self.profiles.select(fields=['profile', 'suite'], order='profile'))
        self.set_row_select(self.profile_selected)

    def profile_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.current = row
        self.select_profile(self.current.profile)

    def select_profile(self, profile):
        self.variables = ProfileEnvironment(self.conn, profile)
        self.profiletrait.set_profile(profile)
        self.__set_pages(profile)

    def __set_pages(self, profile):
        pages = dict(self.pages)
        #set traits for profile
        pages['traits'].set_rows(self.profiletrait.trait_rows())
        pages['traits'].set_select_mode('multi')
        self.__set_droptargets__(pages)
        clause = Eq('profile', self.current.profile)
        cursor = self.variables.env.cursor
        pages['variables'].set_rows(cursor.select(clause=clause), ['trait'])
        pages['variables'].set_select_mode('multi')

    def __set_droptargets__(self, pages):
        set_receive_targets(pages['traits'].listbox, self.drop_trait,
                            TARGETS.get('trait', self.current.suite))

    def trait_command(self, menuitem, action):
        traits = self._get_listbox('traits', 'trait')
        if action == 'drop':
            clause = In('trait', traits) & Eq('profile', self.current.profile)
            self.profiletrait.cmd.delete(clause=clause)
            self.__set_pages(self.current.profile)
        elif action == 'order':
            if not self.dialogs['order']:
                self.dialogs['order'] = dialogs.Entry('enter order',
                                                      name='order')
                self.dialogs['order'].set_ok(self.set_order)
                self.dialogs['order'].set_cancel(self.destroy_dialog)

    def variable_command(self, menuitem, action):
        rows = self.pages['variables'].get_selected_data()
        cursor = self.variables.env.cursor
        if action == 'drop':
            for row in rows:
                clause = Eq('profile', self.current.profile) & Eq(
                    'trait', row.trait)
                clause &= Eq('name', row.name)
                cursor.delete(clause=clause)
        elif action == 'edit':
            self.edit_profilevars()

    def edit_profilevars(self):
        config = ProfileVariablesConfig(self.conn, self.current.profile)
        tmp, path = tempfile.mkstemp('variable', 'paella')
        tmp = file(path, 'w')
        config.write(tmp)
        tmp.close()
        os.system('$EDITOR %s' % path)
        tmp = file(path, 'r')
        newconfig = RawConfigParser()
        newconfig.readfp(tmp)
        tmp.close()
        os.remove(path)
        cursor = self.variables.env.cursor
        pclause = Eq('profile', self.current.profile)
        for trait in config.sections():
            tclause = pclause & Eq('trait', trait)
            if not newconfig.has_section(trait):
                cursor.delete(clause=tclause)
            else:
                for name, value in newconfig.items(trait):
                    nclause = tclause & Eq('name', name)
                    if config.has_option(trait, name):
                        if value != config.get(trait, name):
                            cursor.update(data={'value': value},
                                          clause=nclause)
                    else:
                        idata = {
                            'profile': self.current.profile,
                            'trait': trait,
                            'name': name,
                            'value': value
                        }
                        cursor.insert(data=idata)
                    if config.has_section(trait):
                        for name, value in config.items(trait):
                            if not newconfig.has_option(trait, name):
                                cursor.delete(clause=tclause
                                              & Eq('name', name))
        self.select_profile(self.current.profile)

    def set_order(self, button):
        dialog = self.dialogs['order']
        ord = dialog.get()
        rows = self.pages['traits'].get_selected_data()
        pclause = Eq('profile', self.current.profile)
        for row in rows:
            clause = pclause & Eq('trait', row.trait)
            self.profiletrait.update(data=dict(ord=ord), clause=clause)

    def drop_trait(self, listbox, context, x, y, selection, targettype, time):
        traits = keysplitter(selection)
        self.profiletrait.insert_traits(traits)
        self.__set_pages(self.current.profile)

    def _get_listbox(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def profile_command(self, menu, command):
        if command[:10] == 'change to ':
            self.change_suite(command[10:])
        elif command == 'drop':
            self.profiletrait.drop_profile(self.current.profile)
            self.profiles.drop_profile(self.current.profile)
            self.current = None
            self.reset_rows()
        elif command == 'set defaults':
            self.variables.set_defaults()
        elif command == 'append defaults':
            self.variables.append_defaults()
        else:
            raise Error, 'bad command %s' % command

    def change_suite(self, suite):
        clause = Eq('profile', self.current.profile)
        self.profiles.update(data={'suite': suite}, clause=clause)
        print 'changing suite to ', suite
        self.current_suite = suite
        self.reset_rows()
class ProfileBrowser(ListNoteBook, HasDialogs):
    def __init__(self, conn, suites, name='ProfileBrowser'):
        self.menu = self.__make_mainmenu_(suites)
        ListNoteBook.__init__(self, name=name)
        self.conn = conn
        self.profiles = Profile(self.conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.family = Family(self.conn)
        self.pfamily = StatementCursor(self.conn)
        self.pfamily.set_table('profile_family')
        self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
        self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
        self.family_menu = make_menu(['drop'], self.family_command)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
        self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
        self.append_page(ScrollCList(rcmenu=self.family_menu), 'families')
        self.dialogs = {}.fromkeys(['order'])
        
    def __make_mainmenu_(self, suites):
        suite_commands = ['change to %s' %suite for suite in suites]
        profile_commands = ['drop', 'set defaults', 'append defaults']
        commands = suite_commands + profile_commands
        return make_menu(commands, self.profile_command)

    def reset_rows(self):
        self.set_rows(self.profiles.select(fields=['profile', 'suite'], order='profile'))
        self.set_row_select(self.profile_selected)

    def profile_selected(self, listbox, row, column, event):
        row = listbox.get_selected_data()[0]
        self.current = row
        self.select_profile(self.current.profile)

    def select_profile(self, profile):
        self.variables = ProfileEnvironment(self.conn, profile)
        self.profiletrait.set_profile(profile)
        self.__set_pages(profile)

    def __set_pages(self, profile):
        pages = dict(self.pages)
        #set traits for profile
        pages['traits'].set_rows(self.profiletrait.trait_rows())
        pages['traits'].set_select_mode('multi')
        clause = Eq('profile', self.current.profile)
        cursor = self.variables.env.cursor
        pages['variables'].set_rows(cursor.select(clause=clause), ['trait'])
        pages['variables'].set_select_mode('multi')
        pfrows = self.pfamily.select(fields=['family'], clause=clause)
        pages['families'].set_rows(pfrows)
        pages['families'].set_select_mode('multi')
        self.__set_droptargets__(pages)
        
        
    def __set_droptargets__(self, pages):
        set_receive_targets(pages['traits'].listbox,
                            self.drop_trait, TARGETS.get('trait', self.current.suite))
        set_receive_targets(pages['families'].listbox,
                            self.drop_families, FTargets.get('family', 'flavor'))
        

    def trait_command(self, menuitem, action):
        traits = self._get_listbox('traits', 'trait')
        if action == 'drop':
            clause = In('trait', traits) & Eq('profile', self.current.profile)
            self.profiletrait.cmd.delete(clause=clause)
            self.__set_pages(self.current.profile)
        elif action == 'order':
            if not self.dialogs['order']:
                self.dialogs['order'] = dialogs.Entry('enter order', name='order')
                self.dialogs['order'].set_ok(self.set_order)
                self.dialogs['order'].set_cancel(self.destroy_dialog)


    def variable_command(self, menuitem, action):
        rows = self.pages['variables'].get_selected_data()
        cursor = self.variables.env.cursor
        if action == 'drop':
            for row in rows:
                clause = Eq('profile', self.current.profile) & Eq('trait', row.trait)
                clause &= Eq('name', row.name)
                cursor.delete(clause=clause)
        elif action == 'edit':
            self.edit_profilevars()

    def family_command(self, menuitem, action):
        print action
        families = [x[0] for x in self.pages['families'].get_selected_data()]
        if action == 'drop':
            clause = Eq('profile', self.current.profile) & In('family', families)
            self.pfamily.delete(clause=clause)

        
    def edit_profilevars(self):
        config = ProfileVariablesConfig(self.conn, self.current.profile)
        newconfig = config.edit()
        config.update(newconfig)
        self.select_profile(self.current.profile)
                            
    def set_order(self, button):
        dialog = self.dialogs['order']
        ord = dialog.get()
        rows = self.pages['traits'].get_selected_data()
        pclause = Eq('profile', self.current.profile)
        for row in rows:
            clause = pclause & Eq('trait', row.trait)
            self.profiletrait.update(data=dict(ord=ord), clause=clause)
        
    def drop_trait(self, listbox, context, x, y, selection,
                   targettype, time):
        traits = keysplitter(selection)
        self.profiletrait.insert_traits(traits)
        self.__set_pages(self.current.profile)

    def drop_families(self, listbox, context, x, y, selection,
                    targettype, time):
        families = keysplitter(selection)
        clause = Eq('profile', self.current.profile)
        data = dict(profile=self.current.profile)
        current = [x.family for x in self.pfamily.select(clause=clause)]
        for f in families:
            if f not in current:
                data['family'] = f
                self.pfamily.insert(data=data)
        self.__set_pages(self.current.profile)
            

    def _get_listbox(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def profile_command(self, menu, command):
        if command[:10] == 'change to ':
            self.change_suite(command[10:])
        elif command == 'drop':
            self.profiletrait.drop_profile(self.current.profile)
            self.profiles.drop_profile(self.current.profile)
            self.current = None
            self.reset_rows()
        elif command == 'set defaults':
            self.variables.set_defaults()
        elif command == 'append defaults':
            self.variables.append_defaults()
        else:
            raise Error, 'bad command %s' %command
            
    def change_suite(self, suite):
        clause = Eq('profile', self.current.profile)
        self.profiles.update(data={'suite' : suite}, clause=clause)        
        print 'changing suite to ', suite
        self.current_suite = suite
        self.reset_rows()