Archives 2005 - 2019

Archetypes.schemaextender does not create getters and setters for fields

published Mar 06, 2010 02:00   by admin ( last modified Mar 06, 2010 02:00 )

So if you want to access a field's value you have to do it through the content item's schema:

obj.Schema()['fieldname'].get(obj)

In templates (or more actually, views), this means doing it from the python file in a Zope view.

Nein, ich habe gesagt, dass man mit der """ "get" Methode des fields """ an die Daten kommt -> obj.Schema()['fieldname'].get(obj)



Läs mer: [dzug-zope] Probleme mit archetypes.schemaextender und ReferenceField


Plone training in London May 4-6

published Mar 01, 2010 08:51   by admin ( last modified Mar 01, 2010 08:51 )

We've been doing Plone Training in London since 2005, but last autumn we were so swamped with consulting work back home that we could not make it. However we now have scheduled a course for May in London. There is going to be more about buildout, subversion and a preview of Plone 4, otherwise steady as she goes.


Plone training in London July 19-21

published Mar 01, 2010 08:51   by admin ( last modified Mar 01, 2010 08:51 )

We've been doing a lot of development and consulting lately, but I want to go back to more teaching, in Plone and in other subjects. We did a Plone course in Stockholm in April this year and now we will be back with Plone Training in the UK with with a course in July in London.


How to use Edge Side Includes (ESI) with Varnish in Plone

published Mar 01, 2010 08:50   by admin ( last modified Mar 01, 2010 08:50 )

With ESI it is possible to cache the more or less static parts of Plone's pages in Varnish, and "fold in" the dynamic stuff per request. This can in some use cases increase performance massively.

Putting Varnish in front of Plone is a common way to speed up things, and can lead to insane speed increases. However, Plone and Zope are dynamic and tighly coupled frameworks, and it is a bit of a shame to have it serve out essentially static pages. Even if you use something intelligent like CacheSetup (Cache fu), if you make a change that affects a portlet, e.g. "recent comments", you will need to invalidate all pages where that portlet is shown.

Varnish however has support for caching only parts of pages and then fetch the dynamic parts and combine with the static stuff, before serving it out to the visitor. Can Plone be used with it? Yes it can, with some hoop jumping.

The technology of combining pages on the fly is called Edge Side Includes (ESI) and Varnish supports part of the standard. Here is how it works in Varnish:

If you put in a special xml fragment (stanza) like this in your html output:

<esi:include src="/site/@@left_column"/>

