示例#1
0
class ProfileDoc(BaseDocument):
    def __init__(self, app, **atts):
        BaseDocument.__init__(self, app, **atts)
        self.profile = Profile(self.conn)

    def set_profile(self, profile):
        self.clear_body()
        self.profile.set_profile(profile)
        title = SimpleTitleElement('Profile:  %s' % profile, bgcolor='IndianRed',
                                   width='100%')
        self.body.appendChild(title)
        rows = self.profile.get_trait_rows()
        ptitle = Anchor('edit.traits.%s' % self.profile.current.profile, 'Traits')
        self.body.appendChild(SectionTitle(ptitle))
        #self.body.appendChild(SectionTitle('Traits'))
        if len(rows):
            self.body.appendChild(TraitTable(rows, bgcolor='IndianRed1'))
        vtitle = Anchor('edit.variables.%s' % self.profile.current.profile, 'Variables')
        self.body.appendChild(SectionTitle(vtitle))
        erows = self.profile._env.get_rows()
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
        etitle = Anchor('edit.families.%s' % self.profile.current.profile, 'Families')
        self.body.appendChild(SectionTitle(etitle))
        families = self.profile.get_families()
        flist = UnorderedList()
        for f in families:
            flist.appendChild(ListItem(f))
        self.body.appendChild(flist)
示例#2
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'])
示例#3
0
class ProfileDoc(BaseDocument):
    def __init__(self, app, **atts):
        BaseDocument.__init__(self, app, **atts)
        self.profile = Profile(self.conn)

    def set_profile(self, profile):
        self.clear_body()
        self.profile.set_profile(profile)
        title = SimpleTitleElement('Profile:  %s' % profile,
                                   bgcolor='IndianRed',
                                   width='100%')
        self.body.appendChild(title)
        rows = self.profile.get_trait_rows()
        ptitle = Anchor('edit.traits.%s' % self.profile.current.profile,
                        'Traits')
        self.body.appendChild(SectionTitle(ptitle))
        #self.body.appendChild(SectionTitle('Traits'))
        if len(rows):
            self.body.appendChild(TraitTable(rows, bgcolor='IndianRed1'))
        vtitle = Anchor('edit.variables.%s' % self.profile.current.profile,
                        'Variables')
        self.body.appendChild(SectionTitle(vtitle))
        erows = self.profile._env.get_rows()
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
        etitle = Anchor('edit.families.%s' % self.profile.current.profile,
                        'Families')
        self.body.appendChild(SectionTitle(etitle))
        families = self.profile.get_families()
        flist = UnorderedList()
        for f in families:
            flist.appendChild(ListItem(f))
        self.body.appendChild(flist)
示例#4
0
class TraitAssigner(BaseAssigner):
    def __init__(self, app, parent, profile):
        self.profile = Profile(app.conn)
        self.profile.set_profile(profile)
        BaseAssigner.__init__(self, app, parent,
                              name='TraitAssigner', udbuttons=True)
        self.connect(self, SIGNAL('okClicked()'), self.slotLaughAtMe)
        
    def initView(self):
        app = self.app
        self.db = app.db
        self.suite = self.profile.current.suite
        self.traits = StatementCursor(app.conn)
        self.traits.set_table('%s_traits'  % self.suite)
        
        ptrows = self.profile.get_trait_rows()
        pt = [r.trait for r in ptrows]
        all_trows = self.traits.select(fields=['trait'], order=['trait'])
        trows = [r for r in all_trows if r.trait not in pt]
        abox = self.listBox.availableListBox()
        sbox = self.listBox.selectedListBox()
        for row in ptrows:
            r = QListBoxText(sbox, row.trait)
            r.trait = row.trait
        for row in trows:
            r = QListBoxText(abox, row.trait)
            r.trait = row.trait

    def slotLaughAtMe(self):
        sbox = self.listBox.selectedListBox()
        traits = [sbox.item(n).trait for n in range(sbox.numRows())] 
        print 'laughing out loud', traits
