jhbuild r2101 - in trunk: . jhbuild jhbuild/commands jhbuild/frontends



Author: fpeters
Date: Sun May 18 13:12:01 2008
New Revision: 2101
URL: http://svn.gnome.org/viewvc/jhbuild?rev=2101&view=rev

Log:
* jhbuild/commands/base.py, jhbuild/commands/checkbranches.py,
jhbuild/commands/info.py, jhbuild/commands/rdepends.py,
jhbuild/commands/sanitycheck.py, jhbuild/frontends/terminal.py,
jhbuild/main.py: made uprint() use locale.getpreferredencoding()
instead of getting sys.stdout encoding, as redirecting output would
fall to ascii encoding.  Also replaced print by uprint() in many
places.



Modified:
   trunk/ChangeLog
   trunk/jhbuild/commands/base.py
   trunk/jhbuild/commands/checkbranches.py
   trunk/jhbuild/commands/info.py
   trunk/jhbuild/commands/rdepends.py
   trunk/jhbuild/commands/sanitycheck.py
   trunk/jhbuild/frontends/terminal.py
   trunk/jhbuild/main.py

Modified: trunk/jhbuild/commands/base.py
==============================================================================
--- trunk/jhbuild/commands/base.py	(original)
+++ trunk/jhbuild/commands/base.py	Sun May 18 13:12:01 2008
@@ -411,11 +411,11 @@
             if options.show_rev:
                 rev = mod.get_revision()
                 if rev:
-                    print '%s (%s)' % (mod.name, rev)
+                    uprint('%s (%s)' % (mod.name, rev))
                 else:
-                    print mod.name
+                    uprint(mod.name)
             else:
-                print mod.name
+                uprint(mod.name)
 
 register_command(cmd_list)
 

Modified: trunk/jhbuild/commands/checkbranches.py
==============================================================================
--- trunk/jhbuild/commands/checkbranches.py	(original)
+++ trunk/jhbuild/commands/checkbranches.py	Sun May 18 13:12:01 2008
@@ -63,7 +63,7 @@
             except urllib2.URLError:
                 pass
             else:
-                print _('%(module)s is missing branch definition for %(branch)s') % {'module': mod.name, 'branch': branch}
+                uprint(_('%(module)s is missing branch definition for %(branch)s') % {'module': mod.name, 'branch': branch})
 
 
 register_command(cmd_checkbranches)

Modified: trunk/jhbuild/commands/info.py
==============================================================================
--- trunk/jhbuild/commands/info.py	(original)
+++ trunk/jhbuild/commands/info.py	Sun May 18 13:12:01 2008
@@ -60,59 +60,59 @@
     def show_info(self, module, packagedb, module_set):
         installdate = packagedb.installdate(module.name, module.get_revision() or '')
 
-        print _('Name:'), module.name
-        print _('Module Set:'), module.moduleset_name
-        print _('Type:'), module.type
+        uprint(_('Name:'), module.name)
+        uprint(_('Module Set:'), module.moduleset_name)
+        uprint(_('Type:'), module.type)
 
         if installdate is not None:
-            print _('Install-date:'), time.strftime('%Y-%m-%d %H:%M:%S',
-                                                 time.localtime(installdate))
+            uprint(_('Install-date:'), time.strftime('%Y-%m-%d %H:%M:%S',
+                                                 time.localtime(installdate)))
         else:
-            print _('Install-date:'), _('not installed')
+            uprint(_('Install-date:'), _('not installed'))
 
         if isinstance(module, MozillaModule):
             if module.projects:
-                print _('Moz-Projects:'), ', '.join(module.projects)
+                uprint(_('Moz-Projects:'), ', '.join(module.projects))
 
         if isinstance(module, MetaModule):
             pass
         elif isinstance(module.branch, CVSBranch):
-            print _('CVS-Root:'), module.branch.repository.cvsroot
-            print _('CVS-Module:'), module.branch.module
+            uprint(_('CVS-Root:'), module.branch.repository.cvsroot)
+            uprint(_('CVS-Module:'), module.branch.module)
             if module.branch.revision:
-                print _('CVS-Revision:'), module.branch.revision
+                uprint(_('CVS-Revision:'), module.branch.revision)
         elif isinstance(module.branch, SubversionBranch):
-            print _('Subversion-Module:'), module.branch.module
+            uprint(_('Subversion-Module:'), module.branch.module)
         elif isinstance(module.branch, ArchBranch):
-            print _('Arch-Version:'), module.branch.module
+            uprint(_('Arch-Version:'), module.branch.module)
         elif isinstance(module.branch, DarcsBranch):
-            print _('Darcs-Archive:'), module.branch.module
+            uprint(_('Darcs-Archive:'), module.branch.module)
         elif isinstance(module.branch, GitBranch):
-            print _('Git-Module:'), module.branch.module
+            uprint(_('Git-Module:'), module.branch.module)
         elif isinstance(module.branch, TarballBranch):
-            print _('URL:'), module.branch.module
-            print _('Version:'), module.branch.version
+            uprint(_('URL:'), module.branch.module)
+            uprint(_('Version:'), module.branch.version)
         try:
             tree_id = module.branch.tree_id()