...Varnish will fetch the contents of that url (http://yoursite/site/@@left_column), and include it, and replace the stanza with what it finds at that url.

The 123-567.net hobby project

My current hobby project is a salsa dancing web site called 123-567.net. It allows visitors to put together their own salsa dancing routine from short fragments ("Moves"). Moves are connected through positions. It is currently running on our hobby server on the office ADSL connection.

In the right hand column there is a portlet that keeps track of each visitor's routine as it is being built up. No login is required but a captcha tries to keep the salsa dancing away from robots (who suck at dancing anyway, currently, although this may change).

There is one big honking page that lists all moves, and traverses a lot of archetypes references to compute and display all possible moves from each move (and how many moves in its turn can follow each such move). This page basically manages to wake up and excercise every single content object on the site, sometimes multiple times, and the page takes 3-5 seconds to render on a small server. The page cannot be made static, since the contents of the routine portlet will be different for each visitor that uses it.

There are multiple ways of optimizing this page while keeping the portlet dynamic, from RAM-caching with memoize (which brings down the render time of the page to 0.2 s), to using KSS, to using the catalog exclusively for calculating moves.

Memoize seemed like a good solution, but since there are also videos on the site, and I did not want to tie up a Plone process serving each one, I still needed some extra oomph. Varnish should be able to cache the videos and offload Zope's precious processes.

Making the portlet render with ESI

It should be enough to instead of showing the portlet on the page, just show a placeholder for it:

<esi:include src="/site/@@left_column"/>

..and then construct a view by the name "@@left_column" and show the portlet in that view.

Varnish's behavior is controlled by a configuration file, normally called varnish.vcl. The configuration file basically deals with:

  • What it should do with requests coming in
  • What to do with responses going out

The part of the vcl file that deals with responses is a subroutine called vcl_fetch. Here is a simplified part of that code for 123-567.net, with esi enabled:

 

sub vcl_fetch {

    if (req.url == "/site/@@left_column") {
        pass;
    }
   
   
    if (obj.http.Content-Type ~ "html") {
        esi;  /* Do ESI processing */
        unset obj.http.set-cookie;
        set obj.ttl = 24 h;

    }

      

The esi directive as framed above enables esi parsing and caching of all html pages, but first the preceding if clause sees to that the @@left_column is passed through without caching ("pass").

The @@left_column view needs to be constructed, and since the portlet is a proper portlet, I could register its page template file also as a viewlet, but a quicker and dirtier way (the "customer" of this project, i.e. me, is very tolerant of whims and shortcuts :-) is to just put in a the entire portlet renderer into the view.

<metal:block use-macro="here/global_defines/macros/defines"/>

<tal:block replace="structure provider:plone.leftcolumn" />

 

Come to think of it, that may not be quicker... Anyway, now the site renders the page statically but puts in the portlet in varnish. We are down to 50 ms rendering time from 5s rendering time, according to Apache's ab tool (with an empty portlet).

The portlet is context free, it renders the same on all pages. It uses the Zope (not Plone) session machinery and is essentialy independent of Plone, and should render very quickly, if put directly in the view instead of with the above provider stanza. For portlets that need context, one could just put in a cgi parameter in the esi stanza, with the path from the calling page, and then use that to recreate the context on the receiving end.

But now the site is broken without Varnish...

However if we view the site without Varnish the portlet will never materialize on the pages. There will just be stupid esi directive sitting there. I believe it is important that the site can be used without Varnish.

The obvious solution would be this:

<esi:include src="/site/@@left_column">
<--portlet goes here-->
</esi>

One would hope that Varnish would replace the entire esi element. However Varnish is not zpt, and if you put in the above code, Varnish will replace the start tag of the esi element with the portlet, and happily let the rest of the code stay on the page. Viewed through Varnish you would now have two portlets on the page (of which one portlet is stale).

So we need a way for the portlet to "know":

  • If it is behind Vanish
  • If Varnish has any intentions of caching it

It seems you can find this out from the Plone side! Analyzing the contents of the request variable shows that there is an HTTP_X_VARNISH environment variable which will only be present if varnish is in front. That takes care of displaying the portlet when you are directly accessing Zope. But when behind Varnish, how do we now if we are on the page (ouput ESI tag) or on the specially crafted view (output portlet)? One way is to check for path. The specially crafted view has in its id the string "left_column".  Quickly and dirtily we can do it in the page template:

<tal:varnish define= "behind_varnish 
python:context.REQUEST.get('HTTP_X_VARNISH',False);
not_cached_in_varnish python: 'left_column' in context.REQUEST['URL0']">

<esi:include src="/site/@@left_column"
tal:condition=
"python:behind_varnish and not not_cached_in_varnish"/>

<tal:portlet condition=
"python: not behind_varnish or not_cached_in_varnish">
[...]

Installing varnish

You can do it with a buildout recipe.

Monitoring varnish

You can use varnishtop and varnishhist, which probably comes if you install Varnish centrally on your machine. However for monitoring the buildout based Varnish we need to specify its name. The buildout recipe does not allow this and I do not think it would work even if it were possible. Instead of the name we supply the path to the name parameter ("-n"), giving the path to to where the buildout's Varnish .vsh directory is.

varnishttop -n absolutepath/to/buildout/parts/varnish-build/var/varnish/

..and then tab complete to the lonely dir in there.

 


Making money and helping by investing in Africa

published Feb 27, 2010 02:01   by admin ( last modified Feb 27, 2010 02:01 )

The world economy is shifting away a bit from the "first world", towards countries like China and Brazil, but poorer places in Africa south of Sahara are also starting to get more attention and are deemed to have more potential for growth.

At the same time there is a rather painful insight among many idealists in the developed world that development aid hasn't worked and that in may cases foreign aid has possibly destroyed more than it has helped. For liberals (freedom of the individual, free market) the obvious solution is free trade and strong institutions, and a number of liberals have taken it on themselves to pressure EU and other trading blocks to work in that direction. The results of this work proceeds at a glacial pace.

For socialists these trend towards deregulation and free trade smacks of oppression. I have lost count of the number of debates with socialists I have had about this.

However, if you subscribe to the more liberal (and more correct dare I say) world view of freedom to work and freedom to trade,  what can you do as an individual?

The blogger behind Hotel Ivory has taken upon himself (according the blog the blogger wishes to remain anonymous) to in a small way reach the goals of:

  • Living the good life
  • Do business in a country in west Africa with a violent history and somewhat problematic institutional and legal circumstances.

These goals are hardly unique to the blogger, but it is interesting to follow the analysis and decisions that are taken from a business sense but also liberal perspective. So far the blog has dealt with:

I believe that if thousands (if not millions) of people started doing stuff like this, we should see some pretty strong devlopment all over the world. Problem being of course that these enterprises are fraught with risk. In the nineties, the currency used in the Ivory Coast was devalued by 50%. However as soon as a middle class starts to entrench itself, the virtues of good governance tend to make it into the seats of power. There is just a need to reach that tipping point.


Switcha över en fil till branch i subversion

published Feb 18, 2010 07:45   by admin ( last modified Feb 18, 2010 07:45 )

1) Skapa en branch, t ex genom att skapa ett bibliotek någonstans på hårddisken och sedan importera det:

jorgen@computer:~$ mkdir jm20091111
jorgen@computer:~$ svn import jm20091111 https://svn.someserver/some.project/branches/jm20091111

Committed revision 2683.

2) Gå till det bibliotek någonstans din utcheckade trunk, där filen som man vill jobba på i en branch ligger, Och kopiera över filen till branchen:
svn cp trickyModule.py https://svn.someserver/some.project/branches/jm20091111/

