예제 #1
0
 def __init__(self, conn, suite, name='TraitDebconfBrowser'):
     self.menu = make_menu(dcmenu_cmds, self.modify_trait)
     ListNoteBook.__init__(self)
     self.conn = conn
     self.suite = suite
     self.dc = TraitDebconf(self.conn, self.suite)
     self.traits = Traits(self.conn, self.suite)
     self.reset_rows()
예제 #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
예제 #3
0
class SuiteTraitCombo(QWidget):
    def __init__(self, app, parent, name='SuiteTraitCombo'):
        QWidget.__init__(self, parent, name)
        dbwidget(self, app)
        self.suiteCursor = Suites(self.conn)
        self.suites = self.suiteCursor.list()
        self.traits = Traits(self.conn, self.suites[0])
        self.scombo = SuiteCombo(self, self.suites)
        self.tcombo = MyCombo(self, 'TypeCombo')
        self.tcombo.fill(['template', 'script'])
        self.trcombo = MyCombo(self, 'TraitCombo')
        self.ubutton = KPushButton('update', self)
        self.listView = TraitList(self.app, self)
        self.vbox = QVBoxLayout(self)
        for member in ['listView', 'scombo', 'tcombo', 'trcombo', 'ubutton']:
            widget = getattr(self, member)
            self.vbox.addWidget(widget)
        self.connect(self.scombo,
                     SIGNAL('highlighted(int)'), self.update_traits)
        self.connect(self.ubutton,
                     SIGNAL('clicked()'), self.refreshlistView)
        

    def update_traits(self):
        suite = str(self.scombo.currentText())
        self.traits.set_suite(suite)
        self.listView.set_suite(suite)
        self.listView.ftype = str(self.tcombo.currentText())
        
    def refreshlistView(self):
        trait = str(self.trcombo.currentText())
        if trait:
            self.listView.set_trait(trait)
        self.listView.ftype = str(self.tcombo.currentText())
        suite = str(self.scombo.currentText())
        self.listView.set_suite(suite)
        self.traits.set_suite(suite)
        traits = [row.trait for row in self.traits.select()]
        self.trcombo.fill(traits)
        if trait in traits:
            self.trcombo.setCurrentItem(traits.index(trait))
        self.listView.refreshlistView()

    def getData(self):
        return self.listView.getData()

    def updateData(self, data):
        self.listView.updateData(data)
예제 #4
0
class SuiteTraitCombo(QWidget):
    def __init__(self, app, parent, name='SuiteTraitCombo'):
        QWidget.__init__(self, parent, name)
        dbwidget(self, app)
        self.suiteCursor = Suites(self.conn)
        self.suites = self.suiteCursor.list()
        self.traits = Traits(self.conn, self.suites[0])
        self.scombo = SuiteCombo(self, self.suites)
        self.tcombo = MyCombo(self, 'TypeCombo')
        self.tcombo.fill(['template', 'script'])
        self.trcombo = MyCombo(self, 'TraitCombo')
        self.ubutton = KPushButton('update', self)
        self.listView = TraitList(self.app, self)
        self.vbox = QVBoxLayout(self)
        for member in ['listView', 'scombo', 'tcombo', 'trcombo', 'ubutton']:
            widget = getattr(self, member)
            self.vbox.addWidget(widget)
        self.connect(self.scombo, SIGNAL('highlighted(int)'),
                     self.update_traits)
        self.connect(self.ubutton, SIGNAL('clicked()'), self.refreshlistView)

    def update_traits(self):
        suite = str(self.scombo.currentText())
        self.traits.set_suite(suite)
        self.listView.set_suite(suite)
        self.listView.ftype = str(self.tcombo.currentText())

    def refreshlistView(self):
        trait = str(self.trcombo.currentText())
        if trait:
            self.listView.set_trait(trait)
        self.listView.ftype = str(self.tcombo.currentText())
        suite = str(self.scombo.currentText())
        self.listView.set_suite(suite)
        self.traits.set_suite(suite)
        traits = [row.trait for row in self.traits.select()]
        self.trcombo.fill(traits)
        if trait in traits:
            self.trcombo.setCurrentItem(traits.index(trait))
        self.listView.refreshlistView()

    def getData(self):
        return self.listView.getData()

    def updateData(self, data):
        self.listView.updateData(data)
