Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#7748 closed enhancement (fixed)

[patch] detect when Enscript is not installed

Reported by: techtonik <techtonik@…> Owned by: Remy Blank
Priority: normal Milestone: 0.11.3
Component: rendering Version: 0.11-stable
Severity: normal Keywords: patch
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

trac.log is full of tracebacks about failed Enscript executions. Enscript is not installed and won't be. The patch here checks if Enscript is installed before reporting supported mimetypes.

2008-10-23 00:24:01,436 Trac[__init__] WARNING: HTML preview using <trac.mimeview.enscript.EnscriptRenderer object at 0x40edae8c> failed (Running (enscript --color -h -q --language=html -p - -Ecpp) failed: 127, sh: line 1: enscript: command not found
.)
Traceback (most recent call last):
  File "/home/.december/trex/inst/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/mimeview/api.py", line 635, in render
    rendered_content, filename, url)
  File "/home/.december/trex/inst/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/mimeview/enscript.py", line 145, in render
    raise Exception, err
Exception: Running (enscript --color -h -q --language=html -p - -Ecpp) failed: 127, sh: line 1: enscript: command not found

Attachments (2)

enscript.not_installed.patch.txt (2.7 KB ) - added by techtonik <techtonik@…> 16 years ago.
check if enscript command is available
7748-disable-enscript-r7716.patch (952 bytes ) - added by Remy Blank 16 years ago.
Patch against 0.11-stable disabling enscript after the first execution error

Download all attachments as: .zip

Change History (10)

by techtonik <techtonik@…>, 16 years ago

check if enscript command is available

comment:1 by Christian Boos, 16 years ago

Milestone: 0.11.3

Good idea, but I'd rather do something like an auto-disable after the first failure.

comment:2 by techtonik <techtonik@…>, 16 years ago

Is it possible to disable a component? I thought it is not, because components do not return anything on initialization and TracDev/ComponentArchitecture is also silent about this.

comment:3 by Remy Blank, 16 years ago

Owner: set to Remy Blank

by Remy Blank, 16 years ago

Patch against 0.11-stable disabling enscript after the first execution error

comment:4 by Remy Blank, 16 years ago

The patch above disables EnscriptRenderer when invocation of enscript fails. An environment reload is required to re-enable it.

Christian, is that what you had in mind?

comment:5 by techtonik@…, 16 years ago

Seems good, but it would be even better if log message is expanded with the information that Enscript is getting disabled. And it's still would be nice to look for enscript executable in PATHs.

in reply to:  4 comment:6 by Christian Boos, 16 years ago

Replying to rblank:

The patch above disables EnscriptRenderer when invocation of enscript fails. An environment reload is required to re-enable it.

Christian, is that what you had in mind?

Yes, something similar:

  • trac/mimeview/enscript.py

     
    140140
    141141        np = NaivePopen(cmdline, content.encode('utf-8'), capturestderr=1)
    142142        if np.errorlevel or np.err:
     143            self.env.enabled[self.__class__] = False
    143144            err = 'Running (%s) failed: %s, %s.' % (cmdline, np.errorlevel,
    144145                                                    np.err)
    145146            raise Exception, err

(sorry untested, not much time for Trac those days ;-) )

comment:7 by Remy Blank, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [7719] by disabling the component in the ComponentManager. I have also made clear in the error message that EnscriptRenderer is disabled.

About searching for enscript on PATH, this is already done, as enscript is run through os.system(), which uses exec() which uses PATH to find the executable if it doesn't contain a /. At least it works on *nix, not sure about Windows. I have enscript_path = enscript in my trac.ini and the executable is found.

comment:8 by techtonik <techtonik@…>, 16 years ago

Type: defectenhancement

find_executable() function looks for executable in PATH without executing it, because it is not a good idea to spawn a new system process just to ensure that executable is not available.

find_executable() returns full path for executable. This path can then be executed without shell environment with functions other than os.system() that allow to intercept input/output stream directly instead of file reading/writing/reading cycle as it is now.

It is also recommended to replace os.system() calls with functions from subprocess module.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.