#2031: [PATCH] Catwalk can't create "/catwalk-session" when deploying using
mod_wsgi
-----------------------------+----------------------------------------------
 Reporter:  llucax           |       Owner:  anonymous
     Type:  defect           |      Status:  new      
 Priority:  normal           |   Milestone:  1.1      
Component:  Toolbox.Catwalk  |     Version:  1.0.4.4  
 Severity:  critical         |    Keywords:  patch    
-----------------------------+----------------------------------------------
 Hi. I've just upgraded to Ubuntu Intrepid (8.10) which comes with TG
 1.0.4.4 from an Ubuntu Hardy (8.04) which came with TG 1.0.2.2 and I think
 I've hit a regression.

 I've deployed my app using apache's mod_wsgi and I'm "mounting" Catwalk at
 my root controller using something like this:

 {{{
 admin = identity.SecureObject(CatWalk(model),
 identity.has_permission('admin'))
 }}}

 This worked perfectly in 1.0.2.2 (and still works perfectly in 1.0.4.4 if
 I use the built-in cherrypy server running start-myproj.py) but now I get
 this error:

 {{{
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220] mod_wsgi
 (pid=6351): Target WSGI script '/var/www/entregas/index.wsgi' cannot be
 loaded as Python module.
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220] mod_wsgi
 (pid=6351): Exception occurred processing WSGI script
 '/var/www/entregas/index.wsgi'.
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220] Traceback
 (most recent call last):
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]   File
 "/var/www/entregas/index.wsgi", line 25, in <module>
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]     import
 sercom.controllers
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]   File
 "/var/lib/sercom/sercom/sercom/controllers.py", line 83, in <module>
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]     class
 Root(controllers.RootController):
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]   File
 "/var/lib/sercom/sercom/sercom/controllers.py", line 251, in Root
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]     admin =
 identity.SecureObject(CatWalk(model), identity.has_permission('admin'))
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]   File
 "/var/lib/python-
 support/python2.5/turbogears/toolbox/catwalk/__init__.py", line 133, in
 __init__
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220]     "CatWalk
 failed to load your model file.\\n" + str(e))
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220] ImportError:
 CatWalk failed to load your model file.
 [Wed Nov 12 20:44:36 2008] [error] [client 190.226.108.220] [Errno 13]
 Permission denied: '/catwalk-session'
 }}}

 I digged a little and found that this exception was masked by this code
 (on catwalk/__init__.py arround line 133 like the traceback says):

 {{{
        except Exception, e:
             raise ImportError, (
                 "CatWalk failed to load your model file.\n" + str(e))
 }}}

 So I temporarily remove that try/except block and found the original
 exception was thrown in the same file, arround line 600 in the
 state_path() method):

 {{{
  597         catwalk_session_dir =
 os.path.join(turbogears.util.get_package_name()
  598             or '', 'catwalk-session')
  599         catwalk_session_dir = os.path.abspath(catwalk_session_dir)
  600         if not os.path.exists(catwalk_session_dir):
  601             try:
  602                 os.mkdir(catwalk_session_dir)
  603             except IOError, e:
  604                 msg = 'Fail to create session directory %s' % e
  605                 raise cherrypy.HTTPRedirect(turbogears.url('error',
 msg=msg))
  606         return os.path.join(catwalk_session_dir, 'session.pkl')
 }}}

 There are several problems here:
 1. `turbogears.util.get_package_name()` returns nothing, so
 `catwalk_session_dir` is
    "/catwalk-session" in line 597. I made
 `turbogears.util.get_package_name()` return "myproj"
    adding a `package = "myproj"` in the config file, so I could get
 `catwalk_session_dir` being
    "myproj/catwalk-session". But this doesn't fix the problem.
 2. line 599 makes `catwalk_session_dir` be "/myproj/catwalk-session",
 because it looks like for
    mod_wsgi the current working directory is "/".
 3. In line 603, `OSError` should be catched too (permission denied is an
 `OSError`).

 Since I didn't knew how to fix this properly, I've made a simple change to
 be able to specify via config file where the catwalk-session directory
 should be:

 {{{
 --- /tmp/catwalk.__init__.py.orig       2008-11-12 21:08:38.000000000
 -0200
 +++ /var/lib/python-
 support/python2.5/turbogears/toolbox/catwalk/__init__.py    2008-11-12
 21:38:05.000000000 -0200
 @@ -594,13 +594,15 @@ class CatWalk(turbogears.controllers.Con
          Create a session directory if nescesary.

          """
 -        catwalk_session_dir =
 os.path.join(turbogears.util.get_package_name()
 -            or '', 'catwalk-session')
 +        catwalk_session_dir = turbogears.config.get('catwalk.session-
 dir', None)
 +        if catwalk_session_dir is None:
 +            catwalk_session_dir =
 os.path.join(turbogears.util.get_package_name()
 +                or '', 'catwalk-session')
          catwalk_session_dir = os.path.abspath(catwalk_session_dir)
          if not os.path.exists(catwalk_session_dir):
              try:
                  os.mkdir(catwalk_session_dir)
 -            except IOError, e:
 +            except (IOError, OSError), e:
                  msg = 'Fail to create session directory %s' % e
                  raise cherrypy.HTTPRedirect(turbogears.url('error',
 msg=msg))
          return os.path.join(catwalk_session_dir, 'session.pkl')
 }}}

 Then I add:

 {{{
 catwalk.session-dir = "/path/to/my/catwalk-session"
 }}}

 And all works as expected.

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2031>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to