3) Filen på disken på din dator är nu fortfarande i trunk, men man kan switcha över till kopian. Normalt jobbar switch på ett helt bibliotek, men man kan lägga på ett optional andra argument om man bara vill switcha en fil:

svn switch https://svn.someserver/some.project/branches/jm20091111/trickyModule.py trickyModule.py

4) Kolla status:
svn st
  S   trickyModule.py

S betyder väl "switched" får man gissa. Alla ändringar i denna fil blir nu på commit skickade till den nya branchen (har kollat)


Länk - Eurotopics - nyhetsbevakning av vad som skrivs i europeiska tidningar i kompakt format

published Feb 13, 2010 07:50   by admin ( last modified Feb 13, 2010 07:50 )

 

Press review |



Läs mer: euro|topics - Press review


Recension: Musik av Ricardo Lemvo

published Feb 13, 2010 05:29   by admin ( last modified Feb 13, 2010 05:29 )

Beväpnad endast med ett Spotify-konto och med skraltig kunskap om salsamusikvärldens artister, var det dags att sätta ihop en kollektion med dansant salsamusik. Efter mer eller mindre kreativa sökningar och ett antal genomlyssningar hade dammet lagt sig och av de 40 eller så låtar jag hade valt ut var hälften av Ricardo Lemvo och hans band Makina Loca.

Lemvo gör salsamusik som det är omöjligt att inte bli glad av. Musiken är välproducerad och hela bandet har ett sinne för rytm som gör att en gedigen, närmast muskulös, rytm flödar genom låtarna. Lemvos röst har en tröghet som om hela kroppen måste röra sig i position för att frambringa fraseringen; det är så uppenbart musik att dansa till. När blåssektion kommer in är den snyggt mutad, vilket förutom att det är väldigt vackert gör att man slipper få så hårda ljudstötar från högtalarna på dansgolvet, när blåset kommer in.

Den första låt jag hörde var Africa Havana Paris, som fortfarande efter några dagar är en favorit. Lemvos musik är  afrikainfluerad (Lemvo är från DR Kongo med Angolansk bakgrund och bor i Los Angeles i USA), men hans passion är uppenbart kubansk musik.

