Thursday, November 29, 2007

Capturing shell output in Python

I need to capture the terminal text returned after I run some shell commands to create SVN repos. Unfortunately, os.system() doesn't capture the text, just the numeric value. Fortunately, Python has the command library. So now I can do this:

>>> import commands
>>> print(commands.getstatusoutput('ls -l'))
(0, 'total 0\ndrwxr-xr-x    9 dgreenfe  dgreenfe  306 Nov 28 19:02 bar\ndrwxr-xr-x   11 dgreenfe  dgreenfe  374 Nov 28 19:02 baz\ndrwxr-xr-x    9 dgreenfe  dgreenfe  306 Nov 28 19:00 foo\ndrwxr-xr-x   25 dgreenfe  dgreenfe  850 Nov 27 12:33 svn_bo11282007\ndrwxr-xr-x    9 dgreenfe  dgreenfe  306 Nov 29 10:37 tsvn1\ndrwxr-xr-x    9 dgreenfe  dgreenfe  306 Nov 29 10:46 tsvn2')

Monday, November 26, 2007

How fast can I convert a Zope 3 app to Grok?

Figured it would be quick and easy to make a conversion. I'm still new with both frameworks, but since Grok is built doing DRY and KISS and various Ruby/Django-isms, this should be pretty easy.

The application in question is a Zope 3 Captcha server that I wrote. It served as my learning box for doing Zope 3 and got me past most of the Zope 3 hump.

Complexity added to Plone 3

Mikko Ohtamaa raises some good points about the problems with adding viewlets in Plone 3. It is too complex. Design patterns are good, but they can capture your focus and make you do lots more work than you need, and not just necessarily up front.

Friday, November 23, 2007

Playing with Django

I've been playing with Django over the past few days. I'm not going to compare it to Plone or Zope. But I will happily compare it to Pylons. Ready?

Django is easier than Pylons.

There. That sums it up.

Easy, intuitive, and fun.

Thursday, November 22, 2007

Happy Thanksgiving!

I'm thankful for:

  • My wife and son
  • My students
  • Everyone who helped out when my bike got stolen
  • Only two minor injuries this year
  • My friends
  • My family
  • My crazy coworkers
  • The trip to Italy
  • My NASA customer
  • Python
  • The Plone and Zope communities
  • Good training partners
  • Good teachers

Tuesday, November 20, 2007

RIA arguments

I don't like to work in RIAs. Why reinvent the web when we have AJAX?

That said, I have a bit of respect for what Adobe has done with Flex and little respect for OpenLazlo, Silverlight, or JavaFx.

Anyway, someone I know is a huge OpenLazlo fan. I think they are mistaken to be entranced by OpenLazlo. Flex does all that OpenLazlo does, does it better, and does it for the same cost (free). Furthermore, the chart here shows just what the job market is for OpenLazlo, Flex, and other RIAs:

Friday, November 16, 2007

Need to get into the habit of using Python sets

Periodically I have use cases where I want lists with unique values. And I so often write logic to do it on my own. You know, things like if 'hello' not in mylist: do x(). Well, I need to stop doing that and remember to use sets.

Tuesday, November 13, 2007

Adding a new user at the root of Plone/Zope 2 programmatically

Sometimes you just need to do this sort of thing.
>>> app.portal._addRole('MyRole')

What do you do when zope.Public refuses to be Public?

I'm serving out image and audio files from Zope 3 for my Captcha application. Since the images and audio files are for public consumption, I marked their components in the zcml as having the permission of zope.Public. This works fine for the image, but not for the audio component. Is there something I'm missing? For reference, this is part of my ZCML:


Update 2007/11/14: Looks like the object those things reside in need to have zope.Public declared for it as well. I'm not sure I like that approach, and I'm wondering if I'm just not 'getting' something about Zope 3 security.

Friday, November 9, 2007

How do I deploy development code with buildout?

I've got a project where I want people to run a buildout of Plone 3 that adds in the development trunk into a site, and also creates the admin account and starts up Plone. I know this can be done because p4a does it. However, I want a much simpler version of things.

If I can get this done, then my KSS tutorial is done.

Zope 3 Security

Everyone is right, its not hard to figure out. I would have to say that the docs for it are a bit wordy. So here is my brief summary of things:
  • Permissions are associated with components of your applications. Zope has some built in ones but you can define new ones via ZCML and link them to components via ZCML.
  • Roles are what something is supposed to be generally doing. Such as be a 'user' or 'manager'. They are defined in ZCML and are associated with Permissions and Principals via grants.
  • Principals are anything that accesses something. You could call them 'users' or 'members'. They are called principals because nearly anything can serve as one. Hence why users and members is not used. Principals are associated to Roles via grants. Principals are defined in ZCML but can also be called from special components called 'Password Authentication Utilities'.
  • Grants are how things are related to each other in this via grants.
