[jhbuild] New conf variable 'print_command_pattern' (GNOME bug 650443)



commit 3fd3f02b587331cd9bfc0cb7bc32c5870d02ef1b
Author: Craig Keogh <cskeogh adam com au>
Date:   Fri May 20 16:08:53 2011 +0930

    New conf variable 'print_command_pattern' (GNOME bug 650443)
    
    A string displayed before JHBuild executes a command. %(command)s in the
    string will be replaced with the command about to be executed. %(cwd)s
    in the string will be replaced with the current working directory.
    Defaults to '%(command)s'.

 doc/C/jhbuild.xml              |   12 ++++++++++++
 jhbuild/config.py              |    2 +-
 jhbuild/defaults.jhbuildrc     |    4 ++++
 jhbuild/frontends/terminal.py  |   30 ++++++++++++++++++++++++------
 jhbuild/frontends/tinderbox.py |   32 ++++++++++++++++++++++++++------
 5 files changed, 67 insertions(+), 13 deletions(-)
---
diff --git a/doc/C/jhbuild.xml b/doc/C/jhbuild.xml
index ed5f510..92c48b5 100644
--- a/doc/C/jhbuild.xml
+++ b/doc/C/jhbuild.xml
@@ -1997,6 +1997,18 @@ libgnomecanvas is missing branch definition for gnome-2-20
           </listitem>
         </varlistentry>
         <varlistentry>
+          <term id="cfg-print-command-pattern">
+            <varname>print_command_pattern</varname>
+          </term>
+          <listitem>
+            <simpara>A string displayed before JHBuild executes a command.
+              <varname>%(command)s</varname> in the string will be replaced with
+              the command about to be executed. <varname>%(cwd)s</varname> in
+              the string will be replaced with the current working directory.
+              Defaults to <literal>'%(command)s'</literal>.</simpara>
+          </listitem>
+        </varlistentry>
+        <varlistentry>
           <term id="cfg-progress-bar">
             <varname>progress_bar</varname>
           </term>
diff --git a/jhbuild/config.py b/jhbuild/config.py
index c7f875d..bcf5a9a 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -59,7 +59,7 @@ _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'jhbuildbot_mastercfg', 'use_local_modulesets',
                 'ignore_suggests', 'modulesets_dir', 'mirror_policy',
                 'module_mirror_policy', 'dvcs_mirror_dir', 'build_targets',
-                'cmakeargs', 'module_cmakeargs' ]
+                'cmakeargs', 'module_cmakeargs', 'print_command_pattern' ]
 
 env_prepends = {}
 def prependpath(envvar, path):
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index cebd624..9041028 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -169,3 +169,7 @@ ignore_suggests = False
 
 # local directory for DVCS mirror (git only atm)
 dvcs_mirror_dir = None
+
+# A string displayed before JHBuild executes a command. String may contain the
+# variables %(command)s, %(cwd)s
+print_command_pattern = '%(command)s'
\ No newline at end of file
diff --git a/jhbuild/frontends/terminal.py b/jhbuild/frontends/terminal.py
index 3ee387d..1e403ce 100644
--- a/jhbuild/frontends/terminal.py
+++ b/jhbuild/frontends/terminal.py
@@ -28,7 +28,7 @@ from jhbuild.frontends import buildscript
 from jhbuild.utils import cmds
 from jhbuild.utils import trayicon
 from jhbuild.utils import notify
-from jhbuild.errors import CommandError
+from jhbuild.errors import CommandError, FatalError
 
 term = os.environ.get('TERM', '')
 is_xterm = term.find('xterm') >= 0 or term == 'rxvt'
@@ -147,14 +147,30 @@ class TerminalBuildScript(buildscript.BuildScript):
         kws = {
             'close_fds': True
             }
+        print_args = {}
+        if cwd:
+            print_args['cwd'] = cwd
+        else:
+            print_args['cwd'] = os.getcwd()
+
         if isinstance(command, (str, unicode)):
             kws['shell'] = True
