Source

vpackager / src / vpackager / historymanager.py

Full commit
Moises Henriquez 4ac810a 




Moises Henriquez 6d72a96 
Moises Henriquez 4ac810a 










Moises Henriquez 236a4e5 
Moises Henriquez 0703e58 

Moises Henriquez bc4bb28 
Moises Henriquez 4ac810a 




Moises Henriquez bc4bb28 

Moises Henriquez 1f22c46 
Moises Henriquez bc4bb28 


Moises Henriquez 1f22c46 
Moises Henriquez bc4bb28 












Moises Henriquez 1f22c46 

Moises Henriquez bc4bb28 








Moises Henriquez 1f22c46 





Moises Henriquez bc4bb28 






































Moises Henriquez 1f22c46 
Moises Henriquez bc4bb28 
Moises Henriquez 1f22c46 

Moises Henriquez bc4bb28 





Moises Henriquez 4ac810a 


Moises Henriquez 87ccb7b 





Moises Henriquez 4ac810a 
Moises Henriquez 0703e58 
Moises Henriquez 4ac810a 
Moises Henriquez 1bc4fb0 
Moises Henriquez 4ac810a 





Moises Henriquez 0703e58 
Moises Henriquez 4ac810a 
Moises Henriquez 0703e58 
Moises Henriquez 4ac810a 
Moises Henriquez 0703e58 
Moises Henriquez 87ccb7b 
Moises Henriquez 4ac810a 
Moises Henriquez 0703e58 
Moises Henriquez 87ccb7b 

Moises Henriquez bc4bb28 

Moises Henriquez 0703e58 















Moises Henriquez bc4bb28 


Moises Henriquez 1f22c46 
Moises Henriquez bc4bb28 

Moises Henriquez 0703e58 







Moises Henriquez 4ac810a 

Moises Henriquez 0703e58 
Moises Henriquez 4ac810a 

Moises Henriquez 1bc4fb0 

Moises Henriquez 4ac810a 






Moises Henriquez 0703e58 
Moises Henriquez bc4bb28 
Moises Henriquez 4ac810a 

Moises Henriquez 0703e58 

Moises Henriquez bc4bb28 
Moises Henriquez 0703e58 


Moises Henriquez bc4bb28 

Moises Henriquez 87ccb7b 
Moises Henriquez 0703e58 

Moises Henriquez 4ac810a 

Moises Henriquez 1bc4fb0 
Moises Henriquez 87ccb7b 
Moises Henriquez 4ac810a 

Moises Henriquez 0703e58 


Moises Henriquez 4ac810a 
Moises Henriquez 87ccb7b 






Moises Henriquez 0703e58 

Moises Henriquez 87ccb7b 

Moises Henriquez 0703e58 
Moises Henriquez 87ccb7b 
Moises Henriquez 0703e58 


#!/usr/bin/env python

#    This file is part of vpackager.
#
#    vpackager is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v3 as published by
#    the Free Software Foundation.
#
#    vpackager is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with vpackager.  If not, see <http://www.gnu.org/licenses/>.

import gtk
import dbutils
import guitools
import message
import os

__author__ = 'M0E-lnx'
__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
__version__ = '0.1'

class TaskMenu(gtk.Menu):
    """Menu that pops up when right-clicking a task"""
    def __init__(self, selected, dbase, parent=None):
        gtk.Menu.__init__(self)
        self.selected = selected
        self._parent = parent
        self.dbase = dbase
        item_rebuild = gtk.MenuItem('Build again')
        item_rebuild.connect('activate',
                self._rebuild_event)
        item_details = gtk.MenuItem('Build Details')
        item_details.connect('activate',
                self._task_details_event)
        item_rebuild.show()
        item_details.show()
        self.append(item_rebuild)
        self.append(item_details)

    def _rebuild_event(self, widget=None):
        _id = self.selected
        _srcuri = self.dbase.GetTaskProp(_id, 'srcURI')
        #_srcuri = dbutils.GetTaskProp(_id, 'srcURI')
        if _srcuri.startswith('/'):
            if not os.path.exists(_srcuri):
                # FIXME: Source package can no longer be found
                err = message.Error(parent=self,
                        text="The source package for this job can no longer "+\
                                "be found on the system. Please specify " +\
                                "the new location of the source package")
                if err.run():
                    err.destroy()
        info = self.dbase.GetTaskDetails(_id)
        _descuri = info['descURI']
        _patches = info['patches']
        _type = info['type']
        _app = info['app']
        _ver = info['ver']
        dia = guitools.JobAddDialog()
        dia.SrcURI = _srcuri
        dia.DescURI = _descuri
        dia.appEntry.set_text(_app)
        dia.verEntry.set_text(_ver)
        dia.srcentry.set_text(_srcuri)
        dia.descEntry.set_text(_descuri)
        if _type == 'autotools':
            typeid = 1
        elif _type == 'python':
            typeid = 2
        elif _type == 'cmake':
            typeid = 3
        elif _type == 'perl':
            typeid = 4
        elif _type == 'waf':
            typeid = 5
        else:
            typeid = 0

        dia.srcTypeSel.set_active(typeid)
        #dia.cbsrcTypeSel.set_active(
        #        dia.dbsrcTypeSel.get_model())
        if _patches:
            mod = dia.patchestree.get_model()
            for patch in _patches:
                mod.append([patch])

        res = dia.run()
        dia.hide()
        if res == gtk.RESPONSE_OK:
            app = dia.app
            ver = dia.ver
            desc = dia.DescURI
            src = dia.SrcURI
            rel = dia.release
            srctype = dia.srctype
            toinstall = dia.install
            patches = ','.join(dia.patches)
            self.dbase.NewJob(app, ver, src, desc,
                    rel, srctype, toinstall, patches)
            #dbutils.NewJob(app, ver, src, desc,
            #        rel, srctype, toinstall, patches)
        dia.destroy()

    def _task_details_event(self, widget=None):
        return self._parent._task_details_event(widget)