예제 #5
0
class TraitList(KListView):
    def __init__(self, app, parent, ftype='template', name='TraitList'):
        KListView.__init__(self, parent, name)
        dbwidget(self, app)
        self.ftype = ftype
        self.scripts = None
        self.templates = None
        self.traits = None
        self.setRootIsDecorated(True)
        self.addColumn('trait/file')
        self.addColumn('name')
        self.addColumn('package')
        
    def set_suite(self, suite):
        self.scripts = TraitScript(self.conn, suite)
        self.templates = TraitTemplate(self.conn, suite)
        self.traits = Traits(self.conn, suite)
        

    def refreshlistView(self):
        self.clear()
        if self.ftype == 'template':
            self.setColumnText(1, 'template')
        elif self.ftype == 'script':
            self.setColumnText(1, 'script')

        for trait in self.traits.list():
            item = KListViewItem(self, trait)
            item.trait = trait
            if self.ftype == 'template':
                for row in self.templates.templates(trait):
                    titem = KListViewItem(item, str(row.templatefile), row.template, row.package)
                    titem.trait = trait
                    titem.row = row
            elif self.ftype == 'script':
                for row in self.scripts.cmd.select(clause=Eq('trait', trait), order='script'):
                    sitem = KListViewItem(item, str(row.scriptfile), row.script)
                    sitem.trait = trait
                    sitem.row = row
                    
    def getData(self):
        item = self.currentItem()
        if self.ftype == 'template':
            self.templates.set_trait(item.trait)
            return self.templates.templatedata(item.row.package, item.row.template)
        elif self.ftype == 'script':
            self.scripts.set_trait(item.trait)
            return self.scripts.scriptdata(item.row.script)

    def updateData(self, data):
        item = self.currentItem()
        row = item.row
        if self.ftype == 'template':
            self.templates.set_trait(item.trait)
            self.templates.update_templatedata(row.package, row.template, data)
        elif self.ftype == 'script':
            self.scripts.set_trait(item.trait)
            self.scripts.update_scriptdata(row.script, data)
예제 #6
0
 def __init__(self, app, parent, name='SuiteTraitCombo'):
     QWidget.__init__(self, parent, name)
     dbwidget(self, app)
     self.suiteCursor = Suites(self.conn)
     self.suites = self.suiteCursor.list()
     self.traits = Traits(self.conn, self.suites[0])
     self.scombo = SuiteCombo(self, self.suites)
     self.tcombo = MyCombo(self, 'TypeCombo')
     self.tcombo.fill(['template', 'script'])
     self.ubutton = KPushButton('update', self)
     self.listView = TraitList(self.app, self)
     self.vbox = QVBoxLayout(self)
     for member in ['listView', 'scombo', 'tcombo', 'ubutton']:
         widget = getattr(self, member)
         self.vbox.addWidget(widget)
     self.connect(self.scombo, SIGNAL('highlighted(int)'),
                  self.update_traits)
     self.connect(self.ubutton, SIGNAL('clicked()'), self.refreshlistView)
예제 #7
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
예제 #8
0
 def __init__(self, app, parent, name='SuiteTraitCombo'):
     QWidget.__init__(self, parent, name)
     dbwidget(self, app)
     self.suiteCursor = Suites(self.conn)
     self.suites = self.suiteCursor.list()
     self.traits = Traits(self.conn, self.suites[0])
     self.scombo = SuiteCombo(self, self.suites)
     self.tcombo = MyCombo(self, 'TypeCombo')
     self.tcombo.fill(['template', 'script'])
     self.ubutton = KPushButton('update', self)
     self.listView = TraitList(self.app, self)
     self.vbox = QVBoxLayout(self)
     for member in ['listView', 'scombo', 'tcombo', 'ubutton']:
         widget = getattr(self, member)
         self.vbox.addWidget(widget)
     self.connect(self.scombo,
                  SIGNAL('highlighted(int)'), self.update_traits)
     self.connect(self.ubutton,
                  SIGNAL('clicked()'), self.refreshlistView)