-            print _('Tree-ID:'), tree_id
+            uprint(_('Tree-ID:'), tree_id)
         except (NotImplementedError, AttributeError):
             pass
 
         # dependencies
         if module.dependencies:
-            print _('Requires:'), ', '.join(module.dependencies)
+            uprint(_('Requires:'), ', '.join(module.dependencies))
         requiredby = [ mod.name for mod in module_set.modules.values()
                        if module.name in mod.dependencies ]
         if requiredby:
-            print _('Required-by:'), ', '.join(requiredby)
+            uprint(_('Required-by:'), ', '.join(requiredby))
         if module.suggests:
-            print _('Suggests:'), ', '.join(module.suggests)
+            uprint(_('Suggests:'), ', '.join(module.suggests))
         if module.after:
-            print _('After:'), ', '.join(module.after)
+            uprint(_('After:'), ', '.join(module.after))
         before = [ mod.name for mod in module_set.modules.values()
                    if module.name in mod.after ]
         if before:
-            print _('Before:'), ', '.join(before)
+            uprint(_('Before:'), ', '.join(before))
 
         print
 

Modified: trunk/jhbuild/commands/rdepends.py
==============================================================================
--- trunk/jhbuild/commands/rdepends.py	(original)
+++ trunk/jhbuild/commands/rdepends.py	Sun May 18 13:12:01 2008
@@ -61,7 +61,7 @@
         for module in modules:
             if options.direct:
                 if modname in module.dependencies:
-                    print module.name
+                    uprint(module.name)
             else:
                 module_list = module_set.get_module_list([module.name], ignore_cycles=True)
                 if modname in [x.name for x in module_list]:
@@ -71,6 +71,6 @@
                         dependencies = [x for x in module.dependencies if x in seen_modules]
                         if dependencies:
                             deps = '[' + ','.join(dependencies) + ']'
-                    print module.name, deps
+                    uprint(module.name, deps)
 
 register_command(cmd_rdepends)

Modified: trunk/jhbuild/commands/sanitycheck.py
==============================================================================
--- trunk/jhbuild/commands/sanitycheck.py	(original)
+++ trunk/jhbuild/commands/sanitycheck.py	Sun May 18 13:12:01 2008
@@ -83,39 +83,39 @@
         # check whether the checkout root and install prefix are writable
         if not (os.path.isdir(config.checkoutroot) and
                 os.access(config.checkoutroot, os.R_OK|os.W_OK|os.X_OK)):
-            print _('checkout root is not writable')
+            uprint(_('checkout root is not writable'))
         if not (os.path.isdir(config.prefix) and
                 os.access(config.prefix, os.R_OK|os.W_OK|os.X_OK)):
-            print _('install prefix is not writable')
+            uprint(_('install prefix is not writable'))
 
         # check whether various tools are installed
         if not check_version(['libtoolize', '--version'],
                              r'libtoolize \([^)]*\) ([\d.]+)', '1.5'):
-            print _('%s not found') % 'libtool >= 1.5'
+            uprint(_('%s not found') % 'libtool >= 1.5')
         if not check_version(['gettext', '--version'],
                              r'gettext \([^)]*\) ([\d.]+)', '0.10.40'):
-            print _('%s not found') % 'gettext >= 0.10.40'
+            uprint(_('%s not found') % 'gettext >= 0.10.40')
         if not check_version(['pkg-config', '--version'],
                              r'^([\d.]+)', '0.14.0'):
-            print _('%s not found') % 'pkg-config >= 0.14.0'
+            uprint(_('%s not found') % 'pkg-config >= 0.14.0')
         if not check_version(['db2html', '--version'],
                              r'.* ([\d.]+)', '0.0'):
-            print _('%s not found') % 'db2html'
+            uprint(_('%s not found') % 'db2html')
         if not check_version(['autoconf', '--version'],
                              r'autoconf \([^)]*\) ([\d.]+)', '2.53'):
-            print _('%s not found') % 'autoconf >= 2.53'
+            uprint(_('%s not found') % 'autoconf >= 2.53')
         if not check_version(['automake-1.4', '--version'],
                              r'automake \([^)]*\) ([\d.]+)', '1.4'):
-            print _('%s not found') % 'automake-1.4'
+            uprint(_('%s not found') % 'automake-1.4')
         if not check_version(['automake-1.7', '--version'],
                              r'automake \([^)]*\) ([\d.]+)', '1.7'):
-            print _('%s not found') % 'automake-1.7'
+            uprint(_('%s not found') % 'automake-1.7')
         if not check_version(['automake-1.8', '--version'],
                              r'automake \([^)]*\) ([\d.]+)', '1.8'):
-            print _('%s not found') % 'automake-1.8'
+            uprint(_('%s not found') % 'automake-1.8')
         if not check_version(['automake-1.9', '--version'],
                              r'automake \([^)]*\) ([\d.]+)', '1.9'):
-            print _('%s not found') % 'automake-1.9'
+            uprint(_('%s not found') % 'automake-1.9')
 
         for amver in ('1.4', '1.7', '1.8', '1.9'):
             try:
