Ticket #7748 (closed enhancement: fixed)
Opened 3 years ago
Last modified 3 years 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: | |||
| Release Notes: | |||
| API 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
Change History
Changed 3 years ago by techtonik <techtonik@…>
- Attachment enscript.not_installed.patch.txt added
comment:1 Changed 3 years 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.
comment:2 Changed 3 years 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.
comment:3 Changed 3 years ago by rblank
- Owner set to rblank
Changed 3 years ago by rblank
- Attachment 7748-disable-enscript-r7716.patch added
Patch against 0.11-stable disabling enscript after the first execution error
comment:4 follow-up: ↓ 6 Changed 3 years 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?
comment:5 Changed 3 years 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.
comment:6 in reply to: ↑ 4 Changed 3 years 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
140 140 141 141 np = NaivePopen(cmdline, content.encode('utf-8'), capturestderr=1) 142 142 if np.errorlevel or np.err: 143 self.env.enabled[self.__class__] = False 143 144 err = 'Running (%s) failed: %s, %s.' % (cmdline, np.errorlevel, 144 145 np.err) 145 146 raise Exception, err
(sorry untested, not much time for Trac those days ;-) )
comment:7 Changed 3 years ago by rblank
- Resolution set to fixed
- Status changed from new to closed
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 Changed 3 years 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.



check if enscript command is available