Modify

Opened 10 years ago

Closed 3 years ago

Last modified 3 years ago

#1892 closed enhancement (fixed)

[PATCH] 0.11 Compatibility Patch

Reported by: airadier@… Owned by: Ryan J Ollos
Priority: high Component: ProjectMenuPlugin
Severity: critical Keywords:
Cc: alvaro.iradier@…, Noah Kantrowitz, Ryan J Ollos 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)

web_ui.diff (1.6 KB) - added by airadier@… 10 years ago.
Patch for web_ui.py, 0.11 Compatibility
web_ui.py.diff (2.5 KB) - added by alvaro.iradier@… 10 years ago.
Updated patch (includes additional required modifcations)
web_ui.py.2.diff (2.1 KB) - added by Matt Callaghan 10 years ago.
Updated web_ui.py.diff for 0.11 & environment caching
web_ui.py (1.7 KB) - added by anonymous 9 years ago.

Download all attachments as: .zip

Change History (29)

Changed 10 years ago by airadier@…

Attachment: web_ui.diff added

Patch for web_ui.py, 0.11 Compatibility

Changed 10 years ago by alvaro.iradier@…

Attachment: web_ui.py.diff added

Updated patch (includes additional required modifcations)

comment:1 Changed 10 years ago by Matt Callaghan

Cc: alvaro.iradier@… airadier@… added; anonymous removed

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 10 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 10 years ago by Matt Callaghan

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 10 years ago by Matt Callaghan

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 10 years ago by Matt Callaghan

Cc: Noah Kantrowitz 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 10 years ago by Matt Callaghan

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 10 years ago by Noah Kantrowitz

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 10 years ago by Álvaro Iradier

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 10 years ago by Matt Callaghan

Attachment: web_ui.py.2.diff added

Updated web_ui.py.diff for 0.11 & environment caching

comment:9 Changed 10 years ago by Matt Callaghan

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 10 years ago by Álvaro Iradier

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

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

comment:12 in reply to:  11 Changed 9 years ago by Noah Kantrowitz

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 Changed 9 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 ; Changed 9 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 9 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 9 years ago by anonymous

Attachment: web_ui.py added

comment:16 Changed 9 years ago by anonymous

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

comment:17 in reply to:  16 Changed 9 years ago by Florian Seydoux

Replying to anonymous:

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

... apparently not(?) ...too bad!

comment:18 Changed 8 years ago by Ryan J Ollos

Cc: Ryan J Ollos added

comment:19 Changed 8 years ago by Adrian Fritz

Summary: 0.11 Compatibility Patch[PATCH] 0.11 Compatibility Patch

comment:20 Changed 8 years ago by Álvaro Iradier

Cc: alvaro.iradier@… added; alvaro.iradier@… airadier@… removed

comment:21 Changed 6 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 years ago by Ryan J Ollos (previous) (diff)

comment:22 Changed 6 years 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

comment:23 Changed 3 years ago by Ryan J Ollos

Owner: changed from Noah Kantrowitz to Ryan J Ollos
Status: newassigned

comment:24 Changed 3 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

In 14050:

2.0dev: Add script in IRequestFilter. Fixes #1892.

Patch by airadier.

comment:25 Changed 3 years ago by Ryan J Ollos

In 14051:

2.0dev: Use cache in open_environment call. Refs #1892.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.