예제 #9
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))
예제 #10
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))
예제 #11
0
class TraitDebconfBrowser(ListNoteBook):
    def __init__(self, conn, suite, name='TraitDebconfBrowser'):
        self.menu = make_menu(dcmenu_cmds, self.modify_trait)
        ListNoteBook.__init__(self)
        self.conn = conn
        self.suite = suite
        self.dc = TraitDebconf(self.conn, self.suite)
        self.traits = Traits(self.conn, self.suite)
        self.reset_rows()

    def reset_rows(self):
        rows = self.traits.select(fields=['trait'])
        self.set_rows(rows)
        self.set_row_select(self.trait_selected)

    def trait_selected(self, listbox, row, column, event):
        trait = listbox.get_selected_data()[0].trait
        self.select_trait(trait)
        
    def select_trait(self, trait):
        self.trait = trait
        self.dc.set_trait(trait)
        if trait not in self.pages:
            newpage = ScrollCList()
            self.append_page(newpage, trait)
        self.set_current_page(trait)
        self.pages[trait].set_rows(self.dc.cmd.select())

    def modify_trait(self, menuitem, action):
        try:
            trait = self.listbox.get_selected_data()[0].trait
        except IndexError:
            dialogs.Message('no trait selected')
            raise IndexError
        if action == 'getconfig':
            self.select_configdat(action='getconfig')
        elif action == 'getfromtar':
            self.select_configdat(action='getfromtar')
        elif action == 'update':
            print 'update'
        elif action == 'delete':
            print 'delete'
        

    def select_configdat(self, button=None, data=None, action='getconfig'):
        select_a_file(action, '/', self.filesel_ok)
        

    def pull_from_tar(self, button, fileselect):
        info, tfile = fileselect.extract_file()
        print tfile.name
        conffile, cfpath = tempfile.mkstemp('paella', 'debconf')
        conffile = file(cfpath, 'w')
        conffile.write(tfile.read())
        conffile.close()
        self.editor = DebconfEditorWin(self.conn, self.suite, self.trait)
        self.editor.set_config(cfpath)
        fileselect.destroy()
        os.remove(cfpath)
    
        
    def filesel_ok(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        if action == 'getconfig':
            self.editor = DebconfEditorWin(self.conn, self.suite, self.trait)
            self.editor.set_config(path)
        elif action == 'getfromtar':
            select_from_tarfile('getfromtar', path, self.pull_from_tar)
        filesel.destroy()
예제 #12
0
 def set_suite(self, suite):
     self.scripts = TraitScript(self.conn, suite)
     self.templates = TraitTemplate(self.conn, suite)
     self.traits = Traits(self.conn, suite)
예제 #13
0
 def set_suite(self, suite):
     self.scripts = TraitScript(self.conn, suite)
     self.templates = TraitTemplate(self.conn, suite)
     self.traits = Traits(self.conn, suite)
예제 #14
0
class TraitList(KListView):
    def __init__(self, app, parent, ftype='template', name='TraitList'):
        KListView.__init__(self, parent, name)
        dbwidget(self, app)
        self.ftype = ftype
        self.scripts = None
        self.templates = None
        self.traits = None
        self.trait = None
        self.setRootIsDecorated(True)
        self.addColumn('trait/file')
        self.addColumn('name')
        self.addColumn('package')

    def set_suite(self, suite):
        self.scripts = TraitScript(self.conn, suite)
        self.templates = TraitTemplate(self.conn, suite)
        self.traits = Traits(self.conn, suite)

    def set_trait(self, trait):
        self.trait = trait

    def refreshlistView(self):
        self.clear()
        if self.ftype == 'template':
            self.setColumnText(1, 'template')
        elif self.ftype == 'script':
            self.setColumnText(1, 'script')
        if self.trait is None:
            traits = self.traits.list()
        else:
            traits = [self.trait]
        for trait in traits:
            item = KListViewItem(self, trait)
            item.trait = trait
            if self.ftype == 'template':
                for row in self.templates.templates(trait):
                    titem = KListViewItem(item, str(row.templatefile),
                                          row.template, row.package)
                    titem.trait = trait
                    titem.row = row
            elif self.ftype == 'script':
                for row in self.scripts.cmd.select(clause=Eq('trait', trait),
                                                   order='script'):
                    sitem = KListViewItem(item, str(row.scriptfile),
                                          row.script)
                    sitem.trait = trait
                    sitem.row = row

    def getData(self):
        item = self.currentItem()
        if self.ftype == 'template':
            self.templates.set_trait(item.trait)
            return self.templates.templatedata(item.row.package,
                                               item.row.template)
        elif self.ftype == 'script':
            self.scripts.set_trait(item.trait)
            return self.scripts.scriptdata(item.row.script)

    def updateData(self, data):
        item = self.currentItem()
        row = item.row
        if self.ftype == 'template':
            self.templates.set_trait(item.trait)
            self.templates.update_templatedata(row.package, row.template, data)
        elif self.ftype == 'script':
            self.scripts.set_trait(item.trait)
            self.scripts.update_scriptdata(row.script, data)