jhbuild r2097 - in trunk: . jhbuild/frontends jhbuild/modtypes jhbuild/utils



Author: fpeters
Date: Fri May 16 15:24:46 2008
New Revision: 2097
URL: http://svn.gnome.org/viewvc/jhbuild?rev=2097&view=rev

Log:
* jhbuild/frontends/terminal.py, jhbuild/modtypes/__init__.py,
jhbuild/utils/notify.py, jhbuild/utils/trayicon.py: encode strings
according to terminal character set.  (closes: #532932)



Modified:
   trunk/ChangeLog
   trunk/jhbuild/frontends/terminal.py
   trunk/jhbuild/modtypes/__init__.py
   trunk/jhbuild/utils/notify.py
   trunk/jhbuild/utils/trayicon.py

Modified: trunk/jhbuild/frontends/terminal.py
==============================================================================
--- trunk/jhbuild/frontends/terminal.py	(original)
+++ trunk/jhbuild/frontends/terminal.py	Fri May 16 15:24:46 2008
@@ -67,6 +67,17 @@
     'install':        'install.png',
     }
 
+def get_term_encoding():
+    return getattr(sys.stdout, 'encoding', sys.getdefaultencoding())
+
+def uprint(s):
+    '''Print Unicode string encoded for the terminal'''
+    if type(s) is unicode:
+        print s.encode(get_term_encoding(), 'replace')
+    else:
+        print s
+
+
 class TerminalBuildScript(buildscript.BuildScript):
     triedcheckout = False
     is_end_of_build = False
@@ -87,15 +98,14 @@
             progress = ''
 
         if not (self.config.quiet_mode and self.config.progress_bar):
-            print '%s*** %s ***%s%s' % (t_bold, msg, progress, t_reset)
+            uprint('%s*** %s ***%s%s' % (t_bold, msg, progress, t_reset))
         else:
             progress_percent = 1.0 * (module_num-1) / len(self.modulelist)
             self.display_status_line(progress_percent, module_num, msg)
 
         if is_xterm:
-            sys.stdout.write('\033]0;jhbuild:')
-            sys.stdout.write('%s%s' % (msg, progress))
-            sys.stdout.write('\007')
+            sys.stdout.write('\033]0;jhbuild:%s%s\007' % (
+                        msg.encode('iso-8859-1'), progress))
             sys.stdout.flush()
         self.trayicon.set_tooltip('%s%s' % (msg, progress))
 
@@ -243,9 +253,10 @@
         '''handle error during build'''
         summary = _('error during stage %(stage)s of %(module)s') % {
             'stage':state, 'module':module.name}
-        self.message('%s: %s' % (summary, error))
+        self.message('%s: %s' % (summary, error.message))
         self.trayicon.set_icon(os.path.join(icondir, 'error.png'))
-        self.notify.notify(summary = summary, body = error, icon = 'dialog-error', expire = 20)
+        self.notify.notify(summary = summary, body = error.message,
+                icon = 'dialog-error', expire = 20)
 
         if self.config.trycheckout and (not self.triedcheckout) and altstates.count('force_checkout'):
             self.triedcheckout = True
@@ -256,15 +267,15 @@
             return 'fail'
         while True:
             print
-            print _('  [1] rerun stage %s') % state
-            print _('  [2] ignore error and continue to %s') % nextstate
-            print _('  [3] give up on module')
-            print _('  [4] start shell')
+            uprint(_('  [1] rerun stage %s') % state)
+            uprint(_('  [2] ignore error and continue to %s') % nextstate)
+            uprint(_('  [3] give up on module'))
+            uprint(_('  [4] start shell'))
             i = 5
             for altstate in altstates:
-                print _('  [%d] go to stage %s') % (i, altstate)
+                uprint(_('  [%d] go to stage %s') % (i, altstate))
                 i = i + 1
-            val = raw_input(_('choice: '))
+            val = raw_input(_('choice: ').encode(get_term_encoding(), 'replace'))
             val = val.strip()
             if val == '1':
                 return state
@@ -277,14 +288,14 @@
                     os.chdir(module.get_builddir(self))
                 except OSError:
                     os.chdir(self.config.checkoutroot)
-                print _('exit shell to continue with build')
+                uprint(_('exit shell to continue with build'))
                 os.system(user_shell)
             else:
                 try:
                     val = int(val)
                     return altstates[val - 5]
                 except:
-                    print _('invalid choice')
+                    uprint(_('invalid choice'))
         assert False, 'not reached'
 
 BUILD_SCRIPT = TerminalBuildScript

Modified: trunk/jhbuild/modtypes/__init__.py
==============================================================================
--- trunk/jhbuild/modtypes/__init__.py	(original)
+++ trunk/jhbuild/modtypes/__init__.py	Fri May 16 15:24:46 2008
@@ -180,7 +180,7 @@
             return (e.state, None, None)
         except (CommandError, BuildStateError), e:
             return (self._next_state(buildscript, state),
-                    str(e), method.error_states)
+                    e, method.error_states)
         else:
             return (self._next_state(buildscript, state), None, None)
 

Modified: trunk/jhbuild/utils/notify.py
==============================================================================
--- trunk/jhbuild/utils/notify.py	(original)
+++ trunk/jhbuild/utils/notify.py	Fri May 16 15:24:46 2008
@@ -41,7 +41,7 @@
             cmd.append('--icon=%s' % icon)
         if expire:
             cmd.append('--expire-time=%d' % (1000 * expire))
-        cmd.extend([summary, body])
+        cmd.extend([summary.encode('utf-8'), body.encode('utf-8')])
         try:
             retcode = subprocess.call(cmd, stderr = open('/dev/null', 'a'))
             if retcode:

Modified: trunk/jhbuild/utils/trayicon.py
==============================================================================
--- trunk/jhbuild/utils/trayicon.py	(original)
+++ trunk/jhbuild/utils/trayicon.py	Fri May 16 15:24:46 2008
@@ -75,7 +75,7 @@
     def set_icon(self, icon):
         self._send_cmd('icon: %s\n' % icon)
     def set_tooltip(self, tooltip):
-        self._send_cmd('tooltip: %s\n' % tooltip)
+        self._send_cmd('tooltip: %s\n' % tooltip.encode('utf-8'))
     def set_visible(self, visible):
         if visible:
             visible = 'true'



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]