Commits

Moises Henriquez committed 87ccb7b

Migrated database to a single class so that a single instance can be used throughout the application.

Comments (0)

Files changed (5)

src/vpackager/bot.py

 
 class Dispatcher(threading.Thread):
     """ Dispatcher thread used for dispatching jobs from the queue"""
-    def __init__(self, parent=None):
+    def __init__(self, parent=None, dbase=None):
         threading.Thread.__init__(self)
         self.name = 'job-dispatcher'
         self.parent = parent
+        if dbase:
+            self.dbase = dbase
+        else:
+            self.dbase = dbutils.dbase()
 
     def _get_next_job(self):
         ''' Get the next job in line from the database '''
-        return dbutils.GetNextJob()
+        return self.dbase.GetNextJob()
 
     def _log_job_start(self, _id):
         ''' Log the job start to the database history'''
-        return dbutils.LogJobStart(_id)
+        return self.dbase.LogJobStart(_id)
 
     def _log_job_end(self, _id, stdoutpath, result):
         ''' Log the job end to the database history'''
-        return dbutils.LogJobEnd(_id, stdoutpath, result)
+        return self.dbase.LogJobEnd(_id, stdoutpath, result)
 
     def _refresh_views(self):
         ''' Refresh the screens that show the database status '''
     def run(self):
         while self.parent._bot_run:
             time.sleep(0.25)
-            njob = dbutils.GetNextJob()
+            njob = self.dbase.GetNextJob()
             if njob is None:
                 # NO new job in queue
                 self.parent._bot_run = False
             buf = self.parent.outputplayer.get_buffer()
             buf.delete(buf.get_bounds()[0], buf.get_bounds()[1])
             _id = njob[0]
-            pkg = dbutils.GetJobProp(_id,'app')
-            ver = dbutils.GetJobProp(_id,'ver')
-            src = dbutils.GetJobProp(_id,'srcURI')
-            desc = dbutils.GetJobProp(_id, 'descURI')
-            rel = dbutils.GetJobProp(_id,'release')
-            _type = dbutils.GetJobProp(_id, 'install')
-            patches = dbutils.GetJobProp(_id, 'patches')
-            toinstall = dbutils.GetJobProp(_id,'install')
+            info = self.dbase.GetJobDetails(_id)
+            pkg = info['app']
+            ver = info['ver']
+            src = info['srcURI']
+            desc = info['descURI']
+            rel = info['release']
+            _type = info['type']
+            patches = info['patches']
+            toinstall = info['install']
             patchlist = []
             if patches:
                 patchlist = patches.split(',')
 
 class Tab(gtk.VBox):
     ''' Generic tab for use in the tabstrip '''
-    def __init__(self, label='', stock=None, parent=None):
+    def __init__(self, label='', stock=None, parent=None, dbase = None ):
         gtk.VBox.__init__(self)
+        if dbase is None:
+            self.dbase = dbutils.dbase()
+        else:
+            self.dbase = dbase
         ibox = gtk.VBox()
         img = gtk.Image()
         img.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
 class TabStatus(Tab):
     ''' Bot control and status tab '''
     def __init__(self, *args, **kwargs):
-        Tab.__init__(self, label='Bot Status', stock=gtk.STOCK_PREFERENCES,
-                **kwargs)
+        Tab.__init__(self, label='Bot Status', 
+                stock=gtk.STOCK_PREFERENCES, **kwargs)
+        #Tab.__init__(self, label='Bot Status',
+        #        stock=gtk.STOCK_PREFERENCES)
+
         topbox = gtk.HBox()
         flt = gtk.Frame('Bot Status')
         lvbox = gtk.VBox()
         self.mon_thread = threading.Thread(target=self.__bot_monitor,
                 name='vpackager-bot-monitor', args=())
         self.mon_thread.start()
-        self.jobDispatcher = Dispatcher(parent = self._parent)
+        self.jobDispatcher = Dispatcher(parent = self._parent, 
+                dbase = self.dbase)
 
     def __bot_monitor(self):
         while self._parent._bot_run:
             self.mon_thread.start()
         if not self.jobDispatcher.isAlive():
             del self.jobDispatcher
-            self.jobDispatcher = Dispatcher(parent=self._parent)
+            self.jobDispatcher = Dispatcher(parent=self._parent,
+                    dbase=self.dbase)
             self.jobDispatcher.start()
         return
 
 class TabQueue(Tab):
     """ Job queue tab. Used to manage build jobs."""
