Entries : Category [ Zope ]
[OpenBSD]  [BSD]  [FreeBSD]  [Linux]  [Security]  [Python]  [Zope]  [Daily]  [e-shell]  [Hacks]  [PostgreSQL]  [OSX]  [Nintendo DS]  [enlightenment]  [Apache]  [Nintendo Wii]  [Django]  [Music]  [Plone]  [Varnish]  [Lugo]  [Sendmail]  [europython]  [Cherokee]  [self]  [Nature]  [Hiking]  [uwsgi]  [nginx]  [cycling]  [Networking]  [DNS] 

04 marzo
2009

ImportError: No module named i18n.normalizer.interfaces

this one was hard to solve...

Today I've found one of those ugly problems that took me some time to resolve. In one of my servers I've a Zope instance that was created using a Zope install from the FreeBSD ports collection (pretty useful if you only need plain Zope, as it was my case). Since I installed such version of Zope, I've added a plone "production" buildout to the same server and everything was running smoothly... until I had to restart my original Zope instance (which, yes, has an old plone site inside too). Zope restarted correctly, but when trying to access the plone site, I got a message about the plone site being broken... wtf?.

I took a look over the event.log file of the Zope instance, and I found this error:

ImportError: No module named i18n.normalizer.interfaces

Pretty strange... but seems I wasn't the first one with this problem. In the end it was a path-related problem, as the python process running Zope was picking up some modules from the site-packages directory, instead of the instance lib/python directory.

Final solution?, easy, I just modified my zopectl script to get something like:

#! /bin/sh

PYTHON="/usr/local/bin/python2.4"
ZOPE_HOME="/usr/local/www/Zope210"
INSTANCE_HOME="/usr/local/www/zope2105"
CONFIG_FILE="/usr/local/www/zope2105/etc/zope.conf"
SOFTWARE_HOME="/usr/local/www/Zope210/lib/python"
PLONE_SOFTWARE_HOME="$INSTANCE_HOME/lib/python"
PYTHONPATH="$SOFTWARE_HOME:$PLONE_SOFTWARE_HOME:$PYTHONPATH"
export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME

ZDCTL="$SOFTWARE_HOME/Zope2/Startup/zopectl.py"

exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@"

Setting PLONE_SOFTWARE_HOME and adding it to the PYTHONPATH var.

(of course I should have moved the plone site into the buildout, but that is another story...)

Posted by wu at 16:06 | Comments (0) | Trackbacks (0)
29 octubre
2009

Removing COREBlog moderated/spam comments

a must-have for COREBlog users

For more than 2 years now, I've been using COREBlog as the software to run my personal blog (the first post in this blog is clear enough about this topic) and I'm pretty happy with it. It is somehow an old piece of software, and it probably doesn't have a lot of new-and-shiny features, but it is easy to use, it allow me to write my posts in restructuredText and it runs on top of Zope.

Some months ago I had to add some extra-stuff to it (I wrote about it here) to avoid spam comments (that suddenly began to be a lot of them) and it has been working nicely since then (almost no spam comments got through and even in case any got, I received an email so I could remove it manually).

This setup was almost perfect, but some weeks ago I encountered another problem, the number of spam comments is really really high and it was a waste of resources to keep them in the ZODB. So, I began to search for easy-to-use programatically/batched way to remove the comments that were moderated (closed/hidden) as all of them were spam comments.

I couldn't find anything useful, so I decided to take a look at COREBlog's source code and, finally, I've made a small script of my own to do the job.

Here is the script:

http://paste.e-shell.org/python269428765

And now let me tell you how to use it.

Ok, first you have to open your browser and go to your Zope server ZMI and then click on your COREBlog instance, then click on the Contents tab:

Click on the contents tab

Then you will see the list of objects, folders, scripts, etc within your COREBlog instance, just click on the methods folder:

Click on the methods folder

There you will see some python scripts (the usual hooks) probably, you will need to add another python script, using the combo select near the Add button:

Add another Python script

Use the value you prefer for the Id field (drop_comments for me) and click the Add and Edit button:

Add and Edit the new script

After that you will see the usual screen with a big textarea, where you can edit your script. Remove all the stuff in there (it is some example code) and paste there the code from my script here:

After pasting the code click the Save Changes button.

Paste the code within the textarea and save it

You will see a small message advicing you that the script has been saved succesfully.

Now click in the Test tab, so the script will be executed and all the moderated comments will be removed from your COREBlog instance.

Click on the Test tab

After a while (it will depend on how many moderated messages you have) you will see a screen with a small report/list telling you which comments (title + author) were deleted for each entry.