En ännu mer uptempo-låt är Kasongo Boogaloo, och en lugnare är Serenata Angolano. Lemvo sjunger på en måängd språk. Spanska naturligtvis, men även portugisiska, kikongo och på senaste skivan tydligen även på turkiska.

A long-time fan of Cuban music and traditional salsa as embodied by Johnny Pacheco, Lemvo moved to the USA at age 15 to pursue his studies[1]. His mixture of languages (Spanish, Lingala, Kikongo, French, Portuguese and English) and his keen sense of rhythm made him a favorite of dancers throughout North America, Europe, Latin America, and Africa.


Läs mer: Ricardo Lemvo - Wikipedia, the free encyclopedia


Salsarytm förklarad med hjälp av Java

published Feb 13, 2010 02:53   by admin ( last modified Feb 13, 2010 02:53 )

En sida där man kan examinera och slå av och på clave, conga osv, och lyssna på rersultatet

Salsa music has a complex rhythm. Understanding the rhythm can help you to find the 1 beat or find the 2 beat so that you know when to start dancing. On this page I introduce the most important salsa percussion instruments and explain their common rhythms. You can listen to each instrument as you read about it or combine them in the interactive rhythm player at the end. Each rhythm is "counted in" by six beats to give you the speed.



Läs mer: Salsa Rhythm


Man-in-the-middle-attack mot alla kortläsare med PIN

published Feb 12, 2010 12:15   by admin ( last modified Feb 12, 2010 12:15 )

Forskare vid universitet i Cambridge har lyckats med att auktorisera köp med 6 olika kreditkort genom att interceptera kommunikationen mellan kort och terminal på ett sådant sätt att terminalen tror att transaktionen autentiserats med korrekt PIN-kod, fast slumpmässig PIN-kod använts.

Felet tycks bero på att man inte särkiljer mellan olika autentiseringssätt, och en man in the middle kan därför blanda så att terminalen tror att en högre autentiseringsgrad (PIN) har använts.

In particular, the terminal can record that a PIN verification has taken place, while the card itself receives a verification message that does not specify that a PIN has been used. The resultant authorisation by the terminal is acc


Läs mer: Chip and PIN is broken, say researchers - ZDNet.co.uk


Bra förklaring här:  How the Cambridge chip and PIN attack works - at ZDNet.co.uk


Run a plone zexp imported into a fresh Data.fs

published Feb 09, 2010 11:43   by admin ( last modified Feb 09, 2010 11:43 )

Summary: You can't. The server will give an error. The trick is to create a bogus site in the new Zope server. This somehow modifies Zope, from what I have read on the Internet, the acl_users folder in the Zope root.

One of my hobby projects was not on our backup bandwagon, so when I accidentally corrupted Data.fs by overwriting it (the tar command is very picky it turns out about not mixing up source and destination file names) I was out of remedies. But luckily enough I had made a "site.zexp" a few days ago by exporting the site from within the Zope ZMI.

So, just delete the old Data.fs completely, start up the server and import the zexp. That works, but you cannot view any pages, you get AttributeError: getGroups . Googling I found a posting by Andreas Jung. Jung doesn't explicitly say it but writes:

Problem solved. The behavior is caused by the stupid expectation of Plone
that the root acl_users folder having been replaced with its own
implementation while creating a new site

...and from there it was possible to deduce that creating a new bogus site from within the ZMI should do the trick. And this can be done after the import.


Make rdiff-backup use a different port for ssh

published Feb 09, 2010 11:20   by admin ( last modified Feb 09, 2010 11:20 )

Summary:

rdiff-backup --remote-schema "ssh -C -p9222 %s rdiff-backup --server"
username@remoteserver::/path_to/filestobackup
/path_to/backedupfiles

...worked for me, to backup a remote server via a non standard ssh port (9222 in the above example). Note the double quotes around the string following --remote-schema. All examples I could find on the Internet used single quotes, and using rdiff-backup 1.2.8 between two CentOS 5 machines, this did not work.


