Edgewall Software

Ticket #7748 (closed enhancement: fixed)

Opened 3 months ago

Last modified 4 weeks ago

[patch] detect when Enscript is not installed

Reported by: techtonik <techtonik@…> Owned by: rblank
Priority: normal Milestone: 0.11.3
Component: rendering Version: 0.11-stable
Severity: normal Keywords: patch
Cc:

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

enscript.not_installed.patch.txt (2.7 KB) - added by techtonik <techtonik@…> 3 months ago.
check if enscript command is available
7748-disable-enscript-r7716.patch (0.9 KB) - added by rblank 6 weeks ago.
Patch against 0.11-stable disabling enscript after the first execution error

Change History

Changed 3 months ago by techtonik <techtonik@…>

check if enscript command is available

  Changed 3 months ago by cboos

  • milestone set to 0.11.3

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

  Changed 3 months ago by techtonik <techtonik@…>

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.

  Changed 7 weeks ago by rblank

  • owner set to rblank

Changed 6 weeks ago by rblank

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

follow-up: ↓ 6   Changed 6 weeks ago by 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?

  Changed 6 weeks ago by techtonik@…

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   Changed 6 weeks ago by cboos

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 ;-) )

  Changed 6 weeks ago by rblank

  • status changed from new to closed
  • resolution set to fixed

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.

  Changed 4 weeks ago by techtonik <techtonik@…>

  • type changed from defect to enhancement

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.

Add/Change #7748 ([patch] detect when Enscript is not installed)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from rblank. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.