Commits

Moises Henriquez committed 0ce05f6

Moved bot control/status bar out of the tabstrip. Added preferences settings

Comments (0)

Files changed (7)

         packages=['vpackager'],
         package_dir={'vpackager': 'src/vpackager'},
         package_data={'vpackager': ['data/*']},
+        data_files=[('/etc', ['src/vpackager/vpackager.cfg'])],
         requires =['psutil'],
         install_requires=['psutil'],
         scripts=['src/scripts/vpackager'],

src/vpackager/bot.py

 import shutil
 import urllib
 import time
+import preferences
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
         gtk.VBox.__init__(self)
         self.model = model
         self._parentView = _parentView
-        #self.bot_state_indicators = {}
-        #self.bot_control_buttons = {}
-        #self.bot_state_indicators['state'] = gtk.Label()
-        #self.bot_state_indicators['running_job'] = gtk.Label()
-        #for label in self.bot_state_indicators.values():
-        #    label.set_property('xalign', 0.0)
-        #self.bot_control_buttons['start'] = guitools.vButton(
-        #    stock=gtk.STOCK_YES, label='Start')
-        #self.bot_control_buttons['stop'] = guitools.vButton(
-        #    stock=gtk.STOCK_NO, label='Stop')
-        #for lb  in self.bot_state_indicators.values():
-        #    lb.set_use_markup(True)
-        #self.pack_start(self._get_top_frames(), False, True, 4)
         self.pack_start(self._get_output_display(), True, True, 4)
-        #self.RUN_BOT = False
-        #self.bot_control_buttons['start'].connect(
-        #    'clicked', self.StartBot)
-        #self.bot_control_buttons['stop'].connect(
-        #    'clicked', self.StopBot)
-        #self.StopBot(self.bot_control_buttons['stop'])
-        #self.dispatcher = Dispatcher(model = self.model, view = self)
 
     def IndicateBotRunning(self, app, ver):
+        """ Indicate in the GUI that the bot is running. This just
+        returns a method from the parent window"""
         return self._parentView.IndicateBotRunning(app, ver)
-        #self.bot_state_indicators['state'].set_label(
-        #    'Running')
-        #self.bot_state_indicators['running_job'].set_label(
-        #    '%s-%s'% (app, ver))
 
     def IndicateBotStopped(self):
+        """ Indicate in the gui that the bot is stopped.  Just returns
+        a method from the parent window"""
         return self._parentView.IndicateBotStopped()
-        #self.bot_state_indicators['state'].set_label('Idle')
-        #self.bot_state_indicators['running_job'].set_label('None')
-        #self.bot_control_buttons['stop'].set_sensitive(False)
-        #self.bot_control_buttons['start'].set_sensitive(True)
 
     def StopBot(self, widget=None):
+        """ Stop the bot"""
         return self._parentView.StopBot()
-        #self.RUN_BOT = False
-        #return self.IndicateBotStopped()
 
     def StartBot(self, widget=None):
-        self.RUN_BOT = True
-        self.bot_state_indicators['state'].set_label(
-            '<b>Running</b>')
-        if widget:
-            widget.set_sensitive(False)
-            self.bot_control_buttons['stop'].set_sensitive(True)
-        try:
-            self.dispatcher.start()
-        except:
-            del self.dispatcher
-            self.dispatcher = Dispatcher(model = self.model, view = self)
-            self.dispatcher.start()
-        return
-
-    def _get_top_frames(self):
-        """ Top frames that show the bot status and bot control buttons."""
-        section = gtk.HBox()
-        frm_tl = gtk.Frame('Bot Status')
-        frm_tr = gtk.Frame('Build Bot Control')
-        frm_tl_vbox = gtk.VBox()
-        frm_tl.add(frm_tl_vbox)
-        line1 = gtk.HBox()
-        line2 = gtk.HBox()
-        frm_tl_vbox.pack_start(line1, False, True, 2)
-        frm_tl_vbox.pack_start(line2, False, True, 2)
-        lb_bot_state = gtk.Label('Current State:')
-        lb_running_job = gtk.Label('Current Job:')
-        line1.pack_start(lb_bot_state, False, False, 2)
-        line2.pack_start(lb_running_job, False, False, 2)
-        line1.pack_start(
-            self.bot_state_indicators['state'], True, True, 2)
-        line2.pack_start(
-            self.bot_state_indicators['running_job'], True, True, 2)
-
-        # Pack the bot control widgets
-        rvbox = gtk.VBox()
-        rhbox = gtk.HBox()
-        rvbox.pack_start(rhbox, True, True, 2)
-        rhbox.pack_start(
-            self.bot_control_buttons['start'], False, False, 2)
-        rhbox.pack_start(
-            self.bot_control_buttons['stop'], False, False, 2)
-        frm_tr.add(rvbox)
-
-        section.pack_start(frm_tl, True, True, 2)
-        section.pack_start(frm_tr, False, False, 2)
-
-        return section
+        """ Start the bot"""
+        return self._parentView.StartBot()
 
     def PlayOutput(self, data):
         gtk.gdk.threads_enter()
 
         # Bot control and status bar.
         bot_controlbar = gtk.HBox()
