Commits

Moises Henriquez  committed edfb05f

Added logging to text ui code

  • Participants
  • Parent commits 675500d

Comments (0)

Files changed (15)

File modules/aboutsystem.py

 from support import dialogs
 from support.vectorlinux.utils import _, launch_external_gui
 import subprocess as sp
+import logging
 
 def __vasm_test__():
     return os.path.exists("/usr/bin/hardinfo")
 
 
 def __run__(parent=None):
+    logger = logging.getLogger('vasm')
+    logger.info("Launching /usr/bin/hardinfo")
     @launch_external_gui
     def run_hardinfo():
         proc = sp.Popen(['/usr/bin/hardinfo'],

File modules/tui/tui_aboutvl.py

                                       parent=self.parent)
         
         self.body = urwid.LineBox(self.get_body())
-        #dialogs.ModuleDialog.__init__(self, "About VectorLinux", body,
-        #                          [("OK", self.return_home)])
-        #self.set_focus(self.action_area)
     
     def return_to_module(self, widget=None, data=None):
         """ REturn to this module from another dialog.

File modules/tui/tui_autologin.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "Graphical Environment"
 VASM_LABEL = "Automatic Login Settings"
                 message = _("There was an error saving the your automatic login preferences.") + "\n" + e,
                 buttons = [("OK", self.close_module)]
                 )
+            logger.error("Error saving automatic login settings: %s"% e)
             return self.pop_dialog(dia)
         # Display a success dialog
         dia = dialogs.Info(
             _("Your changes will take effect after the next system reboot."),
             buttons = [("OK", self.close_module)]
             )
+        logger.debug("Saved automatic login settings.")
         return self.pop_dialog(dia)
     
     def autologin_toggle_event(self, radio, newstate, user_data):

File modules/tui/tui_bootloaders.py

 import logging
 
 logger = logging.getLogger('vasm')
+
 class BootloaderTui(dialogs.ModuleDialog):
     def __init__(self, parent):
         self.parent = parent
             parent = self,
             on_focus = self.refresh_module_status_text
             )
-            #        self.videoqualitypicker = widgets.LabeledPicker(
-            #            label = _("Video Quality:"),
-            #            picker_title = _("Select your video quality for your boot screen."),
-            #            options = self._get_valid_video_quality(currentbootloader),
-            #            parent = self,
-            #            on_focus = self.refresh_module_status_text
-            #            )
         self.timeoutspinner = widgets.LabeledSpinner(
             label = "Timeout (seconds):",
             default_value=5,
         print "This may take a few seconds... Please wait."
         for method in methods:
             try:
+                logger.debug("Running %s"% method.func_name)
                 method()
             except AssertionError, e:
                 logger.fatal("%s"% e)
                     )
                 self.return_to_module()
                 self.pop_dialog(dia)
+                logger.error("Error while running %s: %s"%(method.func_name, e))
                 return self.resume_ui()
             time.sleep(1)
         logger.info('%s updated'% sloader)
             buttons = [("OK", self.close_module)]                
             )
         self.return_to_module()
+        logger.debug("Bootloader settings saved.")
         self.pop_dialog(dia)
         self.resume_ui()
 

File modules/tui/tui_bootmode.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "System Startup Mode"
         """ Save the changes in boot mode """
         try:
             self.datamodel.setMode(self.selected_mode)
+            logger.info("Boot mode was set to %s"% self.selected_mode)
         except:
+            logger.error("Unable to save boot mode settings.")
             dia = dialogs.Error(
             parent = self.parent,
             message = _("Unable to set boot mode.  No changes were applied.") + "\n" + \

File modules/tui/tui_dateset.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "Date and Time"
         # Save the date settings
         try:
             self._write_date_settings()
+            logger.debug('Saved system date.')
         except DATESET.DateTimeError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("Failed to set the system date.") + "\n\n%s"% e,
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error("Error while writing system date settings: %s"% e)
             return self.pop_dialog(dia)
         # Save the time settings
         try:
             self._write_time_settings()
+            logger.debug('Saved time settings.')
         except DATESET.DateTimeError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("Failed to save the system time settings.") + "\n\n%s"% e,
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error('Error while saving system time settings: %s'% e)
             return self.pop_dialog(dia)
 
         # Save the timezone settings
         try:
             self._write_timezone_setting()
+            logger.debug('Saved timezone settings')
         except IOError as e:
             return dialogs.Error(
                 parent = self.parent,
                 message = _("Failed to set timezone setting.") + "\n\n%s"% e,
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error('Unable to save timezone settings %s'% e)
             return self.pop_dialog(dia)
     
         # Save the hwclock settings
         try:
             self._write_hwclock_setting()
+            logger.debug('Saved hardware clock settings.')
         except IOError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("Faled to save hardware clock setting.") + "\n\n%s"% e,
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error('Faied to save hardware clock settings: %s'%e)
             return self.pop_dialog(dia)
         except AssertionError as e:
             dia = dialogs.Error(
                 buttons = [("OK", self.return_to_module)],
                 message = _("Failed to save hardware clock setting.") + "\n\n%s"% e            
                 )
+            logger.error('Faied to save hardware clock settings: %s'%e)
             return self.pop_dialog(dia)
 
         dia = dialogs.Info(
             message = ("System date and time settings have been updated."),
             buttons = [("OK", self.close_module)]
             )
+        logger.debug("Successfully saved Date, Time, Timezone, and Hardware clock settings.")
         return self.pop_dialog(dia)
         
 

File modules/tui/tui_fstab.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "Mount Points"
     def keypress(self, size, key):
         if key == 'esc':
             return self.parent.return_to_module()
-        return size, key
+        return super(AboutEntry, self).keypress(size, key)
 
 class FstabMod(dialogs.ModuleDialog):
     def __init__(self, parent):
     def _do_delete_entry(self, widget=None):
         try:
             self.fstabmodel.removeEntry(self.entryToDelete.device)
+            logger.info('Deleted %s from /etc/fstab'% self.entryToDelete.device)
         except AssertionError, e:
             dia = dialogs.Error(
                 message = "%s"% e,
                 parent = self,
                 buttons = [("OK", self.return_to_module)]
             )
+            logger.error('Unable to delete %s from /etc/fstab: %s'% (
+                self.entryToDelete.device, e))
             return self.pop_dialog(dia)
         return self.return_to_module()
     
                 message = "%s"% e,
                 buttons = [("OK", self.return_to_module)],
                 parent = self)
+            logger.error("Tests for % failed: %s"% (entry.device, e))
             return self.pop_dialog(dia)
         try:
             self.fstabmodel.addEntry(entry)
+            logger.info("%s has been added to /etc/fstab"% entry.device)
         except AssertionError, e:
             dia = dialogs.Error(
                 message = "%s"% e,
                 buttons = [("OK", self.return_to_module)],
                 parent = self)
+            logger.error("Unable to add %s to /etc/fstab: %s"% (entry.device, e))
             return self.pop_dialog(dia)
         # Mount the entry if necessary
         if entry._mount_now:
+            logger.debug("Mounting %s"%entry.device)
             return entry.mount()
         return
 

File modules/tui/tui_loginmanager.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "Graphical Environment"
 VASM_LABEL = "System Login Manager"
                 buttons = [("OK", self.close_module)],
                 message = _("Loginmanager settings have been saved.")
             )
+            logger.info("Login manager settings saved.")
         else:
             # There was an error
             dia = dialogs.Error(
                 _("Make sure you are doing this as root and that /etc/rc.d/rc.X is fine"),
                 buttons = [("OK", self.return_to_module)]
             )
+            logger.error("Unable to save login manager settings.  Check /etc/rc.d/rc.X")
         return self.parent.pop_module_dialog(dia)
     
     def loginmanager_toggle(self, radio, newvalue, user_data):

File modules/tui/tui_partitioning.py

 from modules.support.vectorlinux import FSTAB
 from modules.tuisupport import widgets
 from modules.tuisupport import dialogs
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "System Disk Partitions"
     
     def run_cfdisk(self, disk_drive):
         """ Launch cfdisk on the selected drive """
+        logger.debug('Launching cfdisk on %s'% disk_drive)
         cfpath = _get_cfdisk_path()
         self.close_module()
         return run_external_tui(self.parent, [cfpath, disk_drive])
     # otherwise, intercept the call with a dialog asking which drive to partition.
     drives = FSTAB.list_all_system_drives()
     if len(drives) > 1:
+        logger.debug('Multiple drives found.... Asking user to select one')
         dia = DrivePickerDialog(parent)
         return parent.pop_module(dia)
     else:
+        logger.debug('Launching cfdisk')
         run_external_tui(parent, _get_cfdisk_path())

File modules/tui/tui_password.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "Personal"
 VASM_LABEL = "Change My Password"
         # request the password change
         try:
             PASSWORDS.change_password(user, oldpass, newpass)
+            logger.info('Changed password for %s'% user)
         except PASSWORDS.BadPasswordException:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("The current password you entered is incorrect.  Your password remains unchanged."),
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error("Unable to change password for %s.  Current password is incorrect."% user)
             return self.parent.pop_module_dialog(dia)
         except PASSWORDS.BadNewPasswordException:
             dia = dialogs.Error(
                     )),
                 buttons = [("OK", self.return_to_module)]
                 )
+            logger.error("Unable to change password for %s.  New password is bad."% user)
             return self.parent.pop_module_dialog(dia)
         dia = dialogs.Info(
             parent = self.parent,
             message = _("Your password has been successfully changed."),
             buttons = [("OK", self.close_module)]
             )
+        logger.debug("Passowrd for %s has been changed"%user)
         return self.parent.pop_module_dialog(dia)        
 
 def __vasm_test__():

File modules/tui/tui_repos.py

 from modules.support.vectorlinux import REPOS
 from modules.tuisupport import dialogs
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "Software Sources"
                 message = _("There was an error saving changes to /etc/slapt-get/slapt-getrc.") + \
                 "  " + _("Make sure the file exists and you are doing this as root."),
                 buttons = [("OK",self.return_to_module)])
+            logger.error("Failed to save changes to /etc/slapt-get/slapt-getrc")
         else:
             dia = dialogs.Info(
                 parent = self.parent,
                 _("You will need to run `slapt-get -u` for changes to take effect"),
                 buttons = [("OK", self.close_module)]
             )
+            logger.info("/etc/slapt-get/slapt-getrc has been updated.")
         return self.pop_dialog(dia)
 
 

File modules/tui/tui_services.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "System Services Configuration"
         for svc in svcnames:
             for rl in range(2, 6):
                 if self._service_settings[svc][rl] is True:
+                    logging.debug('Enabling service %s for runlevel %s'% (svc, rl))
                     code, output = self.servicemodel.enable_service(svc, rl)
                     print output.strip()
                     if code > 0:
                         errors = True
                 else:
+                    logging.debug('Disabling service %s from runlevel %s'% (svc, rl))
                     code, output = self.servicemodel.disable_service(svc, rl)
                     print output.strip()
                     if code > 0:

File modules/tui/tui_skel.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "Personal"
 VASM_LABEL = "Reset Personal Settings"
         # Now perform the actions
         try:
             self.skelmodel.reset_settings(self._settings_to_reset)
+            logger.debug('Running skel.')
         except AssertionError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("An error has occurred!") + "\n\n%s"% e,
                 buttons = [("OK", self.return_home)]
                 )
+            logger.error('%s'%e)
             return self.parent.pop_module_dialog(dia)
         except Error as e:
             dia = dialogs.Error(
                 message = _("Error") + "\n\n%s"% e,
                 buttons = [("OK", self.return_home)]
                 )
+            logger.error('%s'%e)
         except OSError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("An error has occured!") + "\n\n%s"% e,
                 buttons = [("OK", self.return_home)]
                 )
+            logger.error('%s'%e)
             return self.parent.pop_module_dialog(dia)
 
         dia = dialogs.Info(
             message = _("The settings you selected have been reverted to system defaults."),
             buttons = [("OK", self.return_home)]
             )
+        logger.debug('Settings have been reverted to system defaults.')
         return self.parent.pop_module_dialog(dia)
     
     def return_home(self, widget):

File modules/tui/tui_usermanage.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
+
+logger = logging.getLogger('vasm')
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "Users and Passwords"
         self.account.groups = cgroups
         try:
             self.account.save_groups_changes()
+            logger.info('Group membership for %s changed'% self.account.login)
         except USERADMIN.AccountError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 message = _("The following error was encountered while saving changes") + ":\n\n%s"% e,
                 buttons = [("OK", self.parent.return_to_module)]
                 )
+            logger.error("Error modifying group memberships for %s"% (self.account.login,e))
             return self.parent.pop_dialog(dia, 3)
         dia = dialogs.Info(
             parent = self.parent,
             ret = PASSWORDS.change_password(user=self.login,
                                             oldpassword="foo",
                                             newpassword = pass2)
+            logger.info('Password for %s was changed'% self.login)
         except:
             ret = 1
             dia = dialogs.Error(
                 message = _("Pexpect error"),
                 buttons = [("OK", self.parent.return_to_module_stack)]
             )
+            logger.error('Pexpect returned error while changing password.')
         if ret > 0:
             dia = dialogs.Error(
                 parent = self.parent,
         try:
             self.usermodel.addUser(account)
             self.parent.set_status_text("")
+            logger.info("Added new user %s"% account.login)
         except AssertionError as e:
             dia = dialogs.Error(
                 parent = self.parent,
                 )
             self.parent.set_status_text("")
             self.clear_form_values()
+            logger.error("Unable to add account %s: %s"% (account.login, e))
             return self.parent.pop_dialog(dia)
         dia = dialogs.Info(
             parent = self.parent,
         """ Delete the account after this action has been confirmed """
         try:
             self.usermodel.deleteUser(self.current_user)
+            logger.info('Account %s has been deleted'% self.current_user)
         except AssertionError as e:
             dia = dialogs.Error(
                 message = _("The following error was encontered while deleting the account") + ":\n\n%s"% e,
                 parent = self.parent,
                 buttons = [("OK", self.parent.return_to_module)]
                 )
+            logger.error('Cannot delete account %s'% self.current_user)
             return self.parent.pop_module_dialog(dia, 3)
         dia = dialogs.Info(
             parent = self.parent,
         raise urwid.ExitMainLoop
         self.parent._mainloop.screen.stop()
         script = os.path.abspath(__file__)
-        print script
         proc = sp.popen(['/bin/vsuper','python', script])
         proc.communicate()
         raise urwid.ExitMainLoop
         self.original_overlay = self._mainloop.widget
         #self._previous_module_overlay = self._mainloop.widget
         # create another overlay?
+        logger.debug("Showing module %s" % widget.__module__)
         novl = urwid.Overlay(
             widget,
             self.original_overlay.top_w,
     loop.unhandled_input = top.random_input
     loop.run()
     if  top._GO_TO_ROOT:
+        logger.info("Escalating privileges .... ")
         proc = sp.Popen("clear")
         proc.communicate()
         cmd = ' '.join(sys.argv)
-        print cmd
         print _("You must enter the root password to access the administrative settings.")
         proc = sp.Popen(["su","-c", cmd])
         proc.communicate()