Search This Blog

27 April 2011

zc.buildout in Ubuntu 10.04 LTS

you have a nice buildout in development and it's time to move to the production server

buildout bootstrap
./bin/buildout
.... 
     pkg_resources.Requirement.parse('zc.buildout')).location
AttributeError: 'NoneType' object has no attribute 'location'

ouch!

this workaround worked for me
sudo easy_install zc.buildout==1.4.4
buildout bootstrap

zc.buildout will upgrade itself (to 1.5.2 at the time of writing)

and ./bin/buildout will work again as it should

13 April 2011

using toscawidget behind apache mod_wsgi

Turbogears Ticket #2309

The problem, when it occurred, would be visible when someone clicked the login link (going to /login ). The came_from would, sometimes, be set to "/toscawidgets/resources". When I remove the "modname" parameter from the JSLink above, the problem never occurs.

Quick fix: in the .wsgi script add those 3 lines at the end

import paste.fixture
app=paste.fixture.TestApp(application)
app.get("/") 

Full explanation (copy/paste from Diez Roggish) (http://groups.google.com/group/turbogears/browse_thread/thread/ca4e3fd12a49d44/fa8721260b68741b)

The snippet will in fact force the mod_wsgi-process to pre-load the full application controller hierarchy. As a result, all the tosca-widgets should be instantiated, and their resources registered in the resource-middleware.

The reason this needs to be done is because usually, you run mod_wsgi with several processes. Lets name these P1-P10.

Now if a request hits a freshly started apache (without the "magic lines"), it hits P1. That initial request is directed at a controller action, so the full TG2 app with it's controller hierarchy is bootstrapped. All is nice and easy.

The resulting HTML now contains several references to static resources from TW. So the browser will - in parallel - request these. Because P1 is just finished, it probably won't even getting any of these requests. Instead, the are distributed amongst P2-P10.

And these processes are not bootstrapped yet. So, TW doesn't know about any resources when asked, and the result is a 404 or 500.

And for that reason, the "magic snippet" is there.

It is unfortunate, but I don't see any other way. You could try & have some sort of finalizing method-call into the Pylons/TG2-stack that essentially does the same, but the underlying technology won't be changeable.

01 April 2011

Playing with time zones

>>> from datetime import datetime
>>> import pytz
>>> from pytz import timezone

>>> utc = pytz.utc
>>> paris = timezone('Europe/Paris')

>>> now = datetime.utcnow()
>>> utc_now = now.replace(tzinfo=utc)
>>> utc_now
datetime.datetime(2011, 4, 1, 15, 30, 39, 337114, tzinfo=)
>>> utc_now.astimezone(paris)
datetime.datetime(2011, 4, 1, 17, 30, 39, 337114, tzinfo=)

04 March 2011

patching an external lib at TurboGears startup

sometimes it is useful to monkey patch an external lib

in lib/patches.py

import logging
log = logging.getLogger(__name__)

from tw.jquery import ui
from tw.api import JSLink

# update to release 1.8.9
jquery_ui189 = JSLink(modname=__name__,
               filename='public/javascript/jquery.ui.all.js')

log.warning("Patching jquery.ui.all.js to 1.8.9")
ui.jquery_ui_all_js = jquery_ui189


now we need to inform TG of our patch

in project/config/middleware.py

import qubic.backoffice.lib.patches

that's it, at startup you should see :

Starting subprocess with file monitor
16:14:12,260 WARNI [project.lib.patches] Patching jquery.ui.all.js to 1.8.9

new releases

Long time without any post, time to update

I've recently released new packages and upgrades
is a tosca widget wrapper around the uploadify jquery plugin. It allows to send files to the server with a nice progress bar.
Flash required
this very small package allows to include .dot files in sphinx documentation and have them renderered with graphviz.
Sphinx easily accepts inline graph definition, but not inclusion of graph definition.
is now released in 0.3.1

07 January 2011

genshi in turbogears and HTML

I've had problems with textarea widgets (from toscawidget) and with my tw.jqgrid since the upgrade of genshi.
the widget might generate a <texarea></textarea>

as the content is empty, genshi will output this in XHTML as <texarea/> and most browser will render the html source *inside* the text area.


http://trac.turbogears.org/ticket/2287

if you want to force genshi to output html, in your development.ini :

[DEFAULT]
debug = true
# Uncomment and replace with the address which should receive any error reports
#email_to = you@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost
templating.genshi.method = HTML