Of course, it shouldn't be a bad idea to do a copy of your COREBlog instance first (pretty easy in the ZMI), just in case you forgot any valid comment moderated and you would like to restore it (oh, well, there is even the chance to rollback all the operation using the Undo tab...).

Hope you would find it useful, it was for me!

AH!, almost forgot And do not forget to Pack your ZODB so the removed comments are removed properly from the ZODB (remember that Zope retains older objects so you can undo your transactions/operations)

Posted by wu at 08:56 | Comments (0) | Trackbacks (0)
05 noviembre
2009

Coding party: getting in touch with Zope again

sooner or later I should do this...

Seems I'm definetely getting back to some old habits. If two weeks ago I did a FreeBSD install party, tonight it is time to get in touch with Zope again.

Zope.org, Zope's home

After a lot of months working almost exclusively in a big django-based project, it is time to get back to another project (this one Zope-based) as there is some work to do on it. It has been a long time since my last contribution to it, in fact its code is in some kind of frozen state and I want to do some clean up before releasing it under an open source license.

The most important change is to put a lot of stuff developed through the ZMI into a classic Zope Product (that is, put all of the objects from the ZMI into files in the filesystem and add some magic code to glue them alltogether).

One of the special things about this app is that it uses PostgreSQL as the backend to store all data instead of the ZODB (WTF was I thinking back then???) so it has some dependencies I have to take care of, as well as a lot of ZSQL methods I have to take care of too.

So, the roadmap should be something like:

1- Create a simple Zope product that could be used as a base for all the work (base classes, manage_add* methods and templates, etc)

2- Put all the static content in the filesystem (zope templates, css files, javascript files, images, etc)

3- Put all the ZSQL methods into the filesystem

4- Add some magic methods to use the ZSQL objects from the filesystem without the need to put them back into the ZMI

5- Add a code that automatically creates the ZPsycoPg connection object that will be used to execute the ZSQL methods.

6- Add a code that automatically creates the exUserFolder acl_users folder that will be used for authentication (this will use the ZPsycoPg connection to get user information from the PostgreSQL database). Well, this is the way we authenticate users in this up now, but we could change it if posible (to avoid this dependency).

This is a first approach to a roadmap for the project. I've been working in steps 1 and 2, but for step 3 I needed some help, so it was time to read a little bit about it (and that's exactly the point where I'm right now). Luckily I've found some good docs about such topic:

I even found a tool that could help:

and some information about how to set up caching properties in the proper ZSQL method file:

Man, I love open source software and open source developers... ;D

Posted by wu at 00:01 | Comments (0) | Trackbacks (0)
23 marzo
2010

Add Youtube videos to a Zwiki or COREBlog site

easily, using your old rst-editing-style

Some days ago I found this custom rst directive (thnx MarcosBL) that allows us to embed a Youtube video in a reStructuredText document just adding something like this to it:

.. youtube:: <video-id>

I'm not a fan of embeding flash videos within my blog or wiki sites, mostly because I don't like flash at all (I even don't have the dammned flash plugin installed in most of my browsers), but for certain sites it could be useful, so let's see how to add support for this custom directive.

In COREBlog

In COREBlog you can already add Youtube videos in your posts, you only have to switch your markup to HTML and add in your post the html code provided by Youtube itself. Of course, this is not what we want as it prevents us from using rst to edit the posts.

So, first download the directive from here and save it in a file called youtube.py within your COREBlog Product folder (the one with the file COREBlog.py inside) in your Zope instance.

Then, edit the file COREBlog.py and import the youtube stuff:

import youtube

Finally, you have to restart your Zope instance.

In Zwiki

The process is quite similar, just download the code from here and save it as youtube.py in your Zwiki Product Folder (the one with the file ZWikiPage.py inside).

Then, edit the file ZWikiPage.py and import the youtube stuff at the beginning of the file (you will see where the other import statements are):

import youtube

Finally, restart your Zope instance.

How to use it

Easiest part, just go to Youtube and pick up a video, for example:

Good, now you will need the id of that video:

  • http://www.youtube.com/watch?v= IaM5MgJqtdA

Finally, you only have to add something like this to your page:

.. youtube:: IaM5MgJqtdA

This code results in something like this:

You can add some extra parameters, like width and height of the video (just take a look at the directive's code to see options):

.. youtube:: IaM5MgJqtdA
  width=400
  height=300

And this is the resulting embedded video:

Conclusion

Easy, isn't it? There are a lot of other useful directives out there (like the pygments one I covered in a previous post). Imho, rst is one of the most flexible and powerful markup languages out there, and it is always nice to find out this kind of stuff.

Enjoy!

Posted by wu at 08:39 | Comments (0) | Trackbacks (0)
Prev  1   [2]