And since a picture says a thousand words...

Thursday, November 8, 2007

New blog format

I hate super narrow columns of text in blogs. So I changed my layout.

I'm not happy with blogger. But until I launch some sort of professional site again, I'll just stay here.

Wednesday, November 7, 2007

Plone lets you import/export workflows!

This is for an application that I'm hoping we'll be able to replace after this month. When I put it together it was my place to learn new stuff and make some critical mistakes. In the future workflows will be defined via code, but for now, I'm going to do it in the ZMI.

The problem was doing it in production. We are simply not allowed to touch production boxes or the ZMI there without getting into trouble. And our sys admins know nothing about Plone and Zope (and arguably *nix). So I have to automate the process.

My first thought is Selenium since hopefully the sys admins know how to use that fun tool. But using Selenium for configuration is problematic at best. The ZMI often uses dynamic form field ids per page load, or per Zope instances. This has bit me before.

I looked up doing it programmatically. I could write a script, but instructing a sys admin to run the script might be painful too. I've run into problems with this too.

Then I remembered that much of the ZMI lets you do imports/exports. A quick check and yes, we can do it with workflows.

Now the downside is that it is a slippery slope. Once we start doing things through the ZMI you can't go back. But again, this project will probably be migrated to something much better next year.

Pylons vs Django

I like the interior workings of Pylons, I really do. But if I want to do SQL based crud apps then Django is simply stronger. That strength is what drew me to TurboGears for a bit before parts of TurboGears annoyed me. Pylons just lacks a lot of the things that I want, like built-in auth . Sure, I can roll my own, but I'm lazy. Of course, Django is really meant for the CRUD sort of thing, and I wonder how good it would be beyond that avenue.

Note - I'll be expanding on this over time.

Update: My problematic comparison of Pylons vs Django.

ZPUG-DC Report 2007/11/07

Got a good presentation on repose.zope2 by Chris McConnough, which lets you deploy easily in virtualenv with just a few commands. Paste is used a lot, of course. This repose thing lets you use WSGI, which means you can use middleware of choice. Chris shared evalerrer with us, which promises to be a great middleware for any developer.

I like this sort of development because the easier it is to install independent versions of things with variations quickly and without a lot of fuss. So you can try new things, discover you don't like them, and try something else. And you don't need to know a lot to make this work.

Sure, knowing the stuff about how it works is important, but this serves as a nice tool for understanding why. It lowers the barrier for entry, which in the Zope (and Plone) world is important.

Afterwards had great discussions with ZPUG at some bar in DC. Talked to Paul Everitt, Matt Bowen, Chris McConnough, Kapil, and some others. I was very sleepy so I was not as sharp as I can be, but I learned some interesting things.

Kapil agreed with a growing suspicion I have about Grok. I'll post about that in the future. Its mostly positive but it does have a couple critiques.

Kapil reinforced my feelings about Pylons vs Django. Another item for a future post.

Monday, November 5, 2007

Head meets desk

I need to add a DateTime field to my primary content object. Unfortunately, in Zope 3, they named it Datetime in zope.schema. Now, before you say I should notice the coding standards, please note that the single textline object is zope.schema.TextLine.

Figuring out this one took me way too long for comfort.

This is the first time I've seen this sort of mistake in Zope 3. Until now I've been delighted with Zope 3's consistency and elegance.

I'm hoping it will be a while before I find the same sort of thing again.

Thursday, November 1, 2007

I grok Zope 3!

I've struggled with Zope 3 for a bit. I read books, perused documentation, and took a class in Italy. And yet, it felt confusing. Well, this week I had to finish up a Zope 3 solution in record time. So I really hit the books and squinted my eyes real hard. It was frustrating because I got the individual bits, but putting them together was painful and a matter of trial and error rather than an understanding of how to meld components together.

The long and the short is that I used a mix of using Grok and writing Zope 3 tests to figure out problems I was having in my efforts. And then after about two days of struggling and banging my head against the wall, something clicked.

I get Zope 3.

I made something not working work in minutes.

I'm no expert. I've got a long way to go. I've got to work more with Adapters. But tying pieces together is no longer something scary. It makes sense now.

So, here are my lessons learned for anyone who wants to do Zope 3 and is a newbie..

1. Start with Grok. It removes a lot of the overhead and tells you the core bits of how Zope 3 components and interfaces work.

2. Write Zope 3 unit (doc) tests. I can't understate this issue. Don't worry about functional tests. The nice thing is that they insure that before you go to trying to put pieces together, that your component level bugs are mostly gone, so you don't think that zcml is a monster when really its a bug you didn't spot.