The wrong way to sudo su, and the right way

I've never had a formal training on Linux. My knowledge comes from my experience working on it for the last 12 years, but some things I've just learned as simple recipes and never bother looking them up. One such thing was changing users with sudo. I've been doing it as: sudo su <user> - Notice the dash at the end, which makes provides a "real" environment for <user>, just as if I would have logged in with that user, directly. [...]

Essential Firefox addons

Without these addons, Firefox may not be my favourite browser. With them, it's a beast that has no match among all other browsers. So, a top 10 of my favourite extensions: Vimperator: the essential plugin, makes Firefox behave in a modal manner similar to VIM. Includes many shortcuts similar to vim. Integrates an external editor (like GVim) with any textarea. My favourite things with it: really fast opening/closing of tabs, URL address copying and pasting, follow links, etc. [...]

A simple epub file renaming utility

I have a couple of epub files that have random names assigned to them, and I wanted to rename them based on their metadata, in the form Author - Title. Below is what I came up with: #!/usr/bin/python from zipfile import ZipFile import lxml.etree import os.path import shutil import sys namespaces = { 'u':"urn:oasis:names:tc:opendocument:xmlns:container", 'xsi':"http://www.w3.org/2001/XMLSchema-instance", 'opf':"http://www.idpf.org/2007/opf", 'dcterms':"http://purl.org/dc/terms/", 'calibre':"http://calibre.kovidgoyal.net/2009/metadata", 'dc':"http://purl.org/dc/elements/1.1/", } def main(): if len(sys.argv) != 2: print "Need a path." sys. [...]

Getting the superclasses for a python object

Zope 2 (and Plone) persistent objects usually have an intricate inheritance tree. Finding what classes an object inherits can be a time consuming task, hunting through the various eggs for the relevant source code. Below is a little snippet that shows how to easily get the list of superclasses: (Pdb) pp type(ff).mro() (<class 'plone.app.blob.subtypes.image.ExtensionBlobField'>,  <class 'archetypes.schemaextender.field.TranslatableExtensionField'>,  <class 'archetypes.schemaextender.field.BaseExtensionField'>,  <class 'plone.app.blob.field.BlobField'>,  <class 'Products.Archetypes.Field.ObjectField'>,  <class 'Products.Archetypes.Field.Field'>,  <class 'Products.Archetypes.Layer.DefaultLayerContainer'>,  <class 'plone.app.blob.mixins.ImageFieldMixin'>,  <class 'Products.Archetypes.Field.ImageField'>,  <class 'Products. [...]

Version conflict: zc.buildout's version of madness

I'm not even trying to understand what happens, because it's aggravating to see buildouts fail like this: While:   Installing.   Getting section zope2.   Initializing section zope2.   Installing recipe plone.recipe.zope2install. Error: There is a version conflict. We already have: setuptools 0.6c9 or, worse, this: While:   Installing.   Getting section zope2.   Initializing section zope2.   Installing recipe plone.recipe.zope2install. Error: There is a version conflict. We already have: zc. [...]

Building PIL with JPEG support on Ubuntu 11.04

I had problems building PIL with jpeg support on the latest Ubuntu. There are now two libjpeg libraries: one called libjpeg62 and one libjpeg8. Every guide on the net explaining how to compile PIL with jpeg support points to installing libjpeg62-dev. Needless to say, libjpeg8-dev is actually needed to properly build PIL. My reason for initially avoiding libjpeg8 is that it causes libsdlimage-dev to be uninstalled, so it looks like I'll have to juggle packages whenever I want to compile something that requires SDL. [...]

Export/import users in and out of Plone

A dirty quick method of importing and exporting the users (only usernames and passwords) out of Plone, using 2 external methods. Code below, not much else to say. import cPickle def export(self): pas = self.acl_users users = pas.source_users passwords = users._user_passwords result = dict(passwords) f = open('/tmp/out.blob', 'w') cPickle.dump(result, f) f.close() return "done" def import_users(self): pas = self.acl_users users = pas.source_users f = open('/tmp/out.blob') res = cPickle.load(f) f.close() for uid, pwd in res. [...]

Set product configuration globally in zope.conf

I have a Zope product that needs to write in a centralized location, across multiple instances. The classic Python solution would be to write a variable in a config.py module and read that location from the code, but this feels unelegant in an environment that uses zc.buildout for deployment. The solution I have found is, as follows: In buildout.cfg, in the instance part definition, add: zope-conf-additional =     <environment>         mylocation ${buildout:directory}/var/mylocation     </environment> Next, inside the product code I have: [...]

Running Products.Gloworm on Plone 4

For some reason, the TTW developer tools tend to get neglected in the Plone world. A valuable tools such as Clouseau has fallen out of favour and now Gloworm, the @@manage-viewlets replacement/complement won't run in Plone 4 (at least at version 1.0, which is the latest right now on PyPI). Fortunately, Gloworm has been updated in svn trunk. To get the latest version you need to add it to sources (in buildout. [...]

A pattern for programatically creating Plone content

I'm importing content from a legacy system to a new website that I'm doing with Plone 4 (wow! what an improvement, in speed and technology) and was looking at the existing documentation on how to programatically create new Plone content. The issue I'm having with the existing documentation is that it's incomplete. It won't give you automatically created ids, you'll have to manually call mutators if you don't know any better, etc. [...]