Plone 3 Products Development Cookbook
上QQ阅读APP看书,第一时间看更新

Applying code changes on-the-fly using plone.reload

When a Zope instance is running in debug mode, most of the changes made in the underlying code (except for templates, Python scripts, and some other resources like CSS) won't be refreshed in the server until it is restarted. This means that if we want to test a new method or if we had detected a problem and solved it, we must restart our Zope server to see the results. At first glance, it doesn't seem to be a big deal. However, in the rush of development or when making lots of little changes in the code, this could really be a pain in the neck. This is especially true if we are working with a production database because they normally take a long time during server launch.

Fortunately , plone.reload can come to our rescue. In a fraction of a second it detects and refreshes all the changes made to the code. Moreover, if we had modified configuration options (not .py files but .zcml, as we'll see in future chapters), we can apply them on-the-fly also.

How to do it…

  1. Add a plone.reload line in the eggs parameter of the [buildout] part.
    [buildout]
    
    ...
    
    # Add additional eggs here 
    eggs = 
     plone.reload
    

How it works…

You just need to point your browser URL to http://localhost:8080/@@reload (notice that @@reload is called on Zope instance root and not on Plone site) and click on the corresponding button to:

  • Reload code (.py files).
  • Reload code and configuration options (.py and .zcml).

After doing this, you'll get a short log about the files that were detected during reload.

Note

plone.reload is available only when Zope is running in debug mode.

Unfortunately, plone.reload does not always work. If you find unexpected error messages (typically ComponentLookupError or could not adapt) in your console, it is most likely that plone.reload couldn't do the whole job properly. In these situations, just restart your instance to continue working.

There's more…

You may want to remember (or save a bookmark in your browser) the URL of the resulting action to speed up your code changes:

  • http://localhost:8080/@@reload?action=code, for code changes
  • http://localhost:8080/@@reload?action=zcml, for code and configuration changes

Note

More information about plone.reload is available at: http://pypi.python.org/pypi/plone.reload.