-        btStatuslb = gtk.Label('Bot Status:')
+        btStatuslb = gtk.Label()
+        btStatuslb.set_property('use-markup', True)
+        btStatuslb.set_markup('<b>Bot Status: </b>')
         bot_controlbar.pack_start(btStatuslb, False, False, 2)
         self.bot_state_label = gtk.Label()
         self.bot_state_label.set_property('use-markup', True)
     def StartBot(self, widget=None):
         """ Start the bot"""
         self.RUN_BOT = True
-        if widget:
-            widget.set_sensitive(False)
-        self.bt_bot_stop.set_sensitive(True)
+        #self.bt_bot_start.set_sensitive(False)
+        #self.bt_bot_stop.set_sensitive(True)
 
         try:
             self.dispatcher.start()
         self.bot_state_label.set_text(
             "Building %s-%s"%(app, ver))
         self.bt_bot_start.set_sensitive(False)
-        self.bt_bot_start.set_sensitive(True)
+        self.bt_bot_stop.set_sensitive(True)
 
     def CheckDatabase(self):
         """ Run a sanity check and make sure the databse tables exist"""
         return mb
 
     def ShowPrefsWindow(self, widget=None):
-        #dia = guitools.message.Error(
-        #    text = "No preferences available yet",
-        #    parent = self)
+        """ Show the preferences window and update the settings
+        accordingly"""
         dia = guitools.PrefsDialog(parent = self)
-        if dia.run():
-            return dia.destroy()
+        res = dia.run()
+        dia.hide()
+        if res == gtk.RESPONSE_OK:
+            conf = preferences.VPConf()
+            conf.SetSetting('packager_name', dia.PACKAGER_NAME)
+            conf.SetSetting('sources_home', dia.DEFAULT_SOURCES_PATH)
+            conf.SetSetting('database_home', dia.DATABASE_HOME)
+
+        return dia.destroy()
 
     def _exit(self, widget=None):
         self.bot_tab.RUN_BOT = False

src/vpackager/buildutils.py

 import glob
 import shutil
 import exceptions
+import preferences
 
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 __version__ = '0.1'
 
-_sources_home = '/tmp/vpackager/'
+try:
+    _sources_home = preferences.VPConf().GetSetting('sources_home')
+except:
+    _source_home = "/tmp/vpackager"
+try:
+    _packager = preferences.VPConf().GetSetting('packager_name')
+except:
+    _packager="vpackager"
 
 class SourceCopyError(Exception):
     pass
         return bottools.Execute('installpkg %s'% fullpath)
 
 
-    def makeSlackBuild(self, buildno='1', packager='vpackager'):
+    def makeSlackBuild(self, buildno='1', packager=_packager):
         """ Generate a slackbuild using sbbuilder to build this source"""
         ### Use sbbuilder to create a slackbuild for his package.
         ### The only diff from using this vs sbbuilder itself is that
         self.builder = srctype
         self.link = link
 
-    def makeSlackBuild(self, buildno='1', packager='vpackager'):
+    def makeSlackBuild(self, buildno='1', packager=_packager):
         """ Generate the build script for this source """
         try:
             os.makedirs(_sources_home)
         # Make sure we are at the correct location
         os.chdir(self.srclocation)
         return bottools.Execute('sh %s.SlackBuild'% self.app)
-
-
-
-

src/vpackager/dbutils.py

 
 import sqlite3
 import os
+import preferences
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 __version__ = '0.1'
 