示例#5
0
 def __init__(self, conn, cfg):
     os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
     Installer.__init__(self, conn, cfg)
     self.profiletrait = ProfileTrait(self.conn)
     self.profile = None
     self.installer = None
     self.cfg = cfg
     self._profile = Profile(self.conn)
     self.log.info('profile installer initialized')
示例#6
0
 def __init__(self, app, parent):
     SimpleSplitWindow.__init__(self, app, parent, ProfileView, 'ProfileMainWindow')
     self.app = app
     self.initActions()
     self.initMenus()
     self.initToolbar()
     self.conn = app.conn
     self.cfg = app.cfg
     self.cursor = StatementCursor(self.conn)
     self.profile = Profile(self.conn)
     self.refreshListView()
     self.resize(600, 800)
     self.setCaption('paella profiles')
示例#7
0
 def __init__(self, conn, suites, name='ProfileBrowser'):
     self.menu = self.__make_mainmenu_(suites)
     ListNoteBook.__init__(self, name=name)
     self.conn = conn
     self.profiles = Profile(self.conn)
     self.profiletrait = ProfileTrait(self.conn)
     self.family = Family(self.conn)
     self.pfamily = StatementCursor(self.conn)
     self.pfamily.set_table('profile_family')
     self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
     self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
     self.family_menu = make_menu(['drop'], self.family_command)
     self.reset_rows()
     self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
     self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
     self.append_page(ScrollCList(rcmenu=self.family_menu), 'families')
     self.dialogs = {}.fromkeys(['order'])
示例#8
0
 def __init__(self, conn, cfg):
     os.environ["DEBIAN_FRONTEND"] = "noninteractive"
     Installer.__init__(self, conn, cfg)
     self.profiletrait = ProfileTrait(self.conn)
     self.profile = None
     self.installer = None
     self.cfg = cfg
     self._profile = Profile(self.conn)
     self.log.info("profile installer initialized")
示例#9
0
 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')
示例#10
0
 def __init__(self, app, parent, profile):
     KMainWindow.__init__(self, parent, 'TraitAssigner')
     self.page = QFrame(self)
     self.vbox = QVBoxLayout(self.page, 5, 7)
     self.listBox = KActionSelector(self.page)
     self.listBox.setShowUpDownButtons(True)
     self.setCentralWidget(self.page)
     self.vbox.addWidget(self.listBox)
     hbox = QHBoxLayout(self.page, 5, 7)
     self.vbox.addLayout(hbox)
     self.ok_button = KPushButton('ok', self.page)
     self.cancel_button = KPushButton('cancel', self.page)
     hbox.addWidget(self.ok_button)
     hbox.addWidget(self.cancel_button)
     self.app = app
     self.db = app.db
     self.profile = Profile(app.conn)
     self.profile.set_profile(profile)
     self.suite = self.profile.current.suite
     self.traits = StatementCursor(app.conn)
     self.traits.set_table('%s_traits'  % self.suite)
     self.initlistView()
     self.show()
示例#11
0
class TraitAssignerOrig(KMainWindow):
    def __init__(self, app, parent, profile):
        KMainWindow.__init__(self, parent, 'TraitAssigner')
        self.page = QFrame(self)
        self.vbox = QVBoxLayout(self.page, 5, 7)
        self.listBox = KActionSelector(self.page)
        self.listBox.setShowUpDownButtons(True)
        self.setCentralWidget(self.page)
        self.vbox.addWidget(self.listBox)
        hbox = QHBoxLayout(self.page, 5, 7)
        self.vbox.addLayout(hbox)
        self.ok_button = KPushButton('ok', self.page)
        self.cancel_button = KPushButton('cancel', self.page)
        hbox.addWidget(self.ok_button)
        hbox.addWidget(self.cancel_button)
        self.app = app
        self.db = app.db
        self.profile = Profile(app.conn)
        self.profile.set_profile(profile)
        self.suite = self.profile.current.suite
        self.traits = StatementCursor(app.conn)
        self.traits.set_table('%s_traits'  % self.suite)
        self.initlistView()
        self.show()

    def initlistView(self):
        ptrows = self.profile.get_trait_rows()
        pt = [r.trait for r in ptrows]
        all_trows = self.traits.select(fields=['trait'], order=['trait'])
        trows = [r for r in all_trows if r.trait not in pt]
        abox = self.listBox.availableListBox()
        sbox = self.listBox.selectedListBox()
        for row in ptrows:
            QListBoxText(sbox, row.trait)
        for row in trows:
            QListBoxText(abox, row.trait)