class Main(gtk.VBox):
    ''' Container holding a treeview with convinient methods to work with the
    job history'''
    def __init__(self, dbase=None):
        if dbase:
            self.dbase = dbase
        else:
            self.dbase = dbutils.dbase()

        gtk.VBox.__init__(self)
        self._selected_jobid = None
        self.model = gtk.ListStore(
                int, str, str, str, str, str)
        self.pack_start(gtk.Label('Job History'), False, True, 2)
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_AUTOMATIC,
                gtk.POLICY_AUTOMATIC)
        self.pack_start(scroll, True, True, 2)
        scroll.add(self._get_tree())

        self.show_all()
        self.pack_start(self._get_bottom_toolbar(), False, True, 2)
        self._refresh_history_display()
        self.btWipeHistory.set_property('sensitive',
                len(self.dbase.GetHistory()) >0)

    def _task_details_event(self, widget=None):
        dia = guitools.AboutTask(self._selected_jobid,
                dbase = self.dbase)
        if dia.run():
            dia.destroy()

    def _get_bottom_toolbar(self):
        '''toolbar at the bottom of the job history'''
        box = gtk.HBox()
        btWipe = guitools.vButton(stock=gtk.STOCK_DELETE,
                label='Erase History')
        self.btWipeHistory = btWipe
        self.btTaskDetails = guitools.vButton(stock=gtk.STOCK_INFO,
                label='Build Details')
        self.btTaskDetails.connect('clicked', self._task_details_event)
        self.btWipeHistory.connect('clicked', self._do_wipe_history)
        box.pack_start(btWipe, False, False, 2)
        box.pack_start(self.btTaskDetails, False, False, 2)

        return box

    def _tree_button_press(self, widget, event):
        if event.button == 3:
            m = TaskMenu(selected = self._selected_jobid,
                    dbase = self.dbase, parent=self)
            m.popup(None, None, None, event.button, event.time)

    def _tree_click_event(self, tree=None):
        """ Events triggered by clicking on the treeview"""
        sel = tree.get_selection()
        (model, _iter) = sel.get_selected()
        selrow = tree.get_model()[_iter][0]
        self._selected_jobid = selrow
        self.btTaskDetails.set_property('sensitive',
                self._selected_jobid != None)

    def _get_tree(self):
        """ Create the treeview that displays the history"""
        self.tree = gtk.TreeView(model = self.model)
        i = 0
        for field in ('ID','Application', 'Version',
                'Build Start', 'Build End', 'Result'):
            col = gtk.TreeViewColumn(field)
            col.set_resizable(True)
            crt = gtk.CellRendererText()
            col.pack_start(crt)
            col.add_attribute(crt, 'text', i)
            self.tree.append_column(col)
            i += 1
        self.tree.connect('cursor-changed', self._tree_click_event)
        self.tree.connect('button-press-event', self._tree_button_press)
        return self.tree

    def _do_wipe_history(self, widget=None):
        """ Wipe the entire history """
        dia = message.Question(
                text='This will erase you entire build history. \n' + \
                        'Are you sure you want to continue?')
        res = dia.run()
        dia.destroy()
        if res == gtk.RESPONSE_YES:
            self.dbase.WipeHistory()
        return self._refresh_history_display()

    def _refresh_history_display(self):
        self.tree.set_model(
                gtk.ListStore(int,str, str, str, str, str))
        lst = self.dbase.GetHistory()
        for entry in lst:
            self.tree.get_model().append(entry)
        self.btWipeHistory.set_property('sensitive', (len(lst) > 0))
        self.btTaskDetails.set_property('sensitive',
                self._selected_jobid != None)

    def _exit(self, widget=None):
        try:
            self.dbase.close()
        except:
            pass
        gtk.main_quit()

if __name__ == '__main__':
    w = gtk.Window(gtk.WINDOW_TOPLEVEL)
    content = Main()
    w.add(content)
    w.set_size_request(500,300)
    w.connect('destroy', content._exit)
    w.show_all()
    gtk.gdk.threads_init()
    gtk.gdk.threads_enter()
    gtk.main()