官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 缙云县| 尉氏县| 武冈市| 长海县| 古田县| 阿鲁科尔沁旗| 二连浩特市| 富源县| 尤溪县| 九寨沟县| 剑阁县| 莱州市| 平遥县| 高州市| 临江市| 会昌县| 东阿县| 华亭县| 五指山市| 庆阳市| 鄂托克旗| 中宁县| 利津县| 通榆县| 彰武县| 政和县| 鄂托克旗| 集安市| 诸城市| 鄂托克旗| 县级市| 闽清县| 米泉市| 康平县| 鄂伦春自治旗| 屏东县| 定安县| 辉南县| 潞西市| 自贡市| 开化县|