Get Spotify working with PulseAudio on Ubuntu Linux

published Feb 09, 2010 05:36   by admin ( last modified Feb 09, 2010 05:36 )

I had problems getting Spotify to work under Ubuntu and Wine, with a Microsoft LifeChat LX-3000 headset. The sound chopped 2-3 times per second.

Using OSS and normal Wine worked fine with the internal sound card of the laptop, but not with the USB headset.

I found this discussion thread and tried different remedies. The one that worked was Neil Wilson's fork of Wine, WinePulse, with support for PulseAudio.

You can update your system with unsupported packages from this untrusted PPA by adding ppa:neil-aldur/ppa to your system's Software Sources. Not using Ubuntu 9.10 (karmic)?


Läs mer: Release Packages : Neil Wilson


Encrypted and preconfigured vnc

published Feb 08, 2010 05:55   by admin ( last modified Feb 08, 2010 05:55 )


This looks very interesting for customer support. I have to look into this more. It seems it would make it possible for a customer to show exactly what teh problem is that they have. It does rely on the customer being able to download and run an executable though.

UltraVNC SC is a mini (166k) UltraVNC Server that can be customized and preconfigured for download by a Customer. UltraVNC SC does not require installation and does not make use of the registry. The customer only have to download the little executable and Click to make a connection. The connection is initiated by the server, to allow easy access thru customers firewall.



Läs mer: Single Click - UltraVNC: Remote Support Software, Remote Support tool,Remote Desktop Control, Remote Access Software, PC Remote Control


Hur mycket ekonomisk tillväxt är bara ökad sårbarhet?

published Jan 30, 2010 10:08   by admin ( last modified Jan 30, 2010 10:08 )

I The Economist kan man läsa en artikel om att 2010-talet kan komma att handla om samhällens sårbarhet, hur de klarar av att hantera olika former av kriser. I kommentarerna kan man läsa förslag om hur man gör ett samhälle mindre sårbart, men då påpekar någon att ekonomisk utveckling lätt ger ökad sårbarhet, genom just-in-time tillverkning och allehanda rationaliseringar.

Då inställer ju sig frågan:

  • Hur ser man till att ekonomisk tillväxt inte är sårbar?

Samtidigt inställer sig frågan:

  • Vill vi bli av med sårbarheten?

Ett syfte med frihandel är ju att fostra ett ömsesidigt beroende, så att det aldrig ska löna sig att gå i krig. Kanske sårbarheten är bra? Oräknat naturkatastrofer såklart.

Sherwood Botsford wrote: Jan 29th 2010 3:32 GMT There is no shortage of ideas. Possibly one of workable ideas. Here's 10 off the top of my head.
1. Deprecate efficiency as a measure of merit. Efficient systems are brittle. "Just in time" means that one company is hostage to another company, the weather, the transport. Instead modify the tax laws to encourage 'pools' in the pipeline.
2. Encourage locality. This can in part be done by a progressive tax on business. E.g. Larger businesses get taxed at a higher rate than small businesses.
3. Encourage multi-skills. Prohibit union contracts[...]



Läs mer: Comments on Scarcity and globalisation: A needier era | The Economist


xpra - vnc for individual windows on Linux, X

published Jan 29, 2010 12:02   by admin ( last modified Jan 29, 2010 12:02 )

I haven't tested this software yet, but it seems interesting. It allows you to run a program on one machine, and display it on another. Well many things can do that, including X itself. But the cool thing is that it is actually not running in the machine you're viewing it on, it just displays a Window that renders the contents of an "invisible" window on the server.

What this means is that just like with vnc, you can disconnect and reattach to that window from another computer. xpra becomes a bit like screen, but for GUIs.

VNC is another system for using apps remotely. The main difference between xpra and VNC is that xpra is "rootless" -- i.e., programs you run under it show up on your desktop as regular programs, managed by your regular window manager, instead of being trapped inside a box. It gives you "remote applications", not a "remote desktop". (Hence the name -- "X Persistent Remote Applications".)



Läs mer: README.xpra - partiwm - Project Hosting on Google Code


