Opened 6 years ago
Last modified 13 months ago
#1892 new enhancement
[PATCH] 0.11 Compatibility Patch
| Reported by: | airadier@… | Owned by: | coderanger |
|---|---|---|---|
| Priority: | high | Component: | ProjectMenuPlugin |
| Severity: | critical | Keywords: | |
| Cc: | alvaro.iradier@…, coderanger, rjollos | Trac Release: | 0.11 |
Description
Hi,
projectmenu plugin doesn't work in Trac 0.11. Calling add_script in get_navigation_items enters an infinite recursive call.
Attached is a patch to fix this, and make it work in Trac 0.11
Attachments (4)
Change History (26)
Changed 6 years ago by airadier@…
comment:1 Changed 5 years ago by fermulator
- Cc alvaro.iradier@… airadier@… added
Which web_ui.py should this be applied to?
If we run a:
find . | grep web_ui.py
we receive several instances ...
./trac/search/web_ui.pyc ./trac/search/web_ui.py ./trac/prefs/web_ui.pyc ./trac/prefs/web_ui.py ./trac/admin/web_ui.pyc ./trac/admin/web_ui.py ./trac/timeline/web_ui.pyc ./trac/timeline/web_ui.py ./trac/ticket/web_ui.pyc ./trac/ticket/web_ui.py ./trac/wiki/web_ui.pyc ./trac/wiki/web_ui.py ./patches_and_diffs/projectmenuplugin/web_ui.py.diff
comment:2 Changed 5 years ago by alvaro.iradier@…
Sorry, it applies to the web_ui.py file in the ProjectMenu plugin, not in the trac core.
comment:3 Changed 5 years ago by fermulator
FYI: I ran:
patch -p0 < web_ui.py.diff
then received the following results:
patching file web_ui.py Hunk #1 succeeded at 1 with fuzz 2. Hunk #2 FAILED at 10. Hunk #3 succeeded at 27 (offset -1 lines). Hunk #4 succeeded at 35 (offset -1 lines). 1 out of 4 hunks FAILED -- saving rejects to file web_ui.py.rej
The reject file web_ui.py.rej looks as follows:
***************
*** 9,16 ****
class ProjectMenuModule(Component):
! implements(INavigationContributor, ITemplateProvider)
# INavigationProvider methods
def get_navigation_items(self, req):
projects = []
--- 10,25 ----
class ProjectMenuModule(Component):
! implements(INavigationContributor, ITemplateProvider, IRequestFilter)
+ # IRequestFilter methods
+ def pre_process_request(self, req, handler):
+ add_script(req, 'projectmenu/projectmenu.js')
+ return handler
+
+ def post_process_request(self, req, template, content_type):
+ return(template, content_type)
+
# INavigationProvider methods
def get_navigation_items(self, req):
projects = []
Even with the rejected hunk I still tried to install it, and it works!
Is this missing code important?...
comment:4 Changed 5 years ago by fermulator
OK I was wrong, it doesn't work ...
The menu itself shows up, but clicking on a project doesn't do anything
comment:5 Changed 5 years ago by fermulator
- Cc coderanger added
Well! Clearly the IRequestFilter was required :-)
Although that hunk failed, I manually changed the line:
implements(INavigationContributor, ITemplateProvider)
to
implements(INavigationContributor, ITemplateProvider, IRequestFilter)
and immediately following I added the lines:
# IRequestFilter methods
def pre_process_request(self, req, handler):
add_script(req, 'projectmenu/projectmenu.js')
return handler
def post_process_request(self, req, template, content_type):
return(template, content_type)
Then ran:
sudo easy_install -U .
And it works! Most excellent.
comment:6 Changed 5 years ago by fermulator
Alright so after more analysis unfortunately this doesn't work. Something about the patched code there causes a massive slowdown in trac.
Pages would sometimes take upwards of 20 seconds to load instead of the usual 2 seconds (at most). Running a dual core server caused 100% CPU load on both processors for EVERY page refresh (i.e. every time it called the ProjectMenuPlugin code since it shows on every page ... )
Any ideas coderanger/airadier?
comment:7 Changed 5 years ago by coderanger
In the call to open_environment, add the argument use_cache=True. Otherwise it loads every environment off disk each time and will be, as you said, insanely slow.
comment:8 Changed 5 years ago by airadier
Great, I didn't know use_cache parameter was possible. I also noticed a slow down when the number of existing projects increased. Was this caused by my patch, or was it in the original plugin?
comment:9 Changed 5 years ago by fermulator
So I've just added an updated diff file: web_ui.py.2.diff
This contains the changes as per the previous diffs, as well as the addition to use the cache when calling the environments.
airradier, do you plan to incorporate this patch into the trunk to fully support 0.11?
comment:10 Changed 5 years ago by airadier
I'm not the mantainer, I just made the patches for 0.11. I guess coderanger should merge them if he thinks they are right.
comment:11 follow-up: ↓ 12 Changed 5 years ago by wbranderson@…
All of the *.diff files are empty ... where have the patches gone?
comment:12 in reply to: ↑ 11 Changed 5 years ago by coderanger
Replying to wbranderson@gmail.com:
All of the *.diff files are empty ... where have the patches gone?
Use the "Original Format" link at the bottom of the page. It's an old bug in Trac that can't render some diffs.
comment:13 follow-up: ↓ 14 Changed 5 years ago by wbranderson@…
After applying the diff and restarting trac, I received the following error:
Traceback (most recent call last):
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\web\api.py", line 339, in send_error
'text/html')
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\web\chrome.py", line 684, in render_template
data = self.populate_data(req, data)
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\web\chrome.py", line 592, in populate_data
d['chrome'].update(req.chrome)
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\web\api.py", line 168, in __getattr__
value = self.callbacks[name](self)
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\web\chrome.py", line 460, in prepare_request
for category, name, text in contributor.get_navigation_items(req):
File "build\bdist.win32\egg\projectmenu\web_ui.py", line 29, in get_navigation_items
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\env.py", line 561, in open_environment
env = env_cache.setdefault(env_path, open_environment(env_path))
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\env.py", line 565, in open_environment
env = Environment(env_path)
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\env.py", line 190, in __init__
self.verify()
File "c:\python24\lib\site-packages\Trac-0.11rc1-py2.4.egg\trac\env.py", line 243, in verify
fd = open(os.path.join(self.path, 'VERSION'), 'r')
IOError: [Errno 2] No such file or directory: 'X:\\Path\\To\\Trac\\Installation\\trac.ini\\VERSION'
Any thoughts? I have Multiple environments installed at 'X:
Path
To
Trac
Installation
', but the folder itself is not an environment. Do I need to have a parent project? And if so, how to I set this up?
comment:14 in reply to: ↑ 13 ; follow-up: ↓ 15 Changed 5 years ago by kmx
Your (wbranderson@…) error is caused by existing files in the directory where your multiple Trac project subdirs are located.
It can be easily fixed by the following patch:
for project in os.listdir(search_path):
- if project != this_project:
+ if project != this_project and os.path.isdir(os.path.join(search_path, project)):
proj_env = open_environment(os.path.join(search_path, project),use_cache=True)
comment:15 in reply to: ↑ 14 Changed 5 years ago by wbranderson@…
Yea, I fixed the problem shortly after posting the ticket. All is well. Thanks for the help.
Replying to kmx:
Your (wbranderson@…) error is caused by existing files in the directory where your multiple Trac project subdirs are located.
It can be easily fixed by the following patch:
for project in os.listdir(search_path): - if project != this_project: + if project != this_project and os.path.isdir(os.path.join(search_path, project)): proj_env = open_environment(os.path.join(search_path, project),use_cache=True)
Changed 5 years ago by anonymous
comment:16 follow-up: ↓ 17 Changed 5 years ago by anonymous
Is there an intent to create a 0.11 compatible install anytime soon ?
comment:17 in reply to: ↑ 16 Changed 4 years ago by didoux
Replying to anonymous:
Is there an intent to create a 0.11 compatible install anytime soon ?
... apparently not(?) ...too bad!
comment:18 Changed 4 years ago by rjollos
- Cc rjollos added
comment:19 Changed 3 years ago by AdrianFritz
- Summary changed from 0.11 Compatibility Patch to [PATCH] 0.11 Compatibility Patch
comment:20 Changed 3 years ago by airadier
- Cc alvaro.iradier@… added; alvaro.iradier@… airadier@… removed
comment:21 Changed 20 months ago by anonymous
trac-0.12.2
- patch web_ui.py.2.diff(this ticket)
- "?format=raw" url query is needed
- http://trac-hacks.org/attachment/ticket/1892/web_ui.py.2.diff?format=raw
- patch comment:14 and modify like below
if project != this_project and os.path.isdir(os.path.join(search_path, project)) and project[0] != '.':"
- e.g. ".egg-cache"
comment:22 Changed 15 months ago by anonymous
After applying web_ui.py.2.diff to trac-0.12.2, I received the following warning:
Trac[chrome] WARNING: Error with navigation contributor ProjectMenuModule


Patch for web_ui.py, 0.11 Compatibility