-    def __init__(self, *args, **kwargs):
+    def __init__(self, dbase=None, *args, **kwargs):
         Tab.__init__(self, label = 'Job Queue',
                 stock = gtk.STOCK_INDEX, **kwargs)
+        if not self.dbase:
+            if dbase is None:
+                self.dbase = dbutils.dbase()
+            else:
+                self.dbase = dbase
         cont = jobmanage.Main()
         self.pack_start(cont, True, True, 2)
         self._parent.queueman = cont
 
 class TabHistory(Tab):
     """ Tab displaying the job build history"""
-    def __init__(self, *args, **kwargs):
+    def __init__(self, dbase = None, *args, **kwargs):
         Tab.__init__(self, label = 'Job History',
                 stock=gtk.STOCK_JUSTIFY_FILL, **kwargs)
+        if not self.dbase:
+            if not dbase:
+                self.dbase = dbutils.dbase()
+            else:
+                self.dbase = dbase
         cont = historymanager.Main()
         self.pack_start(cont, True, True, 2)
         self._parent.historyman = cont
     """ Main app GUI """
     def __init__(self):
         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        # Load the database
+        self.dbase = dbutils.dbase()
         self.set_title('vpackager')
         self.connect('destroy', self._exit)
         datadir = os.path.dirname(os.path.abspath(__file__))
     def _get_notebook(self):
         """ Main content notebook"""
         strip = TabStrip()
-        stats = TabStatus(parent=self)
+        stats = TabStatus(parent=self, dbase = self.dbase)
         strip.append_page(stats, stats.label)
 
-        queuet = TabQueue(parent=self)
+        queuet = TabQueue(parent=self, dbase = self.dbase)
         strip.append_page(queuet, queuet.label)
 
-        history = TabHistory(parent=self)
+        history = TabHistory(parent=self, dbase = self.dbase)
         strip.append_page(history, history.label)
 
 
     def _exit(self, widget=None):
         self._stop_bot = True
         time.sleep(0.25)
+        self.dbase.close()
         return gtk.main_quit()
 
     def _check_db_sanity(self):
-        dbutils.create_vpackager_db()
+        if self.dbase.verify_tables():
+            self.dbase.CreateTables()
 
 if __name__ == '__main__':
     gtk.gdk.threads_init()

src/vpackager/dbutils.py

 
 dbpath = '/tmp/vpackager.db'
 
-def __verify_tables():
-    ''' Verify that the essential tables for the vpackager environment
-    exist'''
-    #if os.path.exists(dbpath):
-        #        os.remove(dbpath)
-    #return True
-    # FIXME: ^^^ Remove this before final release ^^
+class dbase(object):
+    """ Main database class. All operations to the job queue or history are
+    done via this class. The database must be closed on exit"""
+    def __init__(self, path = dbpath):
+        self._dbpath = path
+        self.db = sqlite3.connect(self._dbpath)
+        self.cursor = self.db.cursor()
 
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute('select name from sqlite_master where type="table"')
-    res = c.fetchall()
-    c.close()
-    db.close()
-    if len(res) > 0:
-        return False
-    return True
 
-def create_vpackager_db():
-    ''' Create the essential tables for the vpackager environment'''
-    if __verify_tables() is True:
-        __create_queue_table()
-        __create_history_table()
+    def close(self):
+        """ Completely close the database to save all data """
+        self.cursor.close()
+        self.db.close()
+
+    def verify_tables(self):
+        """Verify that the essential tables for the vpackages environemtn
+        actually exist"""
+        self.cursor.execute('''select name from sqlite_master where
+                type="table"''')
+        res = self.cursor.fetchall()
+        if len(res) > 0:
+            return False
+        return True
+
+    def CreateTables(self):
+        """Create the essential tables for the vpackager environment. Should
+        only need to be ran once"""
+        self.cursor.execute('''
+        create table queue (id integer primary key autoincrement,
+        app text,
+        ver text,
+        srcURI text,
+        descURI text,
+        release text,
+        type text,
+        install text,
+        patches text)''')
+        self.db.commit()
+
+        self.cursor.execute('''
+        create table history(id integer primary key,
+        app text, ver text, srcURI text, descURI text,
+        release text, type text, patches text, buildstart text,
+        buildend text, stdout text, result text)''')
+        self.db.commit()
+
         return
-    return
 