示例#12
0
class ProfileMainWindow(SimpleSplitWindow):
    def __init__(self, app, parent):
        SimpleSplitWindow.__init__(self, app, parent, ProfileView, 'ProfileMainWindow')
        self.app = app
        self.initActions()
        self.initMenus()
        self.initToolbar()
        self.conn = app.conn
        self.cfg = app.cfg
        self.cursor = StatementCursor(self.conn)
        self.profile = Profile(self.conn)
        self.refreshListView()
        self.resize(600, 800)
        self.setCaption('paella profiles')
        
    def initActions(self):
        collection = self.actionCollection()
        
    def initMenus(self):
        mainMenu = KPopupMenu(self)
        menus = [mainMenu]
        self.menuBar().insertItem('&Main', mainMenu)
        self.menuBar().insertItem('&Help', self.helpMenu(''))

    def initToolbar(self):
        toolbar = self.toolBar()

    def initlistView(self):
        self.listView.setRootIsDecorated(True)
        self.listView.addColumn('group')
        
    def refreshListView(self):
        for row in self.profile.select(fields=['profile', 'suite'], order='profile'):
            item = KListViewItem(self.listView, row.profile)
            item.profile = row.profile
                
    def selectionChanged(self):
        current = self.listView.currentItem()
        if hasattr(current, 'profile'):
            self.view.set_profile(current.profile)
        if hasattr(current, 'trait'):
            print 'trait is', current.trait
            self.view.set_trait(current.trait)
        if hasattr(current, 'suite'):
            print 'suite is', current.suite
            if hasattr(current, 'widget'):
                print 'widget is', current.widget
示例#13
0
 def __init__(self, conn, suites, name='ProfileBrowser'):
     self.menu = self.__make_mainmenu_(suites)
     ListNoteBook.__init__(self, name=name)
     self.conn = conn
     self.profiles = Profile(self.conn)
     self.profiletrait = ProfileTrait(self.conn)
     self.family = Family(self.conn)
     self.pfamily = StatementCursor(self.conn)
     self.pfamily.set_table('profile_family')
     self.trait_menu = make_menu(['drop', 'order'], self.trait_command)
     self.pdata_menu = make_menu(['edit', 'drop'], self.variable_command)
     self.family_menu = make_menu(['drop'], self.family_command)
     self.reset_rows()
     self.append_page(ScrollCList(rcmenu=self.trait_menu), 'traits')
     self.append_page(ScrollCList(rcmenu=self.pdata_menu), 'variables')
     self.append_page(ScrollCList(rcmenu=self.family_menu), 'families')
     self.dialogs = {}.fromkeys(['order'])
示例#14
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'])
示例#15
0
 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')
