Friday, June 19, 2009

Countdown shell (bash) script


function countdown () {
a=$1
while [ $a -gt 0 ]; do
echo $a;
a=$(($a-1));
done
}
for i in `countdown 10`; do echo $i; sleep 0.1; done

Thursday, June 18, 2009

How to change Plone's default folder listing sort order

Note: you may also want to look at this article, which show how to add new content on the top of a folder instead of at the bottom.

The easy, all-Plone way to change Plone's folder sort order is to create a Collection (or Smart Folder, or Topic) which you can configure through the web to display items from wherever you please, in whatever order you please. I think you should consider using a Collection first. For example, look how the "News" folder is set up in in a fresh Plone install. It contains a Collection which is used as the default view for the folder.

See the documentation on using Collections.

And now, the entering-a-world-of-pain way:

The folder_listing and folder_contents views use the script getFolderContents (in CMFPlone) to get brains objects.

If you want to modify the default order in which items are listed in your site, you can customize this script by adding these lines:

# Modification to alter sort order
contentFilter['sort_on'] = "modified"
contentFilter['sort_order'] = "descending"


If you wanted a different sort order for different folders, you could place the script in the folder itself. Acquisition should take care of that. (Haven't tried this myself yet.)

I have tested this on Plone 2.5, but it should work equally well on Plone 3.2.2, as the getFolderContents script is still present there.

Note that this will disable the feauture that allows you to sort the folder by hand!

Monday, June 15, 2009

Creating a Plone 2.5 buildout with slideshowfolder 4.0

Slideshowfolder 4.0 can work on Plone 2.5, but it requires plone.app.form.

The default buildout from paster create -t plone2.5_buildout requires some tweaking. I checked out http://svn.plone.org/svn/plone/plone.app.form/branches/plone-2.5 in develop-eggs/ and used the buildout.cfg below. Note that you have to explicitly include Five 1.4.4 (Zope ships with a 1.3 version) and CMFonFive.

[buildout]
parts =
plone
zope2
productdistros
instance
zopepy


# Add additional egg download sources here. dist.plone.org contains archives
# of Plone packages.
find-links =
http://dist.plone.org
http://download.zope.org/ppix/
http://download.zope.org/distribution/
http://effbot.org/downloads

# Add additional eggs here
# elementtree is required by Plone
eggs =
elementtree
plone.app.form
Products.slideshowfolder

# Reference any eggs you are developing here, one per line
# e.g.: develop = src/my.package
develop =
develop-eggs/plone.app.form

[plone]
# For more information on this step and configuration options see:
# http://pypi.python.org/pypi/plone.recipe.distros
recipe = plone.recipe.distros
urls = http://launchpad.net/plone/2.5/2.5.5/+download/Plone-2.5.5.tar.gz
nested-packages = Plone-2.5.5.tar.gz
version-suffix-packages = Plone-2.5.5.tar.gz

[zope2]
# For more information on this step and configuration options see:
# http://pypi.python.org/pypi/plone.recipe.zope2install
recipe = plone.recipe.zope2install
fake-zope-eggs = true
additional-fake-eggs =
ZODB3
url = http://www.zope.org/Products/Zope/2.9.10/Zope-2.9.10-final.tgz

# Use this section to download additional old-style products.
# List any number of URLs for product tarballs under URLs (separate
# with whitespace, or break over several lines, with subsequent lines
# indented). If any archives contain several products inside a top-level
# directory, list the archive file name (i.e. the last part of the URL,
# normally with a .tar.gz suffix or similar) under 'nested-packages'.
# If any archives extract to a product directory with a version suffix, list
# the archive name under 'version-suffix-packages'.
[productdistros]
# For more information on this step and configuration options see:
# http://pypi.python.org/pypi/plone.recipe.distros
recipe = plone.recipe.distros
urls =
http://codespeak.net/z3/five/release/Five-1.4.4.tgz
http://codespeak.net/z3/cmfonfive/release/CMFonFive-1.3.4.tgz
nested-packages =
version-suffix-packages =

[instance]
# For more information on this step and configuration options see:
# http://pypi.python.org/pypi/plone.recipe.zope2instance
recipe = plone.recipe.zope2instance
zope2-location = ${zope2:location}
user = admin:admin
http-address = 1235
debug-mode = on
verbose-security = on

# If you want Zope to know about any additional eggs, list them here.
# This should include any development eggs you listed in develop-eggs above,
# e.g. eggs = Plone my.package
eggs =
${buildout:eggs}


# If you want to register ZCML slugs for any packages, list them here.
# e.g. zcml = my.package my.other.package
zcml =
plone.app.form

products =
${buildout:directory}/products
${productdistros:location}
${plone:location}

[zopepy]
# For more information on this step and configuration options see:
# http://pypi.python.org/pypi/zc.recipe.egg
recipe = zc.recipe.egg
eggs = ${instance:eggs}
interpreter = zopepy
extra-paths = ${zope2:location}/lib/python
scripts = zopepy

Thursday, June 11, 2009

Testing cookies with wget

I noticed an odd behaviour on one of our websites, hosted by an external party: When cookies exceeded a certain length, our Plone site didn't get any cookies in the request.

An excellent way to find the point of failure here is to use wget in combination with a script which prints the cookies it gets. Create a file cookie.txt:
your.domain.com  FALSE  / FALSE 0 cookie_id "SomeCookieValue"

This file must be tab-separated! Wget will not display error messages if your cookie file is corrupt.

Next, run
wget -qO - --load-cookie cookie.txt http://your.domain.com/showCookies

where showCookies is a page that wil simply print the cookies it gets. (-O - sends output to terminal instead of file, q turns off other info.)

In my case, i used several cookie files: for each domain, a short cookie (8 chars value) and a long one (2000 characters). This way, i was able to determine that the current Debian/Ubuntu (Intrepid) Pound package (version 2.4.3) doesn't deal well with cookies: when cookie data exceeds about 500 bytes, the cookies aren't passed to the application. Hand-compiling version 2.4.4 remedies this.

Update: More info on limited cookie(s) size with Pound.