-def __create_queue_table():
-    """ Create the job queue table. NEVER to be called from the program
-    itself!"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute("""create table queue
-    (id integer primary key autoincrement,
-    app text, ver text, srcURI text, descURI text, release text, type text,
-    install text, patches text)""")
-    db.commit()
-    c.close()
-    db.close()
+    def NewJob(self, app, ver, srcURI, descURI, release, _type,
+            install, patches):
+        """ Add a new job to the job queue"""
+        t = (app, ver, srcURI, descURI, release, _type, install, patches)
+        self.cursor.execute('''
+        insert into queue (app, ver, srcURI, descURI, release, type,
+        install, patches) values (?,?,?,?,?,?,?,?)''', t)
+        self.db.commit()
+        return
 
-    return
+    def DeleteJob(self, job_id):
+        """ Removes job_id from the job queue"""
+        t = (job_id,)
+        self.cursor.execute('''
+        delete from queue where id=?''',t)
+        self.db.commit()
+        return
 
-def __create_history_table():
-    """ Create the job history table. NEVER to be called from the program
-    itself!"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    # The id integer comes from the job queue table, so we can have some
-    # consistancy here.
-    c.execute("""
-    create table history
-    (id integer primary key,
-    app text,
-    ver text,
-    srcURI text,
-    descURI text,
-    release text,
-    type text,
-    patches text,
-    buildstart text,
-    buildend text,
-    stdout text,
-    result text)"""
-    )
+    def LogJobStart(self, job_id):
+        """ Moves a job from the queue to the history and adds the timestamp to
+        the corresponding to the time the job started"""
+        t = (job_id,)
+        self.cursor.execute('''
+        select id, app, ver, srcURI, descURI, release, type from queue where
+        id=?''',t)
+        res = self.cursor.next()
+        self.cursor.execute('''
+        insert into history (id, app, ver, srcURI, descURI, release, type,
+        buildstart, result) values (?,?,?,?,?,?,?,CURRENT_TIMESTAMP,
+        'Running')''', res)
+        self.cursor.execute('delete from queue where id=?', t)
+        self.db.commit()
+        return
 
-    db.commit()
-    c.close()
-    db.close()
+    def LogJobEnd(self, job_id, stdoutpath, result):
+        """ Update the job history to log timestamp when the job ended and the
+        result of the build"""
+        t = (job_id,)
+        self.cursor.execute('''
+        update history set buildend=CURRENT_TIMESTAMP where id=?''',t)
+        t = (stdoutpath, job_id)
+        self.cursor.execute('''
+        update history set stdout=? where id=?''',t)
+        t = (result, job_id)
+        self.cursor.execute('''
+        update history set result=? where id=''',t)
 
-    return
+        self.db.commit()
+        return
 
-def NewJob(app, ver, srcURI, descURI, release, _type, install,
-        patches):
+    def GetJobProp(self, job_id, prop):
+        """ Returns job_id's property (prop) """
+        self.cursor.execute('''select % from queue where id=%s'''% (prop,
+            job_id))
+        try:
+            ret = self.cursor.next()
+        except StopIteration:
+            ret = None
+        if ret:
+            return ret[0]
+        return None
 
-    """ Add a job to the job queue"""
-    db = sqlite3.connect(dbpath)
-    t = (app, ver, srcURI, descURI, release, _type, install, patches)
-    c = db.cursor()
-    c.execute("""insert into queue (app, ver, srcURI, descURI, release, Type,
-    install, patches) values (?,?,?,?,?,?,?,?)""", t)
+    def GetTaskProp(self, job_id, prop):
+        """ Return job_id's (prop) property on a performed task. This
+        information comes from the build history"""
+        self.cursor.execute('''select %s from history where id=%s'''% (prop,
+            job_id))
+        try:
+            ret = self.cursor.next()
+        except StopIteration:
+            ret = None
 
-    db.commit()
-    c.close()
-    db.close()
+        if ret:
+            return ret[0]
+        return None
 