示例#16
0
class ProfileInstaller(Installer):
    def __init__(self, conn, cfg):
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
        Installer.__init__(self, conn, cfg)
        self.profiletrait = ProfileTrait(self.conn)
        self.profile = None
        self.installer = None
        self.cfg = cfg
        self._profile = Profile(self.conn)
        self.log.info('profile installer initialized')

    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ['PAELLA_PROFILE'] = profile
        self.profiletrait.set_profile(profile)
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, profile)
        self.installer = TraitInstaller(self.conn, self.suite, self.cfg)
        self.installer.log = self.log
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info('profile set to %s' % profile)

    def get_profile_data(self):
        return self.env.ProfileData()

    def set_logpath(self, logpath):
        Installer.set_logpath(self, logpath)
        if hasattr(self, 'installer'):
            self.installer.set_logpath(logpath)

    def make_traitlist_orig(self):
        traitparent = TraitParent(self.conn, self.suite)
        profile_traits = [x.trait for x in self.profiletrait.trait_rows()]
        all_traits = list(self.traitparent.get_traitset(profile_traits))
        traitlist = []
        while len(profile_traits):
            profile_traits_prepended = False
            trait = profile_traits[0]
            traitparent.set_trait(trait)
            parents = [r.parent for r in traitparent.parents()]
            for p in parents:
                if not profile_traits_prepended and p not in traitlist:
                    profile_traits = [p] + profile_traits
                    profile_traits_prepended = True
                    self.log.info('profile_traits prepended with %s' % p)
            if not profile_traits_prepended:
                traitlist.append(trait)
                del profile_traits[0]
            self.log.info('%s %s' % (str(traitlist), profile_traits))
        return traitlist

    def make_traitlist(self):
        tp = TraitParent(self.conn, self.suite)
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        all = list(self.traitparent.get_traitset(listed))
        setfun = tp.set_trait
        parfun = tp.parents
        log = self.log
        return make_deplist(listed, all, setfun, parfun, log)

    def process(self):
        traits = self.make_traitlist()
        self.processed = []
        for trait in traits:
            self.process_trait(trait)
            self.log.info('currently processed %s' % ','.join(self.processed))
        self.log.info('all traits processed for profile %s' % self.profile)
        self.log.info('------------------------------------')

    def process_trait(self, trait):
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info('processing trait %s' % trait)
        self.installer.process()
        self.processed.append(trait)
        self.log.info('processed:  %s' % ', '.join(self.processed))

    def set_template_path(self, path):
        self.installer.set_template_path(path)

    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command('apt-get update'))

    def install_kernel(self, package):
        os.system(self.command('touch /boot/vmlinuz-fake'))
        os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz'))
        os.system(self.command('apt-get -y install %s' % package))
        print 'kernel %s installed' % package
示例#17
0
class ProfileInstaller(Installer):
    def __init__(self, conn, cfg):
        os.environ["DEBIAN_FRONTEND"] = "noninteractive"
        Installer.__init__(self, conn, cfg)
        self.profiletrait = ProfileTrait(self.conn)
        self.profile = None
        self.installer = None
        self.cfg = cfg
        self._profile = Profile(self.conn)
        self.log.info("profile installer initialized")

    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ["PAELLA_PROFILE"] = profile
        self.profiletrait.set_profile(profile)
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, profile)
        self.installer = TraitInstaller(self.conn, self.suite, self.cfg)
        self.installer.log = self.log
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info("profile set to %s" % profile)

    def get_profile_data(self):
        return self.env.ProfileData()

    def set_logpath(self, logpath):
        Installer.set_logpath(self, logpath)
        if hasattr(self, "installer"):
            self.installer.set_logpath(logpath)

    def make_traitlist_orig(self):
        traitparent = TraitParent(self.conn, self.suite)
        profile_traits = [x.trait for x in self.profiletrait.trait_rows()]
        all_traits = list(self.traitparent.get_traitset(profile_traits))
        traitlist = []
        while len(profile_traits):
            profile_traits_prepended = False
            trait = profile_traits[0]
            traitparent.set_trait(trait)
            parents = [r.parent for r in traitparent.parents()]
            for p in parents:
                if not profile_traits_prepended and p not in traitlist:
                    profile_traits = [p] + profile_traits
                    profile_traits_prepended = True
                    self.log.info("profile_traits prepended with %s" % p)
            if not profile_traits_prepended:
                traitlist.append(trait)
                del profile_traits[0]
            self.log.info("%s %s" % (str(traitlist), profile_traits))
        return traitlist

    def make_traitlist(self):
        tp = TraitParent(self.conn, self.suite)
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        all = list(self.traitparent.get_traitset(listed))
        setfun = tp.set_trait
        parfun = tp.parents
        log = self.log
        return make_deplist(listed, all, setfun, parfun, log)

    def process(self):
        traits = self.make_traitlist()
        self.processed = []
        for trait in traits:
            self.process_trait(trait)
            self.log.info("currently processed %s" % ",".join(self.processed))
        self.log.info("all traits processed for profile %s" % self.profile)
        self.log.info("------------------------------------")

    def process_trait(self, trait):
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info("processing trait %s" % trait)
        self.installer.process()
        self.processed.append(trait)
        self.log.info("processed:  %s" % ", ".join(self.processed))

    def set_template_path(self, path):
        self.installer.set_template_path(path)

    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command("apt-get update"))

    def install_kernel(self, package):
        os.system(self.command("touch /boot/vmlinuz-fake"))
        os.system(self.command("ln -s boot/vmlinuz-fake vmlinuz"))
        os.system(self.command("apt-get -y install %s" % package))
        print "kernel %s installed" % package
