Ticket #1892 (new enhancement)

Opened 1 year ago

Last modified 2 weeks ago

0.11 Compatibility Patch

Reported by: airadier@intelcard.com Assigned to: coderanger
Priority: high Component: ProjectMenuPlugin
Severity: critical Keywords:
Cc: alvaro.iradier@intelcard.com, airadier@intelcard.com, coderanger 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

web_ui.diff (1.6 kB) - added by airadier@intelcard.com on 08/03/07 04:17:37.
Patch for web_ui.py, 0.11 Compatibility
web_ui.py.diff (2.5 kB) - added by alvaro.iradier@intelcard.com on 10/18/07 02:34:13.
Updated patch (includes additional required modifcations)
web_ui.py.2.diff (2.1 kB) - added by fermulator on 04/01/08 10:03:15.
Updated web_ui.py.diff for 0.11 & environment caching
web_ui.py (1.7 kB) - added by anonymous on 08/24/08 21:37:18.

Change History

08/03/07 04:17:37 changed by airadier@intelcard.com

  • attachment web_ui.diff added.

Patch for web_ui.py, 0.11 Compatibility

10/18/07 02:34:13 changed by alvaro.iradier@intelcard.com

  • attachment web_ui.py.diff added.

Updated patch (includes additional required modifcations)

03/14/08 13:31:54 changed by fermulator

  • cc set to alvaro.iradier@intelcard.com, airadier@intelcard.com.

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

03/17/08 05:06:49 changed by alvaro.iradier@intelcard.com

Sorry, it applies to the web_ui.py file in the ProjectMenu? plugin, not in the trac core.

03/20/08 09:11:05 changed 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?...

03/20/08 09:15:14 changed by fermulator

OK I was wrong, it doesn't work ...

The menu itself shows up, but clicking on a project doesn't do anything

03/20/08 09:22:53 changed by fermulator

  • cc changed from alvaro.iradier@intelcard.com, airadier@intelcard.com to alvaro.iradier@intelcard.com, airadier@intelcard.com, coderanger.

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.

03/28/08 15:48:56 changed 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?

03/28/08 16:26:43 changed 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.

03/31/08 03:33:52 changed 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?

04/01/08 10:03:15 changed by fermulator

  • attachment web_ui.py.2.diff added.

Updated web_ui.py.diff for 0.11 & environment caching

04/01/08 10:05:04 changed 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?

04/01/08 11:23:54 changed 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.

(follow-up: ↓ 12 ) 06/02/08 10:55:04 changed by wbranderson@gmail.com

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

(in reply to: ↑ 11 ) 06/02/08 11:51:23 changed 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.

(follow-up: ↓ 14 ) 06/02/08 12:10:40 changed by wbranderson@gmail.com

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

dchrome?.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?

(in reply to: ↑ 13 ; follow-up: ↓ 15 ) 08/04/08 14:38:04 changed by kmx

Your (wbranderson@gmail.com) 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)

(in reply to: ↑ 14 ) 08/04/08 15:34:49 changed by wbranderson@gmail.com

Yea, I fixed the problem shortly after posting the ticket. All is well. Thanks for the help.

Replying to kmx:

Your (wbranderson@gmail.com) 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) }}}

08/24/08 21:37:18 changed by anonymous

  • attachment web_ui.py added.

11/06/08 13:01:53 changed by anonymous

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


Add/Change #1892 (0.11 Compatibility Patch)




Change Properties
Action