Commits

Moises Henriquez  committed e24c4dd

initial commit

  • Participants

Comments (0)

Files changed (3)

+#!/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 v2 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 os
+import subprocess as sp
+import dbconn as db
+
+buildproc = None
+
+class AutoTools(object):
+    def __init__(self, srcpath, app, version):
+        self.path = srcpath
+        self.config = ['--prefix=/usr',
+            '--sysconfdir=/etc', '--mandir=/usr/man',
+            '--disable-debug']
+        if os.uname()[-1] == 'x86_64':
+            self.cflags = '-O2 -fpic'
+            self.arch = os.uname()[-1]
+        elif os.uname()[-1] in ('i386', 'i486', 'i586', 'i686'):
+            self.arch = 'i586'
+            self.cflags = '-O2 -march=i586 -mtune=i686'
+        elif os.uname()[-1] == 'powerpc':
+            self.cflags='-O2'
+            self.arch = os.uname()[-1]
+        self.path = srcpath
+        self.workdir = os.path.join(srcpath, '%s-%s'%(app, version))
+        self.app = app
+        self.version = version
+
+    def _open_log(self):
+        self.log = open(os.path.join(self.path, 'bbot_build.log'), 'a')
+    def _close_log(self):
+        return self.log.close()
+    def do_log(self, log):
+        self._open_log()
+        self.log.write(log)
+        self._close_log()
+        
+    def configure(self):
+        os.chdir(self.workdir)
+        cstr = './configure ' + ' '.join(self.config)
+        buildproc = sp.Popen(cstr.split(), stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = buildproc.communicate()[0]
+        self.do_log(output)
+        return buildproc.returncode
+    
+    def compile(self):
+        os.chdir(self.workdir)
+        buildproc = sp.Popen([
+            'make'], stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = buildproc.communicate()[0]
+        self.do_log(output)
+        return buildproc.returncode
+    
+    def mkinstall(self):
+        os.chdir(self.workdir)
+        pkg = os.path.join(self.workdir, 'PKG')
+        os.makedirs(pkg)
+        self.pkgdir = pkg
+        buildproc = sp.Popen([
+            'make','DESTDIR=%s'% pkg, 'install'],
+            stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = buildproc.communicate()[0]
+        self.do_log(output)
+        return buildproc.returncode
+    def package(self, buildno='1', tag=''):
+        pkgdir = os.path.join(self.workdir, 'PKG')
+        try :
+            os.makedirs(pkgdir)
+        except :
+            pass
+        self.pkgdir = pkgdir
+        os.chdir(self.pkgdir)
+        pname = '%s-%s-%s-%s%s.%s'% (
+            self.app, self.version, self.arch, buildno, tag, 'tlz')
+            
+        buildproc = sp.Popen(['makepkg', '-p', '-l', 'y', '-c', 'n',
+            os.path.join(self.path, pname)],
+            stdout = sp.PIPE, stderr=sp.STDOUT)
+        output = buildproc.communicate()[0]
+        self.do_log(output)
+        return buildproc.returncode
+    
+class AutoMake(AutoTools):
+    def __init__(self, srcpath, app, version):
+        AutoTools.__init__(self, srcpath, app, version)
+    
+    def configure(self):
+        ### Goes straight to make, so always return 0
+        return 0
+
+class Python(object):
+    def __init__(self, srcpath, app, version):
+        self.path = srcpath
+        #self.workdir = srcpath
+        self.workdir = os.path.join(srcpath, '%s-%s'%(app, version))
+        #self.tmpdir = os.path.join(srcpath, '%s-%s'%(app,version))
+        ### Open the build log and leave the stream open for the rest of the
+        ### build process
+        self.app = app
+        self.version = version
+        #self.log = open(os.pardir.join(srcpath, 'bbot_build.log'), 'a')
+    
+    def _open_log(self):
+        self.log = open(os.path.join(self.path, 'bbot_build.log'), 'a')
+    def _close_log(self):
+        return self.log.close()
+    def do_log(self, log):
+        self._open_log()
+        self.log.write(log)
+        self._close_log()
+    def configure(self):
+        self._open_log()
+        os.chdir(self.workdir)
+        buildproc = sp.Popen(['python', 'setup.py', 'build'],
+            stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = ''.join(buildproc.stdout.readlines())
+        self.do_log(output)
+        return buildproc.returncode
+    def compile(self):
+        return 0
+    def mkinstall(self):
+        pkg = os.path.join(self.workdir, 'PKG')
+        os.makedirs(pkg)
+        self.pkgdir = pkg
+        os.chdir(self.workdir)
+        #os.chdir(self.pkgdir)
+        buildproc = sp.Popen(['python', 'setup.py', 'install',
+        '--root=%s'% self.pkgdir], stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = ''.join(buildproc.stdout.readlines())
+        self.do_log(output)
+        return buildproc.returncode
+    def package(self, buildno='1', tag=''):
+        arch = os.uname()[-1]
+        if arch in ('i386', 'i486', 'i586', 'i686'):
+            arch = 'i586'
+        os.chdir(self.pkgdir)
+        pkgname = '%s-%s-%s-%s%s.%s'% (
+            self.app, self.version, arch, buildno, tag, 'tlz')
+        buildproc = sp.Popen(
+            ['makepkg', '-p', '-l', 'y', '-c', 'n',
+            os.path.join(self.path, pkgname)], 
+            stdout=sp.PIPE, stderr=sp.STDOUT)
+        output = ''.join(buildproc.stdout.readlines())
+        self.do_log(output)
+        return buildproc.returncode
+
+    
+        
+class Source(object):
+    def __init__(self, path, app='', version=''):
+        tmpdir='/tmp/bbot'
+        self.path = path
+        
+        self.buildtool = None
+        split=self._split_filename()
+        self.app = app
+        self.version = version
+        if not app: self.app = split[0]
+        if not version: self.version = split[1]
+        self.srcpath = os.path.join(tmpdir, self.app, self.version)
+        self.type = self._get_type()
+    def configure(self):
+        return self.buildtool.configure()
+    def compile(self):
+        return self.buildtool.compile()
+    def mkinstall(self):
+        return self.buildtool.mkinstall()
+    def package(self):
+        return self.buildtool.package()
+    
+
+    
+    
+    def _split_filename(self):
+        fn = os.path.split(self.path)[-1]
+        sp = os.path.splitext(fn)
+        if sp[0].endswith('.tar'):
+            rname = sp[0][:-4]
+        return rname.rsplit('-',2)
+        
+        
+    def get_type(self):
+        return self.type
+        
+    def _get_type(self):
+        l = sp.Popen([
+            'tar', '-tf', self.path], stdout=sp.PIPE,
+            stderr=sp.PIPE).communicate()[0]
+        if 'configure' in l:
+            self.buildtool = AutoTools(self.srcpath, self.app, self.version)
+            return 'autotools'
+        if 'Makefile' in l:
+            self.buildtool = AutoMake(self.srcpath, self.app, self.version)
+            return 'automake'
+        if 'setup.py' in l:
+            self.buildtool = Python(self.srcpath, self.app, self.version)
+            return 'python'
+        return None
+    
+    def extract(self, dir=''):
+        if not dir: dir = self.srcpath
+        if not os.path.isdir(self.srcpath): os.makedirs(self.srcpath)
+        self.logfile = os.path.join(self.srcpath, 'bbot_build.log')
+        self.logstream = open(self.logfile, 'w')            
+        
+        ext = os.path.splitext(self.path)[-1]
+        if ext in ('.gz', '.bz2'):
+            buildproc = sp.Popen(['tar', 'xfv', self.path, '-C', dir],
+            stdout=sp.PIPE, stderr=sp.STDOUT)
+            output = buildproc.communicate()[0]
+            self.logstream.write(output)
+            self.logstream.close()
+           
+            return buildproc.returncode
+
+    def log_build_activity(self, result):
+        stdout = self.logfile
+        srcpath = self.path
+        res = result
+        
+        return db.log_build_attempt(srcpath, stdout, result)
+    
+#!/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 v2 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 threading
+import time
+import gobject
+import gtk
+import bbot
+import dbconn
+
+gtk.gdk.threads_init()
+todo = dbconn.refresh_todo()
+
+_busy = False
+class Monitor(threading.Thread):
+    def __init__(self, label):
+        super(Monitor, self).__init__()
+        self.label = label
+        self.quit = False
+        global _busy
+        
+    def update_label(self, txt):
+        self.label.set_text(txt)
+        #return False
+    
+    def run(self):
+        counter = 0
+        global _busy
+        while _busy is True:
+           gobject.idle_add(self.update_label,'Working')
+         
+           time.sleep(1)
+
+        gobject.idle_add(self.update_label,'Idle')
+        time.sleep(1)
+        
+
+class tbp(threading.Thread):
+    def __init__(self, src):
+        global _busy
+        global w
+        super(tbp, self).__init__()
+        self.src = src
+        _busy  = True
+
+        ### Take a split second to log the activity to the database
+        sql = 'INSERT INTO en_history (srcpath, buildstart, result)' + \
+        " values ('%s',%s,'Running')"% (src.path, 'CURRENT_TIMESTAMP')
+        dbconn.push_data(sql)
+        ### Another update is made when the process ends in exit_build
+        
+    def supdate(self, txt):
+        w.info_label1.set_text(txt)
+        w.info_label2.set_text(self.src.app)
+        #return False
+    def run(self):
+        global _busy
+        
+        gobject.idle_add(self.supdate,'Extracting')
+        if self.src.extract() > 0:
+            _busy = False
+        
+            gobject.idle_add(self.supdate,'Etraction error')
+            return self.exit_build('Fail', 1)
+        
+        gobject.idle_add(self.supdate, 'Running configure')
+        if self.src.configure() > 0:
+            _busy = False
+        
+            gobject.idle_add(self.supdate, 'configure error')
+            return self.exit_build('Fail', 1)
+        
+        gobject.idle_add(self.supdate, 'RUnning make')
+        if self.src.compile() > 0:
+            _busy = False
+        
+            gobject.idle_add(self.supdate, 'Compilation error')
+            return self.exit_build('Fail', 1)
+        
+        gobject.idle_add(self.supdate, 'Installing')
+        if self.src.mkinstall() > 0:
+            _busy = False
+        
+            gobject.idle_add(self.supdate, 'installation error')
+            return self.exit_build('Fail', 1)
+        
+        gobject.idle_add(self.supdate, 'Packaging')
+        if self.src.package() > 0:
+            _busy = False
+        
+            gobject.idle_add(self.supdate, 'Error packaging')
+            return self.exit_build('Fail', 1)
+        
+        gobject.idle_add(self.supdate, 'Packaged')
+        
+        _busy = False
+        return self.exit_build('Success', 0)
+        
+        
+    def exit_build(self, result, retval):
+        logfile = self.src.logfile
+
+
+        sql = 'UPDATE en_history SET stdout="%s", buildend=%s, result="%s" WHERE srcpath="%s" AND result="Running"'%(logfile,
+        'CURRENT_TIMESTAMP',result, self.src.path)
+        
+        sql2 = 'DELETE FROM todo WHERE srcpath="%s"'% self.src.path
+
+        dbconn.push_data(sql)  ## Update status to finished with result
+        dbconn.push_data(sql2) ## Remove from todo list
+    
+        return retval
+        
+
+class dispatcher(threading.Thread):
+    def __init__(self):
+        global todo
+        global _busy
+        super(dispatcher, self).__init__()
+
+    def run(self):
+        global todo
+        global _busy
+        for task in todo:
+            src = bbot.Source(task[1])
+            while _busy is True:
+                time.sleep(1)
+            threaded_build = tbp(src)
+            print '[dispatch] %s'% task[1]
+            threaded_build.start()
+        #print 'Finished building'
+
+    def update_status(self, status):
+        w.info_label3.set_text(status)
+class gui(gtk.Window):
+    def __init__(self):
+        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        body = gtk.VBox(False, 4)
+        self.add(body)
+        
+        banner = gtk.Label('This is a build bot')
+        body.pack_start(banner, 0, 0, False)
+        
+        srcline = gtk.HBox(False, 4)
+        src_lbl = gtk.Label('Pick Source Archive')
+        srcline.pack_start(src_lbl, False)
+        src_input = gtk.Entry()
+        self.pathbox = src_input
+        srcline.pack_start(src_input,True)
+        bt_load_src = gtk.Button(stock=gtk.STOCK_OPEN)
+        bt_load_src.connect('clicked', self.bt_load_src_click)
+        srcline.pack_start(bt_load_src, False)
+        
+        body.pack_start(srcline, 0, 0, True)
+
+        info_area = gtk.Frame('About Selection')
+        blank1=gtk.Label()
+        blank2 = gtk.Label()
+        self.info_label1 = gtk.Label('No source has been selected')
+        self.info_label2 = gtk.Label()
+        self.info_label3 = gtk.Label()
+        area = gtk.VBox(False, 4)
+        area.pack_start(blank1)
+        area.pack_start(self.info_label1)
+        area.pack_start(self.info_label2)
+        area.pack_start(self.info_label3)
+        area.pack_start(blank2)
+        
+        
+        info_area.add(area)
+        
+        btgo = gtk.Button('GO')
+        btgo.connect('clicked', self.start_build)
+        body.pack_start(btgo, 0, 0, False)
+        body.pack_start(info_area, 0, 0, True)
+        self.connect('destroy', gtk.main_quit)
+    def start_build(self, widget):
+        dispatch = dispatcher()
+        dispatch.start()
+
+    def bt_load_src_click(self, widget):
+        dia = gtk.FileChooserDialog(title='Select source file',
+            parent = self, buttons=(gtk.STOCK_OPEN,
+            gtk.RESPONSE_OK,
+            gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        dia.set_default_response(gtk.RESPONSE_OK)
+        
+        flt = gtk.FileFilter()
+        flt.set_name('Compressed Archives')
+        flt.add_pattern('*.tar.*')
+        
+        dia.add_filter(flt)
+        res = dia.run()
+        if res == gtk.RESPONSE_OK:
+            self.pathbox.set_text(dia.get_filename())
+            self.info_label1.set_property('xalign', 0.5)
+            self.info_label2.set_property('label', '')
+            self.info_label3.set_property('label', '')
+            self.info_label1.set_property('label', 'Loading information...')
+            gobject.idle_add(self.update_src_about, dia.get_filename())
+            
+        else:
+            self.pathbox.set_text('')
+        
+        dia.destroy()
+    
+    def update_src_about(self, path):
+        self.src = bbot.Source(path)
+        self.info_label1.set_property('use-markup', True)
+        self.info_label2.set_property('use-markup', True)
+        self.info_label3.set_property('use-markup', True)
+        self.info_label1.set_property('xalign', 0.0)
+        self.info_label2.set_property('xalign', 0.0)
+        self.info_label3.set_property('xalign', 0.0)
+        self.info_label1.set_property('label', 
+            '<b>Application: </b>%s'% self.src.app)
+        self.info_label2.set_property('label', 
+            '<b>Version: </b>%s'% self.src.version)
+        self.info_label3.set_property('label',
+            '<b>Source Type: </b>%s'% self.src.type)
+
+class mWindow(gtk.Window):
+    def __init__(self):
+        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        self.set_property('title', 'buildbot')
+        body = gtk.VBox(False, 4)
+        banner = gtk.Label()
+        banner.set_property('use-markup', True)
+        banner.set_property('label', 'Welcome to the buildbot')
+        banner.set_property('xalign', 0.0)
+        
+        body.pack_start(banner, False, False, 4)
+        blank = gtk.Label()
+        body.pack_start(blank, False, False, 4)
+        frm_todo = gtk.Frame('Scheduled Builds')
+        ### ------------------ Scheduled builds list -------------------##
+        frm_todo_int = gtk.VBox(False, 4)
+        
+        sw = gtk.ScrolledWindow()
+        
+        treestore = gtk.TreeStore(str, str, str)
+        self._todo_list = treestore
+        #treestore.append(None, ['0','Task 1', 'Description Path'])
+        #treestore.append(None,['1','Task 2', 'Description Path'])
+        
+        ## Get the todo list from the database:
+        _lst = dbconn.refresh_todo()
+        for row in _lst:
+            treestore.append(None, [row[0], row[1], row[2]])
+
+        tv = gtk.TreeView(treestore)
+        col = gtk.TreeViewColumn('Task ID')
+        col1 = gtk.TreeViewColumn('Source URI')
+        col2 = gtk.TreeViewColumn('Description URI')
+        tv.append_column(col)
+        tv.append_column(col1)
+        tv.append_column(col2)
+        
+        cell = gtk.CellRendererText()
+        cell1 = gtk.CellRendererText()
+        cell2 = gtk.CellRendererText()
+        col.pack_start(cell, True)
+        col1.pack_start(cell1, True)
+        col2.pack_start(cell2, True)
+        col.add_attribute(cell, 'text', 0)
+        col1.add_attribute(cell1, 'text', 1)
+        col2.add_attribute(cell2, 'text', 2)
+        tv.set_search_column(0)
+        col.set_sort_column_id(0)
+        tv.set_reorderable(True)
+        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        sw.add(tv)
+        ### End of tree, Lets add some action buttons in the same frame
+        
+        toolbar_frame = gtk.Frame()
+        task_toolbar = gtk.HBox(False, 4)
+        bt_addtask = gtk.Button(label='New Job')
+        #bt_addtask.connect('clicked', self.sample_add)
+        bt_addtask.connect('clicked', self._show_add_form)
+        img = gtk.Image()
+        img.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
+        bt_addtask.set_image(img)
+        
+        img1 = gtk.Image()
+        bt_remove = gtk.Button('Delete Job')
+        img1.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
+        bt_remove.set_image(img1)
+        
+        bt_edit = gtk.Button('Edit Job')
+        img2 = gtk.Image()
+        img2.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON)
+        bt_edit.set_image(img2)
+        
+        lhblank = gtk.Label()
+        rhblank = gtk.Label()
+        task_toolbar.pack_start(lhblank, True, True, 0)
+        task_toolbar.pack_start(bt_addtask, False, False, 2)
+        task_toolbar.pack_start(bt_remove, False, False, 2)
+        task_toolbar.pack_start(bt_edit, False, False, 2)
+        task_toolbar.pack_start(rhblank, True, True, 0)
+        toolbar_frame.add(task_toolbar)
+        frm_todo_int.pack_start(sw, True, True, 4)
+        frm_todo_int.pack_start(toolbar_frame, False, True, 4)
+        
+        #frm_todo_int.pack_start(int_lbl, True, True, 4)
+        frm_todo.add(frm_todo_int)
+        
+        body.pack_start(frm_todo, True, True, 4)
+        ### ------------------- End of scheduled buidls list -----------##
+        frm_history = gtk.Frame('Current bot status')
+        frm_history_int = gtk.VBox(False, 4)
+        frm_history.add(frm_history_int)
+        hist_lbl = gtk.Label('current status information here.')
+        blnk = gtk.Label()
+        frm_history_int.pack_start(hist_lbl, True, True, 4)
+        frm_history_int.pack_start(blnk, True, True, 4)
+        
+        body.pack_start(frm_history, False, False, 4)
+        
+        self.statusbar = gtk.Statusbar()
+        body.pack_start(self.statusbar, False, True, 4)
+
+
+        
+        self.info_label1 = gtk.Label()
+        self.info_label2 = gtk.Label()
+        self.info_label3 = gtk.Label()
+
+
+        self.add(body)
+        self.connect('destroy', gtk.main_quit)
+    def _show_add_form(self, widget):
+        aw = JobWindow()
+        aw.show_all()
+    
+    def add_job(self, widget):
+        pass
+        
+    
+    def refresh_task_list(self):
+        _lst = dbconn.refresh_todo()
+        for row in _lst:
+            self._todo_list.append(None, [row[0], row[1], row[2]])
+        
+
+class JobWindow(gtk.Window):
+    def __init__(self):
+        gtk.Window.__init__(self)
+        body = gtk.VBox(False, 4)
+        self.set_title('Add New Job')
+        top_label = gtk.Label('Add new job to queue')
+        top_label.set_property('xalign', 0.0)
+        blnk = gtk.Label()
+        body.pack_start(blnk, False, False, 0)
+        body.pack_start(top_label, False, False, 0)
+        blnk = gtk.Label()
+        body.pack_start(blnk, False, False, 0)
+        
+        srcline = gtk.HBox(False, 4)
+        srclbl = gtk.Label('URI to Source')
+        srcline.pack_start(srclbl, False, False, 2)
+        src_entry = gtk.Entry()
+        self.srcentry = src_entry
+        srcline.pack_start(src_entry, True, True, 2)
+        src_loader = gtk.Button(stock=gtk.STOCK_OPEN)
+        src_loader.connect('clicked', self.load_source)
+        srcline.pack_start(src_loader, False, False, 2)
+        
+        body.pack_start(srcline, False, False, 2)
+        
+        descline = gtk.HBox(False, 4)
+        desclbl = gtk.Label('URI to Description')
+        desc_entry = gtk.Entry()
+        self.desc_entry = desc_entry
+        desc_loader = gtk.Button(stock=gtk.STOCK_OPEN)
+        desc_loader.connect('clicked', self.load_description)
+        
+        descline.pack_start(desclbl, False, False, 2)
+        descline.pack_start(desc_entry, True, True, 2)
+        descline.pack_start(desc_loader, False, False, 2)
+        
+        blnk = gtk.Label()
+        
+        body.pack_start(descline, False, False, 2)
+        body.pack_start(blnk, True, True, 0)
+        
+        self.path_to_source = None
+        self.path_to_desc = None
+        
+        toolbar = gtk.HBox(False, 2)
+        bt_OK = gtk.Button(stock=gtk.STOCK_OK)
+        bt_Cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
+        bt_Cancel.connect('clicked', lambda _: self.destroy())
+        
+        toolbar.pack_end(bt_OK, False, False, 2)
+        toolbar.pack_end(bt_Cancel, False, False, 2)
+        
+        body.pack_start(toolbar, False, False, 4)
+        self.add(body)
+
+    def load_source(self, widget):
+        dia = gtk.FileChooserDialog(buttons = (gtk.STOCK_OPEN,
+        gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        dia.set_title('Select source file')
+
+        if dia.run():
+            self.path_to_source = dia.get_filename()
+            self.srcentry.set_text(self.path_to_source)
+        else:
+            self.path_to_source = ""
+            self.srcentry.set_text("")
+            
+        dia.destroy()
+    def load_description(self, widget):
+        dia = gtk.FileChooserDialog(buttons = (gtk.STOCK_OPEN,
+        gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        if dia.run():
+            self.path_to_desc = dia.get_filename()
+            self.desc_entry.set_text(self.path_to_desc)
+        else:
+            self.path_to_desc = ""
+            self.desc_entry.set_text(self.path_to_desc)
+        
+        dia.destroy()
+        
+        
+        
+        
+        
+#w = gui()
+w = mWindow()
+w.statusbar.push(0, 'Idle')
+w.show_all()
+tmon = Monitor(w.info_label1)
+tmon.start()
+gtk.gdk.threads_enter()
+gtk.main()
+gtk.gdk.threads_leave()
+
+_busy = False
+#!/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 v2 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 MySQLdb as dbase
+
+db = None
+
+def open_connection():
+    global db
+    db = dbase.connect(host='localhost', user='root', db='buildbot')
+    return 0
+
+def close_connection():
+    global db
+    db.close()
+    return 0
+def refresh_todo():
+    '''Read the todo list from the database'''
+    global db
+    open_connection()
+    if db.cursor is None: return 1
+    cursor = db.cursor()
+    cursor.execute("""SELECT * FROM todo ORDER BY id""")
+    res = []
+    for row in cursor.fetchall():
+        res.append(row)
+    cursor.close()
+    
+    close_connection()
+    
+    return res
+
+def push_data(sql_data):
+    global db
+    #print sql_data
+    open_connection()
+    cursor = db.cursor()
+    cursor.execute(sql_data)
+    db.commit()
+    close_connection()
+    
+
+def refresh_build_history():
+    '''Read the build history from the database'''
+    global db
+    open_connection()
+    if db.cursor is None: return 1
+    cursor = db.cursor()
+    cursor.execute("""SELECT * FROM en_history ORDER BY id""")
+    res = []
+    for row in cursor.fetchall():
+        res.append(row)
+    cursor.close()
+    close_connection()
+    return res
+
+def log_build_attempt(srcpath, stdoutpath, buildresult):
+    global db
+    open_connection()
+    cursor = db.cursor()
+    if db.cursor is None: return 1
+    cursor.execute("""INSERT INTO history (srcpath, stdout, result) values (
+        '%s','%s','%s')"""% (srcpath, stdoutpath, buildresult))
+    cursor.execute("""DELETE FROM todo WHERE srcpath='%s'"""% srcpath)
+    db.commit()
+    close_connection()
+    return 0
+    
+
+if __name__ == '__main__':
+    print refresh_todo()
+    
+