-dbpath = '/tmp/vpackager.db'
+dbpath = os.path.join(preferences.VPConf().GetSetting('database_home'),
+                      'vpackager.db')
+#dbpath = '/tmp/vpackager.db'
 
 class dbase(object):
     """ Main database class. All operations to the job queue or history are

src/vpackager/guitools.py

 import buildutils
 import message
 import dbutils
-import ConfigParser
+import preferences
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
         self.set_has_separator(True)
         self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
         self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
-        self.config = ConfigParser.ConfigParser()
-        self.PACKAGER_NAME = "vpackager"
-        self.DEFAULT_SOURCES_PATH = "/home"
-        self.DATABASE_HOME = "/tmp"
+        #self.config = ConfigParser.ConfigParser()
+        self.entries = {}
+        conf = preferences.VPConf()
+        self.PACKAGER_NAME = conf.GetSetting('packager_name')
+        self.DEFAULT_SOURCES_PATH = conf.GetSetting('sources_home')
+        self.DATABASE_HOME = conf.GetSetting('database_home')
+
         # banner
         bannerbox = gtk.HBox()
         img = gtk.Image()
         confbox.pack_start(line_packager, False, True, 4)
         lb_packager = gtk.Label('Packager Name:')
         en_packager = gtk.Entry()
+        en_packager.connect('changed', self.packager_change_event)
         line_packager.pack_start(lb_packager, False, False, 2)
         line_packager.pack_start(en_packager, True, True, 2)
 
         # default sources path
         line_srcs = gtk.HBox()
         confbox.pack_start(line_srcs, False, True, 4)
-        lb_srcs = gtk.Label('Local sources Dir:')
+        lb_srcs = gtk.Label('Build Directory:')
         en_srcs = gtk.Entry()
+        en_srcs.connect('changed', self.sources_home_change_event)
         bt_srcs = vButton(stock=gtk.STOCK_OPEN, label='Select')
+        bt_srcs.connect('clicked', self.select_sources_dir_event)
         line_srcs.pack_start(lb_srcs, False, False, 2)
         line_srcs.pack_start(en_srcs, True, True, 2)
         line_srcs.pack_start(bt_srcs, False, False, 2)
         confbox.pack_start(line_dbase_loc, False, True, 4)
         lb_dbase = gtk.Label("Database Location:")
         en_dbase = gtk.Entry()
+        en_dbase.connect('changed', self.dbase_home_change_event)
         bt_dbase = vButton(stock=gtk.STOCK_OPEN, label='Select')
+        bt_dbase.connect('clicked', self.select_dbase_dir_event)
         line_dbase_loc.pack_start(lb_dbase, False, False, 2)
         line_dbase_loc.pack_start(en_dbase, True, True, 2)
         line_dbase_loc.pack_start(bt_dbase, False, False, 2)
+        self.entries['packager'] = en_packager
+        self.entries['sources_dir'] = en_srcs
+        self.entries['dbase_home'] = en_dbase
 
+        self._set_entries_values()
 
         self.show_all()
 
+    def select_dbase_dir_event(self, widget=None):
+        dia = gtk.FileChooserDialog(
+            title = 'Select database directory',
+            action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+            parent = self,
+            buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK,
+                       gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        dia.set_current_folder('/')
+        res = dia.run()
+        dia.hide()
+        if res == gtk.RESPONSE_OK:
+            self.DATABASE_HOME = dia.get_filename()
+            self.entries['dbase_home'].set_text(self.DATABASE_HOME)
+        return dia.destroy()
+
+    def select_sources_dir_event(self, widget=None):
+        dia = gtk.FileChooserDialog(
+            title = 'Select root build directory',
+            action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+            parent = self,
+            buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK,
+                       gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        dia.set_current_folder('/')
+        res = dia.run()
+        dia.hide()
+        if res == gtk.RESPONSE_OK:
+            self.DEFAULT_SOURCES_PATH = dia.get_filename()
+            self.entries['sources_dir'].set_text(self.DEFAULT_SOURCES_PATH)
+        return dia.destroy()
+
+    def _set_entries_values(self):
+        """ Sets the initial values in the fields with the window is shown"""
+        self.entries['packager'].set_text(self.PACKAGER_NAME)
+        self.entries['sources_dir'].set_text(self.DEFAULT_SOURCES_PATH)
+        self.entries['dbase_home'].set_text(self.DATABASE_HOME)
+
+    def packager_change_event(self, widget=None):
+        """ UPdate the packager name when the text entry changes"""
+        self.PACKAGER_NAME = widget.get_text()
+
+    def sources_home_change_event(self, widget=None):
+        """ Update the source home dir"""
+        self.DEFAULT_SOURCES_PATH = widget.get_text()
+
+    def dbase_home_change_event(self, widget=None):
+        """ Update the database home directory"""
+        self.DATABASE_HOME = widget.get_text()
+
 class BoldLabel(gtk.Label):
     """ Preset label that displays text in bigger larger fonts """
     def __init__(self, text):

src/vpackager/preferences.py

+#!/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/>.
+
+# Settings reading / writing module for vpackager
+
+import ConfigParser
+
+__author__ = 'M0E-lnx'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+__version__ = '0.1'
+
+dotcfg = '/etc/vpackager.cfg'
+
+
+class VPConf(ConfigParser.SafeConfigParser):
+    """ vpackager configuration class """
+    def __init__(self):
+        ConfigParser.SafeConfigParser.__init__(self)
+
+    def SaveConfig(self):
+        with open(dotcfg, 'wb') as configfile:
+            self.write(configfile)
+        return
+
+    def WriteDefaultConfig(self):
+        self.add_section('vpackager')
+        self.set('vpackager', 'packager_name', 'vpackager')
+        self.set('vpackager', 'sources_home', '/tmp/vpackager')
+        self.set('vpackager', 'database_home', '/tmp')
+        return self.SaveConfig()
+
+    def GetSetting(self, key):
+        self.read(dotcfg)
+        return self.get('vpackager', key)
+
+    def SetSetting(self, key, value):
+        self.read(dotcfg)
+        self.set('vpackager', key, value)
+        return self.SaveConfig()

src/vpackager/vpackager.cfg

+#    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/>.
+
+# Default vpackager configuration
+
+[vpackager]
+packager_name = M0E_lnx
+sources_home = /tmp/vpackager
+database_home = /tmp