@@ -124,15 +124,15 @@
                 continue # exception raised if aclocal-ver not runnable
 
             if not inpath('libtool.m4', path):
-                print _("aclocal-%s can't see libtool macros") % amver
+                uprint(_("aclocal-%s can't see libtool macros") % amver)
             if not inpath('gettext.m4', path):
-                print _("aclocal-%s can't see gettext macros") % amver
+                uprint(_("aclocal-%s can't see gettext macros") % amver)
             if not inpath('pkg.m4', path):
-                print _("aclocal-%s can't see pkg-config macros") % amver
+                uprint(_("aclocal-%s can't see pkg-config macros") % amver)
 
         # XML catalog sanity checks
         if not os.access('/etc/xml/catalog', os.R_OK):
-            print _('Could not find XML catalog')
+            uprint(_('Could not find XML catalog'))
         else:
             for (item, name) in [('-//OASIS//DTD DocBook XML V4.1.2//EN',
                                   'DocBook XML DTD V4.1.2'),
@@ -141,36 +141,36 @@
                 try:
                     data = get_output(['xmlcatalog', '/etc/xml/catalog', item])
                 except:
-                    print _('Could not find %s in XML catalog') % name            
+                    uprint(_('Could not find %s in XML catalog') % name            )
 
         # Perl modules used by tools such as intltool:
         for perlmod in [ 'XML::Parser' ]:
             try:
                 get_output(['perl', '-M%s' % perlmod, '-e', 'exit'])
             except:
-                print _('Could not find the perl module %s') % perlmod
+                uprint(_('Could not find the perl module %s') % perlmod)
                 
         # check for cvs:
         if not inpath('cvs', os.environ['PATH'].split(os.pathsep)):
-            print _('%s not found') % 'cvs'
+            uprint(_('%s not found') % 'cvs')
 
         # check for svn:
         if not inpath('svn', os.environ['PATH'].split(os.pathsep)):
-            print _('%s not found') % 'svn'
+            uprint(_('%s not found') % 'svn')
 
         # check for git:
         if not inpath('git', os.environ['PATH'].split(os.pathsep)):
-            print _('%s not found') % 'git'
+            uprint(_('%s not found') % 'git')
         else:
             try:
                 git_help = os.popen('git --help', 'r').read()
                 if not 'clone' in git_help:
-                    print _('Installed git program is not the right git')
+                    uprint(_('Installed git program is not the right git'))
             except:
-                print _('Could not check git program')
+                uprint(_('Could not check git program'))
 
         # check for svn:
         if not inpath('svn', os.environ['PATH'].split(os.pathsep)):
-            print _('%s not found') % 'svn'
+            uprint(_('%s not found') % 'svn')
 
 register_command(cmd_sanitycheck)

Modified: trunk/jhbuild/frontends/terminal.py
==============================================================================
--- trunk/jhbuild/frontends/terminal.py	(original)
+++ trunk/jhbuild/frontends/terminal.py	Sun May 18 13:12:01 2008
@@ -67,17 +67,6 @@
     '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

Modified: trunk/jhbuild/main.py
==============================================================================
--- trunk/jhbuild/main.py	(original)
+++ trunk/jhbuild/main.py	Sun May 18 13:12:01 2008
@@ -23,6 +23,7 @@
 import traceback
 
 import gettext
+import locale
 localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mo'))
 gettext.install('jhbuild', localedir=localedir, unicode=True)
 import __builtin__
@@ -32,6 +33,24 @@
 import jhbuild.commands
 from jhbuild.errors import UsageError, FatalError
 
+_encoding = locale.getpreferredencoding()
+
+
+def uprint(*args):
+    '''Print Unicode string encoded for the terminal'''
+    for s in args[:-1]:
+        if type(s) is unicode:
+            print s.encode(_encoding, 'replace'),
+        else:
+            print s,
+    s = args[-1]
+    if type(s) is unicode:
+        print s.encode(_encoding, 'replace')
+    else:
+        print s
+
+__builtin__.__dict__['uprint'] = uprint
+
 def help_commands(option, opt_str, value, parser):
     thisdir = os.path.abspath(os.path.dirname(__file__))
     
@@ -45,13 +64,13 @@
         except ImportError:
             pass
     
-    print _('JHBuild commands are:')
+    uprint(_('JHBuild commands are:'))
     commands = [(x.name, x.doc) for x in jhbuild.commands.get_commands().values()]
     commands.sort()
     for name, description in commands:
-        print '  %-15s %s' % (name, description)
+        uprint('  %-15s %s' % (name, description))
     print
-    print _('For more information run "jhbuild <command> --help"')
+    uprint(_('For more information run "jhbuild <command> --help"'))
     parser.exit()
 
 def main(args):
@@ -100,10 +119,10 @@
         sys.stderr.write('jhbuild %s: %s\n' % (command, str(exc)))
         sys.exit(1)
     except KeyboardInterrupt:
-        print "Interrupted"
+        uprint(_('Interrupted'))
         sys.exit(1)
     except EOFError:
-        print "EOF"
+        uprint(_('EOF'))
         sys.exit(1)
     except IOError, e:
         if e.errno != errno.EPIPE:



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