-            pretty_command = command
+            print_args['command'] = command
         else:
-            pretty_command = ' '.join(command)
+            print_args['command'] = ' '.join(command)
 
         if not self.config.quiet_mode:
-            print pretty_command
+            if self.config.print_command_pattern:
+                try:
+                    print self.config.print_command_pattern % print_args
+                except TypeError, e:
+                    raise FatalError('\'print_command_pattern\' %s' % e)
+                except KeyError, e:
+                    raise FatalError(_('%(configuration_variable)s invalid key'
+                                       ' %(key)s' % \
+                                       {'configuration_variable' :
+                                            '\'print_command_pattern\'',
+                                        'key' : e}))
 
         kws['stdin'] = subprocess.PIPE
         if hint in ('cvs', 'svn', 'hg-update.py'):
@@ -231,10 +247,12 @@ class TerminalBuildScript(buildscript.BuildScript):
             if p.wait() != 0:
                 if self.config.quiet_mode:
                     print ''.join(output)
-                raise CommandError(_('########## Error running %s') % pretty_command)
+                raise CommandError(_('########## Error running %s')
+                                   % print_args['command'])
         except OSError:
             # it could happen on a really badly-timed ctrl-c (see bug 551641)
-            raise CommandError(_('########## Error running %s') % pretty_command)
+            raise CommandError(_('########## Error running %s')
+                               % print_args['command'])
 
     def start_phase(self, module, phase):
         self.trayicon.set_icon(os.path.join(icondir,
diff --git a/jhbuild/frontends/tinderbox.py b/jhbuild/frontends/tinderbox.py
index d278b86..149ebac 100644
--- a/jhbuild/frontends/tinderbox.py
+++ b/jhbuild/frontends/tinderbox.py
@@ -26,7 +26,7 @@ import sys
 
 from jhbuild.main import _encoding
 from jhbuild.utils import cmds
-from jhbuild.errors import CommandError
+from jhbuild.errors import CommandError, FatalError
 import buildscript
 import commands
 
@@ -201,14 +201,33 @@ class TinderboxBuildScript(buildscript.BuildScript):
         kws = {
             'close_fds': True
             }
+        print_args = {}
+        if cwd:
+            print_args['cwd'] = cwd
+        else:
+            print_args['cwd'] = os.getcwd()
+
         self.modulefp.write('<pre>')
         if isinstance(command, (str, unicode)):
-            self.modulefp.write('<span class="command">%s</span>\n'
-                                % escape(command))
             kws['shell'] = True
+            print_args['command'] = command
         else:
-            self.modulefp.write('<span class="command">%s</span>\n'
-                                % escape(' '.join(command)))
+            print_args['command'] = ' '.join(command)
+
+        if self.config.print_command_pattern:
+            try:
+                commandstr = self.config.print_command_pattern % print_args
+                self.modulefp.write('<span class="command">%s</span>\n'
+                                    % escape(commandstr))
+            except TypeError, e:
+                raise FatalError('\'print_command_pattern\' %s' % e)
+            except KeyError, e:
+                raise FatalError(_('%(configuration_variable)s invalid key'
+                                   ' %(key)s' % \
+                                   {'configuration_variable' :
+                                        '\'print_command_pattern\'',
+                                    'key' : e}))
+
         kws['stdin'] = subprocess.PIPE
         kws['stdout'] = subprocess.PIPE
         kws['stderr'] = subprocess.PIPE
@@ -247,7 +266,8 @@ class TinderboxBuildScript(buildscript.BuildScript):
         self.modulefp.write('</pre>\n')
         self.modulefp.flush()
         if p.returncode != 0:
-            raise CommandError('Error running %s' % command, p.returncode)
+            raise CommandError('Error running %s' % print_args['command'],
+                               p.returncode)
 
     def start_build(self):
         assert self.outputdir



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