En dödsruna skriven av en död man

published Jan 29, 2010 01:15   by admin ( last modified Jan 29, 2010 01:15 )

Är detta vanligt? I The Guardian kan man läsa en dödsruna om J. D. Salinger som dog nu i januari 2010. Dödsrunan beskriver hans liv och hur det går mer mot stillhet.

Det är bara ett problem, längst ner i dödsrunan står det "Mark Krupnick dog 2003". Vem är Mark Krupnick? Jo det är författaren till dödsrunan. Han har varit död i sju år.

Jerome David Salinger, writer, born 1 January 1919; died 27 January 2010 Mark Krupnick died in 2003



Läs mer: JD Salinger obituary | Books | The Guardian


Gross varnar: Många i-länder ligger illa till finansiellt

published Jan 27, 2010 12:45   by admin ( last modified Jan 27, 2010 12:45 )

Enligt Bill Gross, som tydligen är en tungviktare hos en tungviktare (Pimco) i finansbranschen, så ligger många i-länder risigt till ekonomiskt: De har stora underskott och är redan skuldsatta. Gross har gjort ett diagram som han kallar "Ring of fire":



I detta diagram kan man se att Japan ligger tokrisigt till, men att även Storbritannien och USA har stora problem. Gula länder är OK och gröna mycket OK.

Jag är ingen ekonom, men om jag förstår saken rätt så är x-axeln hur skuldsatt landet redan är, och y-axeln i vilken takt skuldsättningen ökar. Ju mer skuldsatt man är, desto svårare blir det rimligen att låna mer pengar, och då kan det bli krisigt. Speciellt varnar Gross för Storbritanniens situation vad gäller obligationer, en situation som han kallar "en krutdurk".

Utvecklingsländer som börjar gå bra är sökrare kort menar Gross och pekar på bl a Kina och Brasilien som exempel.

 

Uppdatering 2010-01-27:

En kompis som jobbar med sådant här påpekar att Japans skuldsättning mycket är till den egna befolkningen, och därför enklare att hantera.

Initial conditions are important because the ability of a country to respond to a financial crisis is related to the size of its existing debt burden and because it points to future financing potential. Is it any wonder that in this New Normal, China, India, Brazil and other developing economies have fared far better than G-7 stalwarts?



Läs mer: PIMCO - February 2010 Gross Ring of Fire


Buss och lokaltågsresenärer nöjda, men mindre än förut

published Jan 25, 2010 03:18   by admin ( last modified Jan 25, 2010 03:18 )

Såg en TT-artikel där en undersökning presenteras om hur väldigt nöjda resenärer är med lokala buss- och tågtransporter, persontrafik. Artiklen nämner också att många av de tillfrågade håller med om att kollektivt resande är miljövänligt. Hmm, det är en väldigt ledande fråga...

Fick för mig att gå in på Svenskt Kvalitetsindex sajt, och där kan man se att kategorin "Persontransport - kollektiv" har haft den i särklass största sänkningen i upplevd kvalitet:

Buss- och lokaltågsresenärerna tycks vara ganska nöjda. Åtta av tio resenärer säger sig vara nöjda eller mycket nöjda med sin senaste resa med lokal- eller länstrafiken.



Läs mer: Bussresenärer överlag nöjda | Inrikes | SvD


Avlyssning byggs in i telefon- och e-postsystem, ibland oklart vem som använder dem

published Jan 24, 2010 07:12   by admin ( last modified Jan 24, 2010 07:12 )

 

Ericsson built this wiretapping capability into Vodafone's products and enabled it only for governments that requested it. Greece wasn't one of those governments, but someone still unknown -- A rival political party? Organized crime? Foreign intelligence? -- figured out how to surreptitiously turn the feature on. And surveillance infrastructure can be exported, which also aids totalitarianism around the world. Western companies like Siemens and Nokia built Iran's surveillance. U.S. companies helped build China's electronic police state. Just last year, Twitter's anonymity saved the lives of Iranian dissidents, anonymity that many governments want to eliminate.



Läs mer: U.S. enables Chinese hacking of Google - CNN.com