Opened 6 years ago

# [PATCH] 0.11 Compatibility Patch

### Description

Hi,

Attached is a patch to fix this, and make it work in Trac 0.11

### Changed 6 years ago by airadier@…

Patch for web_ui.py, 0.11 Compatibility

### Changed 6 years ago by alvaro.iradier@…

Updated patch (includes additional required modifcations)

### comment:1 Changed 6 years ago by fermulator

Which web_ui.py should this be applied to?

If we run a:

find . | grep web_ui.py


./trac/search/web_ui.pyc
./trac/search/web_ui.py
./trac/prefs/web_ui.pyc
./trac/prefs/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


### comment:2 Changed 6 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 6 years ago by fermulator

FYI: I ran:

patch -p0 < web_ui.py.diff


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 ****

projects = []
--- 10,25 ----

+     # IRequestFilter methods
+     def pre_process_request(self, req, handler):
+         return handler
+
+     def post_process_request(self, req, template, content_type):
+         return(template, content_type)
+
projects = []


Even with the rejected hunk I still tried to install it, and it works!
Is this missing code important?...

### comment:4 Changed 6 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 6 years ago by fermulator

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):
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 6 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 ... )

### comment:7 Changed 6 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 6 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?

### Changed 6 years ago by fermulator

Updated web_ui.py.diff for 0.11 & environment caching

### comment:9 Changed 6 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 6 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 6 years ago by wbranderson@…

All of the *.diff files are empty ... where have the patches gone?

### comment:12 in reply to: ↑ 11 Changed 6 years ago by coderanger

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 6 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 "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.

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: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 5 years ago by didoux

Is there an intent to create a 0.11 compatible install anytime soon ?

### comment:19 Changed 4 years ago by AdrianFritz

• Summary changed from 0.11 Compatibility Patch to [PATCH] 0.11 Compatibility Patch

### comment:21 Changed 2 years ago by anonymous

trac-0.12.2

1. patch web_ui.py.2.diff
2. 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"
Last edited 4 months ago by rjollos (previous) (diff)

### comment:22 Changed 21 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


### Modify Ticket

Change Properties