-def RemoveJob(_id):
-    """ Delete a job from the job queue"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    t = (_id,)
-    c.execute('delete from queue where id=?', t)
-    db.commit()
-    c.close()
-    db.close()
+    def GetTaskDetails(self, job_id):
+        """ Returns all information from the job history about job_id in the
+        form of a dictionary"""
+        retval = {}
+        t = (job_id,)
+        self.cursor.execute('''select * from history where id=?''',t)
+        try:
+            ret = self.cursor.next()
+        except StopIteration:
+            ret = None
+        if ret:
+            retval['id'] = ret[0]
+            retval['app'] = ret[1]
+            retval['ver'] = ret[2]
+            retval['srcURI'] = ret[3]
+            retval['descURI'] = ret[4]
+            retval['release'] = ret[5]
+            retval['type'] = ret[6]
+            retval['patches'] = ret[7]
+            retval['buildstart'] = ret[8]
+            retval['buildend'] = ret[9]
+            retval['stdout'] = ret[10]
+            retval['result'] = ret[11]
+        else:
+            retval = {}
 
-def LogJobStart(jobid):
-    """ Move job from queue to history and add the timestamp to the buidl
-    start"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    t = (jobid,)
-    c.execute('''select id,app,ver,srcURI,descURI,release,type from queue where
-    id=?''',t)
-    res = c.next()
-    c.execute('''insert into history (id,app,ver,srcURI,descURI,
-    release,type,buildstart,result)
-    values (?,?,?,?,?,?,?,CURRENT_TIMESTAMP,'Running')''',res)
-    t = (jobid,)
-    c.execute('delete from queue where id=?',t)
-    c.close()
-    db.commit()
-    db.close()
+        return retval
 
-def LogJobEnd(jobid, stdoutpath, result):
-    """ Update the job history to log the end time and end result of the
-    build."""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    t = (jobid,)
-    c.execute('''update history set buildend=CURRENT_TIMESTAMP where
-            id=?''',t)
-    t = (stdoutpath, jobid)
-    c.execute('''update history set stdout=? where id=?''',t)
-    t = (result, jobid)
-    c.execute('''update history set result=? where id=?''',t)
-    c.close()
-    db.commit()
-    db.close()
+    def GetJobDetails(self, job_id):
+        """ Returns all the information from the job queue about job_id in the
+        form of a dictionary"""
+        retval = {}
+        t = (job_id,)
+        self.cursor.execute('select * from queue where id=?',t)
+        try:
+            ret = self.cursor.next()
+        except StopIteration:
+            ret = None
 
-def GetJobPatches(jobID):
-    t = (jobID,)
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute('select patches from queue where id=?',t)
-    try:
-        ret = c.next()
-    except StopIteration:
-        ret = None
-    c.close()
-    db.close()
-    return ret
+        if ret:
+            retval['id'] = ret[0]
+            retval['app'] = ret[1]
+            retval['ver'] = ret[2]
+            retval['srcURI'] = ret[3]
+            retval['descURI'] = ret[4]
+            retval['release'] = ret[5]
+            retval['type'] = ret[6]
+            retval['install'] = ret[7]
+            retval['patches'] = ret[8]
+        else:
+            retval = {}
 
-def GetJobProp(jobid, prop):
-    ''' Returns jobid's propperty (prop) '''
-    t = (prop,jobid)
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute('select %s from queue where id=%s'%(prop, jobid))
-    try:
-        ret = c.next()
-    except StopIteration:
-        ret = None
-    c.close()
-    db.close()
-    if ret:
-        return ret[0]
-    return None
+        return retval
 
-def GetTaskProp(taskid, prop):
-    """ Returns Taskid's property (prop) """
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute('select %s from history where id=%s'% (prop,taskid))
-    try:
-        ret = c.next()
-    except StopIteration:
-        ret = None
-    c.close()
-    if ret:
-        return ret[0]
-    return None
+    def GetNextJob(self):
+        """ Find the next job in line to be built.
+        Returns the jobid for the next job"""
+        self.cursor.execute('select id from queue')
+        try:
+            ret = c.next()
+        except StopIteration:
+            ret = None
 
-def GetTaskDetails(jobid):
-    """ Returns all information from the job history about jobid"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    t = (jobid,)
-    c.execute('select * from history where id=?',t)
-    try:
-        ret = c.next()
-    except StopIteration:
-        ret = None
-    c.close()
-    db.close()
-    return ret
+        return ret
 
-def GetNextJob():
-    """ Find the next job in line to be built"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    c.execute('select id from queue')
-    try:
-        ret = c.next()
-    except StopIteration:
-        ret = None
-    c.close()
-    db.close()
-    return ret
+    def GetQueue(self):
+        """ Returns a list of all pending jobs """
+        self.cursor.execute('''select id, app, ver, release from queue''')
+        ret = self.cursor.fetchall()
+        return ret
 