示例#18
0
 def __init__(self, app, **atts):
     BaseDocument.__init__(self, app, **atts)
     self.profile = Profile(self.conn)
示例#19
0
import os

from paella.profile.base import PaellaConnection, PaellaConfig
from paella.profile.trait import Trait
from paella.profile.family import Family
from paella.profile.profile import Profile
from paella.machines.machine import MachineHandler

if __name__ == '__main__':
    cfg = PaellaConfig()
    conn = PaellaConnection()
    t = Trait(conn)
    f = Family(conn)
    p = Profile(conn)
    m = MachineHandler(conn)
示例#20
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()
示例#21
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()
示例#22
0
class InstallerTools(object):
    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'])

    def env(self):
        env = RefDict(self.tp.Environment())
        env.update(self.pr.get_family_data())
        env.update(self.pr.get_profile_data())
        return env

    def set_trait(self, trait):
        self.trait = trait
        self.tp.set_trait(trait)
        self.tr.set_trait(trait)
        self.parents = self.tr.parents()
        self._envv = self.env()
        self.installer.set_trait(trait)
        self.packages = self.installer.traitpackage.packages()
        self.templates = self.installer.traittemplate.templates()

    def get(self, key):
        if self._envv is None:
            raise Error, 'need to set trait first'
        return self._envv.dereference(key)

    def install_modules(self, name):
        modules = str2list(self.get(name))
        print 'installing modules', modules, 'to %s/etc/modules' % self.target
        setup_modules(self.target, modules)

    def remove_packages(self, packages=None):
        if packages is None:
            packages = self.packages
        if len(packages):
            if hasattr(packages[0], 'package'):
                packages = [p.package for p in packages]
        package_list = ' '.join(packages)
        command = 'apt-get -y remove %s' % package_list
        self.installer.run('remove', command, proc=True)
示例#23
0
 def __init__(self, app, parent, profile):
     self.profile = Profile(app.conn)
     self.profile.set_profile(profile)
     BaseAssigner.__init__(self, app, parent,
                           name='TraitAssigner', udbuttons=True)
     self.connect(self, SIGNAL('okClicked()'), self.slotLaughAtMe)
示例#24
0
 def __init__(self, app, **atts):
     BaseDocument.__init__(self, app, **atts)
     self.profile = Profile(self.conn)
示例#25
0
class InstallerTools(object):
    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'])
            
        
    def env(self):
        env = RefDict(self.tp.Environment())
        env.update(self.pr.get_family_data())
        env.update(self.pr.get_profile_data())
        return env

    def set_trait(self, trait):
        self.trait = trait
        self.tp.set_trait(trait)
        self.tr.set_trait(trait)
        self.parents = self.tr.parents()
        self._envv = self.env()
        self.installer.set_trait(trait)
        self.packages = self.installer.traitpackage.packages()
        self.templates = self.installer.traittemplate.templates()
        
    def get(self, key):
        if self._envv is None:
            raise Error, 'need to set trait first'
        return self._envv.dereference(key)

    def install_modules(self, name):
        modules = str2list(self.get(name))
        print 'installing modules', modules, 'to %s/etc/modules' % self.target
        setup_modules(self.target, modules)

    def remove_packages(self, packages=None):
        if packages is None:
            packages = self.packages
        if len(packages):
            if hasattr(packages[0], 'package'):
                packages = [p.package for p in packages]
        package_list = ' '.join(packages)
        command = 'apt-get -y remove %s' % package_list
        self.installer.run('remove', command, proc=True)