Easily install all Python versions under Linux and OSX using collective.buildout.python

Note: This information is old. Please head to Github collective/buildout.python for recent information.

Here are short instructions how to install all versions (2.4, 2.5, 2.6, 2.7 and 3.1) of Python interpreters on UNIX system. The instructions were tested on Ubuntu 10.04 Lucid Lynx Linux but should work on other systems as is. The installation is based of downloading, compiling and installing different Pythons and their libraries using buildout tool. A buildout configuration for doing this is maintained by a Plone community.

This buildout is especially useful to get Python 2.4 properly running under the latest Ubuntu 10.04 Lucid Lynx. This is because Ubuntu repositories won’t ship with Python 2.4 packages anymore.

The installation will also include static compilation of some very popular libraries. These are dependencies for other Python packages including, but not limited, to

  • libjpeg
  • Python imaging library
  • readline

1. Prerequisites

  • Some Python version is installed (OS default)
  • GCC compiler is installed (sudo apt-get install build-essential)
  • Subversion tool is installed (sudo apt-get install subversion)

2. Running it

svn co http://svn.plone.org/svn/collective/buildout/python/
cd python
python bootstrap.py
bin/buildout

3. Using it

All Pythons are under virtualenv installations. This means that you can activate one Python configuration for your shell once easily (python command will run under different Python versions).

Activating Python 2.4

source python/python-2.4/bin/activate
(python-2.4)moo@murskaamo:~/code$ python -V
Python 2.4.6

Check that Python Imaging Library works

python
Python 2.4.6 (#1, Jul 16 2010, 10:31:46)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL

(No exceptions raised, Python Imaging Library works well).

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Changing the location of Ubuntu 10.04 Lucid Lynx notification bubble to a different corner

Ubuntu notifications, those grey bubbles for incoming instant messages and such, are in the top right corner under the system tray area by default. Many applications, like Google Chrome browser, place lots of controls there and notifications might block them. Also, you might prefer some other corner due to your personal taste. The application for responsible for those bubbles is called notify-osd.

Here are instructions how get a custom notification-osd which can read a config file where you can specify settings for the notifications. Though it requires you to install a custom notify-osd version, the instructions are plain and simple. For less hardcode users, there also exists a version with graphical user interface to configure notify-osd.

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Nokia direct offline maps download links – no Windows software needed

Updated Nokia offline map download links here.

Here (old).

You can download files using your mobile browser and then with little shell/file explorer magic  install them by placing files to proper folder on the internal memory.

Alternatively download using desktop browser and copy the files to the memory card over USB.

The folder varies per device. Let it cache map data bit and see where it stores it on the storage first.

The files apply for all Nokia devices, including N8 and N9 too.

 

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Automatically generating description based on body text

Below is a sample script to automatically generate descriptions based on page body text. It is for Plone CMS, but should be applicable to any Python based CMS with some modifications.

The idea is that we take three first sentences and use them as a description.

Use case: People are lazy to write descriptions (descriptions as in Dublin Core metadata). You can generate some kind of description by taking the few first sentences of the text. This is not perfect, but this is way better than empty description. Also, the script comes with good comments which should be helpful for beginner Plone programmers.
Please comment if you have other simple ideas to generate descriptions.
Usage
  • Add  Script (Python) item through Zope Management interface to any Plone folder
  • Put in the code payload below
  • Hit Test tab or type in Script URL manually – note that the operation is one shot only
  • The script iterates through all content items in that folder
  • The script will provide logging output to standard Plone log (var/log and stdout if Plone is run in the debug mode).

Since Zope uses RestrictedPython for through-the-web created scripts, the user of this script cannot breach the server security (they cannot make Python calls they have no permission for). This sets some limitations for automating tasks like this, but we don’t hit those limitations in our use case.

def create_automatic_description(content, text_field_name="text"):
    """ Creates an automatic description from HTML body by taking three first sentences. 

    Takes the body text

    @param content: Any Plone contentish item (they all have description)

    @param text_field_name: Which schema field is used to supply the body text (may very depending on the content type)
    """

    # Body is Archetype "text" field in schema by default.
    # Accessor can take the desired format as a mimetype parameter.
    # The line below should trigger conversion from text/html -> text/plain automatically using portal_transforms
    field = content.Schema()[text_field_name]

    # Returns a Python method which you can call to get field's
    # for a certain content type. This is also security aware
    # and does not breach field-level security provded by Archetypes
    accessor = field.getAccessor(content)

    # body is UTF-8
    body = accessor(mimetype="text/plain")

    # Now let's take three first sentences or the whole content of body
    sentences = body.split(".")

    if len(sentences) > 3:
       intro = ".".join(sentences[0:3])
       intro += "." # Don't forget closing the last sentence
    else:
       # Body text is shorter than 3 sentences
       intro = body

    content.setDescription(intro)

# context is the reference of the folder where this script is run
for id, item in context.contentItems():
     # Iterate through all content items (this ignores Zope objects like this script itself)

     # Use RestrictedPython safe logging.
     # plone_log() method is permission aware and available on any contentish object
     # so we can safely use it from through-the-web scripts
     context.plone_log("Fixing:" + id)

     # Check that the description has never been saved (None)
     # or it is empty, so we do not override a description someone has
     # set before automatically or manually
     desc = context.Description() # All Archetypes accessor method, returns UTF-8 encoded string

     if desc is None or desc.strip() == "":
          # We use the HTML of field called "text" to generate the description
          create_automatic_description(item, "text")

# This will be printed in the browser when the script completes succesfully
return "OK"

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+