-def GetQueue():
-    """ Return a list of all pending jobs"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    ret = c.execute('select id,app,ver,release from queue').fetchall()
-    #ret = c.execute('select * from queue').fetchall()
-    c.close()
-    db.close()
-    return ret
+    def GetHistory(self):
+        """ Returns alist of all the processed jobs in the job history"""
+        self.cursor.execute('''
+        select id, app, ver, buildstart, buildend, result from history''')
+        return self.cursor.fetchall()
 
-def GetHistory():
-    """ Return a list of all processed jobs"""
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    ret = c.execute('\
-            select id,app,ver,buildstart,buildend,result \
-            from history').fetchall()
-    #ret = c.execute('select * from history').fetchall()
-    c.close()
-    db.close()
-    return ret
+    def WipeHistory(self):
+        """ Deletes the entire job history. Only use after confirming with the
+        user"""
+        self.cursor.execute('''delete from history where id > 0''')
+        return
 
-def WipeHistory():
-    """ Delete the entire build history """
-    db = sqlite3.connect(dbpath)
-    c = db.cursor()
-    ret = c.execute('delete from history where id > 0')
-    c.close()
-    db.close()
-    return
 
 
+
+

src/vpackager/guitools.py

     '''Dialog used to display detailed information about a build job. The user
     interface will not display every detail about the job, but this dialog
     will.'''
-    def __init__(self, jobid=None, title='Job Details', parent=None):
+    def __init__(self, jobid=None, title='Job Details', parent=None, dbase=None):
         gtk.Dialog.__init__(self, parent=parent)
+        if dbase:
+            self.dbase = dbase
+        else:
+            self.dbase = dbutils.dbase()
         self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
         self.body = self.get_content_area()
         lbtop = gtk.Label()
         topbox = gtk.HBox()
         img = gtk.Image()
+        self.set_has_separator(True)
         img.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
-        #img = gtk.image.new_from_stock(gtk.STOCK_INFO,
-        #        gtk.ICON_SIZE_DIALOG)
         topbox.pack_start(img, False, False, 2)
         lbtop.set_markup('<b>Job Details</b>')
         lbtop.set_property('xalign', 0.0)
         sw = gtk.ScrolledWindow()
         sw.set_policy(gtk.POLICY_AUTOMATIC,
                 gtk.POLICY_AUTOMATIC)
-
         mod = gtk.ListStore(str, str)
         tree = gtk.TreeView(model=mod)
         col0 = gtk.TreeViewColumn()
         col1 = gtk.TreeViewColumn()
         cr1 = gtk.CellRendererText()
         col1.pack_start(cr1)
-        col1.add_attribute(cr1, 'text', 1)
+        col1.add_attribute(cr1, 'markup', 1)
         tree.append_column(col0)
         tree.append_column(col1)
+        tree.set_headers_visible(False)
         sw.add(tree)
 
-        # Fill in the informmation:
-        info = self._get_job_details(self._jobid)
-        patches = info['patches'].split(',')
-        mod.append(['<b>Job ID</b>', info['id']])
-        mod.append(['<b>Application</b>', info['app']])
-        mod.append(['<b>Version</b>', info['ver']])
-        mod.append(['<b>Source URI</b>', info['src']])
-        mod.append(['<b>Description URI</b>', info['desc']])
-        mod.append(['<b>Package Release</b>', info['release']])
-        mod.append(['<b>Source Type</b>', info['type']])
-        mod.append(['<b>Install after build</b>', info['install']==1])
-        mod.append(['<b>Patches to be applied</b>', patches[0]])
-        for x in range(1,len(patches)):
-            mod.append(['',patches[x]])
-
-
+        # Fill in the information
+        info = self.dbase.GetJobDetails(self._jobid)
+        patches = info['patches']
+        patchlist = []
+        if patches:
+            patchlist = patches.split(',')
+        mod.append(['Job ID', info['id']])
+        mod.append(['Application', info['app']])
+        mod.append(['Version', info['ver']])
+        mod.append(['Package Release', info['release']])
+        mod.append(['Source URI', info['srcURI']])
+        mod.append(['Description URI', info['descURI']])
+        mod.append(['Source Type', info['type']])
+        mod.append(['Install After Build', info['install']==1])
+        if patchlist:
+            mod.append(['Patches to be applied', patchlist[0]])
+            for x in range(1, len(patchlist)):
+                mod.apend(['',patchlist[x]])
+        else:
+            mod.append(['Patches to be applied', 'None'])
 
         return sw
 
-    def _get_job_details(self, jobid, fromtable='queue'):
-        ''' Retreive details from the database '''
-        info = {}
-        info['id'] = dbutils.GetJobProp(jobid, 'id')
-        info['app'] = dbutils.GetJobProp(jobid, 'app')
-        info['ver'] = dbutils.GetJobProp(jobid, 'ver')
-        info['src'] = dbutils.GetJobProp(jobid, 'srcURI')
-        info['desc'] = dbutils.GetJobProp(jobid, 'descURI')
-        info['release'] = dbutils.GetJobProp(jobid, 'release')
-        info['type'] = dbutils.GetJobProp(jobid, 'type')
-        info['install'] = dbutils.GetJobProp(jobid, 'install')
-        info['patches'] = dbutils.GetJobProp(jobid, 'patches')
-        return info
-
 class AboutTask(gtk.Dialog):
-    """Info dialog used to diaplsy details about a performed job. Similar to
-    AboutJob, but the information for this one comes from the job history (as
-    in past jobs) rather than the queue (to-do list)"""
-    def __init__(self, jobid, title='Task Details', parent=None):
+    """ Informational dialog used to display details about a performed task.
+    Similar to AboutJob, but the information for this one comes from the
+    history table rather than the queue"""
+    def __init__(self, jobid, dbase, title='Task Details', parent=None):
         gtk.Dialog.__init__(self, parent=parent)
+        self.jobid = jobid
+        self.dbase = dbase
         self.set_title(title)
         self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
         self.body = self.get_content_area()
         img.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
         lbl = gtk.Label()
         lbl.set_markup('<b>Build task details</b>')
+        lbl.set_property('xalign', 0.0)
         topbox.pack_start(img, False, False, 2)
         topbox.pack_start(lbl, True, True, 2)
-        lbl.set_property('xalign', 0.0)
         self.body.pack_start(topbox, False, True, 4)
-        self._selected_jobid = jobid
-
+        self.set_has_separator(True)
+        self.set_size_request(500, 400)
         self.body.pack_start(self._get_tree(), True, True, 2)
-        self.set_size_request(500,400)
-
         self.show_all()
 
     def _get_tree(self):
         scroll = gtk.ScrolledWindow()
-        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        scroll.set_policy(gtk.POLICY_AUTOMATIC,
+                gtk.POLICY_AUTOMATIC)
         mod = gtk.ListStore(str, str)
-        tree = gtk.TreeView(model=mod)
         col0 = gtk.TreeViewColumn()
+        cr0 = gtk.CellRendererText()
         col1 = gtk.TreeViewColumn()
-        cr0 = gtk.CellRendererText()
         cr1 = gtk.CellRendererText()
         col0.pack_start(cr0)
         col1.pack_start(cr1)
         col0.add_attribute(cr0, 'markup', 0)
         col1.add_attribute(cr1, 'markup', 1)
+        tree = gtk.TreeView(model = mod)
+        tree.set_headers_visible(False)
         tree.append_column(col0)
         tree.append_column(col1)
-        tree.set_headers_visible(False)
 
-        # Get the data we need
-        jobid = self._selected_jobid
-        (_id, app, ver, src, desc, rel,
-                _type, patches, buildstart,
-                buildend, stdout, result) = dbutils.GetTaskDetails(jobid)
-        # Add the data to the model
-        mod.append(['Job ID', _id])
-        mod.append(['Application', app])
-        mod.append(['Version', ver])
-        mod.append(['Package Release', rel])
-        mod.append(['Source URI', src])
-        mod.append(['Description URI', desc])
-        mod.append(['Source type', _type])
-        mod.append(['Build started', buildstart])
-        mod.append(['Build ended', buildend])
-        mod.append(['Build result', result])
-        mod.append(['Output log', stdout])
+        # Fill the data
+        info = self.dbase.GetTaskDetails(self.jobid)
+        patches = info['patches']
+        mod.append(['Job ID', info['id']])
+        mod.append(['Application', info['app']])
+        mod.append(['Version', info['ver']])
+        mod.append(['Package Release', info['release']])
+        mod.append(['Source URI', info['srcURI']])
+        mod.append(['Description URI', info['descURI']])
+        mod.append(['Source Type', info['type']])
+        mod.append(['Build Started', info['buildstart']])
+        mod.append(['Build Ended', info['buildend']])
+        mod.append(['Build Result', info['result']])
+        mod.append(['Output Log', info['stdout']])
         if patches:
-            lpatches = patches.split(',')
-            mod.append(['Patches applied', lpatches[0]])
-            for x in range(1, len(lpatches)):
-                mod.append(['',lpatches[x]])
+            patchlist = patches.split(',')
+            patchlist = (['Patches Applied', patchlist[0]])
+            for x in range(1, len(patchlist)):
+                mod.append(['',patchlist[x]])
+        else:
+            mod.append(['Patches Applied', 'None'])
 
         scroll.add(tree)
+        return scroll
 
 
 
-        return scroll
 
 class About(gtk.AboutDialog):
     """ About dialog for vpackager"""
 
 
 
+

src/vpackager/historymanager.py

 class Main(gtk.VBox):
     ''' Container holding a treeview with convinient methods to work with the
     job history'''
-    def __init__(self):
+    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(
         self.pack_start(self._get_bottom_toolbar(), False, True, 2)
         self._refresh_history_display()
         self.btWipeHistory.set_property('sensitive',
-                len(dbutils.GetHistory()) > 0)
+                len(self.dbase.GetHistory()) >0)
 
     def _task_details_event(self, widget=None):
-        dia = guitools.AboutTask(self._selected_jobid)
+        dia = guitools.AboutTask(self._selected_jobid,
+                dbase = self.dbase)
         if dia.run():
             dia.destroy()
 
         res = dia.run()
         dia.destroy()
         if res == gtk.RESPONSE_YES:
-            dbutils.WipeHistory()
+            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 = dbutils.GetHistory()
+        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)
-    w.add(Main())
+    content = Main()
+    w.add(content)
     w.set_size_request(500,300)
-    w.connect('destroy', gtk.main_quit)
+    w.connect('destroy', content._exit)
     w.show_all()
     gtk.gdk.threads_init()
     gtk.gdk.threads_enter()

src/vpackager/jobmanage.py

 
 class Main(gtk.VBox):
     '''job manager main container'''
-    def __init__(self):
+    def __init__(self, dbase=None):
         gtk.VBox.__init__(self)
+        if dbase:
+            self.dbase = dbase
+        else:
+            self.dbase = dbutils.dbase()
+
         hbtop = gtk.HBox()
         self.pack_start(hbtop, False, True, 4)
         lbtop = gtk.Label('Manage job queue')
 
     def _job_details_event(self, widget=None):
         ''' Pop-up the job info dialog'''
-        dia = guitools.AboutJob(jobid = self._selected_jobid)
+        dia = guitools.AboutJob(dbase = self.dbase,
+                jobid = self._selected_jobid)
         if dia.run():
             dia.destroy()
 
             toinstall = dia.install
             patches = ','.join(dia.patches)
             dia.destroy()
-            dbutils.NewJob(app, ver, srcuri, desc,
+            self.dbase.NewJob(app, ver, scruri, desc,
                     rel, srctype, toinstall, patches)
             return self._update_queue()
 
     def _btDeleteClick(self, widget=None):
         '''Delete the selected job from the job queue'''
         if self._selected_jobid:
-            dbutils.RemoveJob(self._selected_jobid)
+            self.dbase.DeleteJob(self._selected_jobid)
             self._update_queue()
 
     def _update_queue(self):
         '''Refresh the GUI displaying the job queue'''
         self.tree.set_model(gtk.ListStore(int,str, str, str))
-        lst = dbutils.GetQueue()
+        lst = self.dbase.GetQueue()
         for entry in lst:
             self.tree.get_model().append(entry)
 
 
     def _fill_tree_with_queue(self):
         tm = self.tree.get_model()
-        q = dbutils.GetQueue()
+        q = self.dbase.GetQueue()
         for item in q:
             tm.append(item)
 
+    def _exit(self, widget=None):
+        try:
+            self.dbase.close()
+        except:
+            pass
+        gtk.main_quit()
+
 if __name__ == '__main__':
     w = gtk.Window(gtk.WINDOW_TOPLEVEL)
-    w.connect('destroy', gtk.main_quit)
+    content = Main()
+    w.connect('destroy', content._exit)
     w.set_title('Job Queue Manager')
     w.set_size_request(600, 400)
-    w.add(Main())
+    #content = Main()
+    w.add(content)
     w.show_all()
     gtk.gdk.threads_init()
     gtk.gdk.threads_enter()