Monday, December 6, 2010

string substitution in list

While coding the other day ... I came across this suspiciously looking code that almost look like it would work ...

substituted = ["My name is %s","My name is %s", "My name is %s" ] % ["Earl","Matthew","David"]

So used to looking at string substitution, I almost thought that code could work ... of course in order for that to work correctly ... it would have to be something like this ...

strings = ["My name is %s","My name is %s", "My name is %s" ]
names = ["Earl","Matthew","David"]
substituted = [ string % name for string,name in zip(strings,names) ]

It's string substitution and list substitution .. Repeat that 10 times :). It's always good and enlightening to strip right down to the basics most days. Go on run the first part of the code and see what you get.

Saturday, November 27, 2010

Time to update my Python on windows

It's time again to play with my Python on my Windows vm and I thought it was high time I updated it since it was running ver. 2.5. First came the easy part, replacing Python itself. I just downloaded and changed the path for python in window's environment variable.

I ran 'easy_install mysql-python' thinking on other tasks ahead. Hmm .. command now found, fudge around with the paths and found that I had to install the setuptools for windows. Installed it, changed the path to point at PATH;C:\Python27\Scripts and boom now my Python has easy_install. Little did I know more fun lies in wait ...

First in trying out 'easy_install mysql-python' I ran into an error saying "error: Setup script exited with error: Unable to find vcvarsall.bat". Looks like my install was still lacking something. After some digging around, it seems that, that error is equivalent of gcc not found on Linux, so I was off to install MingGW.

Install that, downloaded the sources for MySQLdb from sf.net. They used to provide binaries for MySQLdb but it seems now no more. I ran into another error! Google lead me to this answer: http://www.mail-archive.com/pylons-discuss@googlegroups.com/msg11448.html. Good point. So I finally found my answer here... http://www.codegood.com/archives/129. Thanks codegood or Ioannis Lalopoulos, for saving a few more of those pili on my scalp! Now ... to find that win32com!

Wednesday, November 24, 2010

Equivalent of python's virtualenv

I use Python's virtualenv nearly everyday in my work and was lamenting about the lack of a well made solution on Ruby's side of the fence, that was until I found this great gem: http://rvm.beginrescueend.com. This is the closest I guess Ruby comes to having virtualenv.

I like the elegant way the author of this too approaches installation of rvm short for Ruby Version Manager. It's just a bunch of bash scripts which does some fancy tap dancing with curl but it elegantly works and everything is in your box in a jiffy. I am eagerly installing rvm on my boxes and will report back on my findings.

Sunday, November 7, 2010

CSVs, unicodes and BOMs

Nothing like a little project specs to make the ugliness start climbing out of the woodwork. I was tasked to write this parser to massage some data destined to be imported into a database. As I worked with the csv library a few things started to be painfully evident to me.

There was no support for unicode in the csv module, and as I gathered from here, it doesn't look as though there will be anytime in the near future ...

Just tinkered a little around with a the neighbor over the fence to see what they offered ... here are both of them side by side ...

>>> data = reader(open("data.csv","r"))
>>> for item in data:
...     print item
...

 'NZ(\xe8\xaf\xba\xe7\xbb\xb4\xe4\xbf\xa1) >Food(\xe9\xa3\x9f\xe5\x93\x81\xe8\xa1\x8c\xe4\xb8\x9a\xe7\xbb\x84)', '\xe8\xaf\xba\xe7\xbb\xb4\xe4\xbf\xa1\xe9\xa3\x9f\xe5\x93\x81\xe8\xa1\x8c\xe4\xb8\x9a\xe7\xbb\x84\xe6\x9c\x80\xe7\xbb\x88\xe7\x94\xa8\xe6\x88\xb7', 'TRUE']                          
['NZ', 'NZ(\xe8\xaf\xba\xe7\xbb\xb4\xe4\xbf\xa1) >Technical(\xe5\xb7\xa5\xe4\xb8\x9a\xe8\xa1\x8c\xe4\xb8\x9a\xe7\xbb\x84)', '\xe8\xaf\xba\xe7\xbb\xb4\xe4\xbf\xa1\xe5\xb7\xa5\xe4\xb8\x9a\xe8\xa1\x8c\xe4\xb8\x9a\xe7\xbb\x84\xe6\x9c\x80\xe7\xbb\x88\xe7\x94\xa8\xe6\x88\xb7', 'TRUE']                     
['NZ', 'NZ(\xe8\xaf\xba\xe7\xbb\xb4\xe4\xbf

irb(main):002:0> require 'csv'                                                                      
=> true                                                                                             
irb(main):003:0> CSV.open('data.csv','r') do |row|                                     
irb(main):004:1* puts row                                                                           
irb(main):005:1> end
诺维信) >Technical(工业行业组) >Starch(淀粉糖行业)                                               
诺维信淀粉糖行业最终用户                                                                            
TRUE
...

Seems like ruby has got the unicode out of the box ... hmm wonder how much effort it would take have that unicode support? Those reading my last 2 posts are probably wondering if I pro ruby or something. I am not. I love Python and use it for most of my tasks and I love recent developments in it ... just that there are a few "nigglies" with it. I want it to improve beyond these few little bumps.

That being said I love the functionality I get when I use DictReader from Python's csv module as it let's me address my columns by name. Useful in situations where you have to reorder the columns. Seems that you can do that too with Ruby with a little work.

The next one that got my goat was this thing about BOMs or Byte Order Marks fecal matter left by Excel on the headers. Not really a problem with Python but rather Excel, still had to deal with that. Ended up sanitizing my headers and stripping off the damn BOM. There was a library to do that but I thought that was a bit of an overkill.

Anyway back to the grindstone ....

Wednesday, November 3, 2010

List comprehension ruby vs python

Been exploring a bit of list comprehension in Python so today I thought I peeked over the fence to see a bit of what is happening at ruby's end..

I really like how they are doing their list comprehension over there, check this example out:

[1,2,3,4,5].select(&:even?).map(|x| x*3)

That is almost readable code even in English! I would read it as something like this.."From the list 1,2,3,4,5 select even numbers and map it to number times 3". Really nice!

This vs the clunkier Python code ...

[x*3 for x in [1,2,3,4,5] if x%2 == 0]

I mean it both works just that it seems more elegant in ruby. Would be nice if we had that even or odd function in Python. Yeah I know it's trivial to write ... but then following that logic wouldn't it also be trivial to include it in the standard library. Probably my way of emulating this example ain't exactly the best and there are other more succint ways of doing it, if so be great to drop me a line here, but for now hang on while I peek over the fence more :)

Thursday, October 28, 2010

Who's playing catch up now?

At one time if I remembered correctly, ruby came up with their gems framework first. I tried it out and really liked it as I got to try out various gems without having to worry if my platform had packages for it or not. At that point the poor Python was left in the dust at the other side of the room without anything remote resembling gems or cshell (Perl).

Fast forward a couple of years and now easy_install and virtualenv and these two great apps are so wide spread. I used them so much and got used to using and depending on them that when I found myself returning to gem to try out watir, a framework for web testing, I found gem to be clunky and unwieldy. Kudos to the Python camp! In such a short time you have left gems shaking it's head disbelief in the dust! Who said snakes can't be fast.

For those who are interested, I had problems installing the gem for watir and encountered all sorts of errors and upon searching for the download point for watir to download it by hand, let's just say I missed PyPi a lot.

Tuesday, October 26, 2010

Python-Flask packages in opensuse

Been doing some work and playing around with opensuse's great build service and as a result, my packages has been accepted by the opensuse team. So, now pensuse has python-flask and a few related packages in there.

Use the devel:languages:python and enjoy.

Alternatively use the search http://software.opensuse.org/113/en to find what you need.

Sunday, August 29, 2010

Blogging awards

Geeta from packt informed me that Packt is having this contest for opensource blogs. To quote the site with the contest running on it's fifth installment:

"Now in its fifth year, the Award, formerly known as the Open Source Content Management System (CMS) Award, is designed to encourage, support, recognize and reward not only CMSes but a wider range of Open Source projects."

Nominations start on August 9 and ends on September 17, so get your nominations in! You can read the full announcement here.

Thursday, August 12, 2010

easy_install how I wish ...

I use a lot of easy_install during the day to manage my packages. First off the bat let me just get this off my chest, I hesitated like about 10 times before writing this article, for fear of getting panned all the way to Sunday, but then Sunday isn't really that far away so here goes. Also, before that if you are going to pan me or burn my ass for not reading docs at least at the end of it disseminate some useful info at the end of the burning comment so that everybody can benefit from it. God knows I would appreciate it.

I was doing some stuff on Pylons and for some reason Routes-1.12 was screwing stuff up, so I had to downgrade Routes by doing something like:

easy_install 'Routes<1.12' and it did it's work well enough.

Two thoughts itched at my thoughts though ... the whole experience of downgrading Routes felt a little bit too deja-vuish to be comfortable. Did I not do this before the other day? I could have sworn it was working the other day with Routes-1.11. All of this mental itching started a seed of mistrust for my hithero good simple friend easy_install.

Anyways, I just proceeded but now with an eye on my friend in the corner just to check up on what the macha was doing. I tried to find out the version of route that was running from easy_install, hmmm there was no way of doing that! At this point I just hear those magnums and AK-47s from all of you Python elites ready to blow me to kingdom come, as they always say "easy_install is meant for easy installing!" Okay okay, but is it so very hard to write it so that we can do something like:

'easy_install query Routes' ??

Remember pan me at this point if you want if you know that easy_install can do it somehow with some black magicks but at least let everybody know how. In the end I settled for this:

'python -c 'import routes;print routes.__path__'

Sigh ... I know my ass is just going to be hurting after this ....

Wednesday, August 11, 2010

New Book from Packt

Guys from packt have been hitting the web quite frequently and have sent me another book to review, this time Object Oriented programming in Python. Always wanted to read about this.

Anyway you can find a peek here:

Chapter No.7: Python Object Oriented Shortcuts

Enjoy!

Saturday, July 10, 2010

My easy buildout example Pt. 1

For a long time I could not make heads or tails of buildouts just that I kept on hearing that it's supposed to be very easy to make packages and distribute them. So finally this week end I sat down, rolled up the sleeves and decided to really try and understand what I was missing.

My aim, create the world's easiest package with absolutely nothing in it. All I wanted to do was just understand what is going on.

Firstly I needed to create my own package, for this I let the great python paste script do all the heavy lifting for me:

[lowks@bobot-mdv-ng pylons]$ ./bin/paster create -t basic_package buildout_example
Selected and implied templates:
  PasteScript#basic_package  A basic setuptools-enabled package

Variables:
  egg:      buildout_example
  package:  buildout_example
  project:  buildout_example
Enter version (Version (like 0.1)) ['']: 0.1
Enter description (One-line description of the package) ['']: Buildout Example
Enter long_description (Multi-line description (in reST)) ['']: Buildout Example
Enter keywords (Space-separated keywords/tags) ['']: buildout example
Enter author (Author name) ['']: Low Kian Seong
Enter author_email (Author email) ['']: kianseong@gmail.com
Enter url (URL of homepage) ['']: www.lowkster.com
Enter license_name (License name) ['']: BSD
Enter zip_safe (True/False: if the package can be distributed as a .zip file) [False]:
Creating template basic_package
Creating directory ./buildout_example
  Recursing into +package+
    Creating ./buildout_example/buildout_example/
    Copying __init__.py to ./buildout_example/buildout_example/__init__.py
  Copying setup.cfg to ./buildout_example/setup.cfg
  Copying setup.py_tmpl to ./buildout_example/setup.py
Running /home/lowks/virtualenv/pylons/bin/python setup.py egg_info

What the paste script will do is it will ask you a bunch of questions where all the answers is used to fill up your setup.py. Your setup.py now will look something like this:

from setuptools import setup, find_packages
import sys, os

version = '0.1'

setup(name='buildout_example',
      version=version,
      description="Buildout Example",
      long_description="""\
Buildout Example""",
      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
      keywords='buildout example',
      author='Low Kian Seong',
      author_email='kianseong@gmail.com',
      url='www.lowkster.com',
      license='BSD',
      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
      include_package_data=True,
      zip_safe=False,
      install_requires=[
          # -*- Extra requirements: -*-
      ],
      entry_points="""
      # -*- Entry points: -*-
      """,
      )

Wow! How did that just happen ?? Well the paster script as promised did all the heavy lifting and filled up the setup.py with all the input you just put in just now. Isn't that magical ?

If you are doing in a virtualenv, do a 'easy_install zc.buildout' to get started on getting all the buildout stuff. Remember that you will definitely find other guides somewhere else to do this. I am just writing this down as an exercise and a reminder to myself.

After you finish installing zc.buildout, to sprinkle the buildout magic in your current source directory, cd into the source directory which for this example would be the buildout_example and then all you have to do is run '../bin/builout init'. It is really really easy!

[lowks@bobot-mdv-ng buildout_example]$ ../bin/buildout init
Creating '/home/lowks/virtualenv/pylons/buildout_example/buildout.cfg'.
Creating directory '/home/lowks/virtualenv/pylons/buildout_example/bin'.
Creating directory '/home/lowks/virtualenv/pylons/buildout_example/parts'.
Creating directory '/home/lowks/virtualenv/pylons/buildout_example/develop-eggs'.
Generated script '/home/lowks/virtualenv/pylons/buildout_example/bin/buildout'.

That's almost it! Thanks to your fairy god mother buildout script, you will find a bunch stuff already created. Most of the guides I read was too heavy as it tried to get too much stuff done now ... so I am going to cover more in the second part. For now just pat your back in that you are 3/4 done! Go have a great cup of puerh tea!

For the next part we will see what each part in the buildout.cfg and at the end we will see how to finish the buildout process plus create a section for nosetests.

Sunday, June 27, 2010

Did you know?

There are some of my overseas friends that are genuinely surprised when they visit my homeland Malaysia, to find that people are actually civilized, not swinging from tree to tree in loin cloths. To these people, with a sense of pride I even venture to tell them "We even have an healthy OpenSource movement !". That being said, this is not a posting about pride.

As I was driving back home I thought about the point of this post, what I wanted to say. I guess I just wanted to let my other Python and OpenSource audience or brothers on the other side of the globe know what is the state of acceptance of Python and other OpenSource technologies in most of the corporate sectors over here. I summarized this list after talking and being turned down by a few corporate companies recently for employment. Here goes ...

Did you know ...

  1. Most of the corporate customers, banking sectors, basically the people that matters still think that most of the OpenSource technologies such as Python, Ruby, MySQL is unsecure and reject it based on that? "unstable" is the word they use. PhP which runs probably the majority of the websites in the world is shunned for security reasons while they force their standards of using Java for all of their internal applications!
  2. While some banks accept that they cannot be a total island and reject OpenSource technologies, they require all components you use in a project to be listed down.  I don't know why, probably they want to scrutinize the list and make sure that everything is secure before accepting any "unstable" application. This vs. the fact that M$ Products all around that are used all around their establishment which do not even reveal any of the components used in their products!
  3. All of these guys complain about the fact that languages like Python should not be used based on the fact that it's not officially supported and at the same time accept Java? Ermmm .... I do hope that Oracle signed an agreement with Sun before buying it that it will never close down support for Java even if it gets unprofitable. 
  4. Almost all of the major financial institutions that I know of that reject OpenSource use products based on OpenSource such as F5, HP and Bluecoat to run their daily operations. Should I be afraid now?
It is my hope that since this blog has a audience of somewhat more than 3 people that the CEO or the decision makers of these institutions chance upon this blog and realize how flamingly stupid their decision for rejecting OpenSource based on these FUD is.  At least if you want to so damn secure then you should be fair and insists that all of your products such as M$ products reveal all of their components and source code so that you can audit it (If you really have so much resources to audit all of the things you use). When you succeed in doing that then the good thing is after that you can set up your own freaking software company. Come on, meet me half way here I would really like to believe that the people which I trust to take care of my money at least know their mouth from their asshole when it comes to the apps they are using to run their daily operations!

For No. 4, don't you think that since these Products use the same OpenSource tools that you rejected, that they would also be unstable or unsecure? When will you learn that it's not the tool you use that makes the app unstable, IT'S HOW YOU BUILD OR PROGRAM IT????? Then based on this logic all of those applications should be rejected too right? Why don't you?

After thinking about it for some time, I decided to start working with some local Universities to educate their students by offering my time to do small projects. I am meeting up with a lot of resistance but I am optimistic. Although my small ship is sailing alongside behemoths like M$ who sponsor everything from labs to the tissue our snot nosed university graduates use to wipe their nose with, the acceptance is growing. More of these students are and have heard about OpenSource technologies at least and a few of the major education institutions have started to accept OpenSource technologies.  

To change the whole apocalyptic outlook for being an "OpenSource consultant" now, fresh graduates will need jobs waiting for them. Show them that it pays to pick up this knowledge or study and they will. Now, the few misfits that dare to venture down the OpenSource hole, always have this unemployment cloud hanging over their heads when they graduate. Herein lies a problem. If this was to go right, these students who invest their time and energies needs jobs, good high paying jobs when they go out and dare to put the current deal breaker word "OpenSource" on their resumes. For that to happen, we need some MNCs out there to start realizing that the space between their ears would be better employed to think with instead of the hole where excrement comes out from.  I really hope that this slap on the face really lands on the right audience as I really hope that one day Malaysia too can come out of this intellect and choice stranglehold that some proprietary vendors think of putting us in.

I would like one day to be able to proudly exclaim "This app was built using OpenSource technologies" like the way it should be instead of having to hide behind generalizations or something out right lying.

Friday, June 25, 2010

Mandriva pt 2

Another little thing that Mandriva paid attention to that makes me like it that much more. After reading the comments to the earlier post, I enabled the backports and installed chrome from the backports, checked the flash plugin out of the box and guess what? It just works!

Great job mandrivians! It's small touches like this that shows you care and make repeat customers (like me) as well as new ones! Btw, I am still trying out the multitude of guides on how to get flash working on Fedora 13 x64 without success.

Wednesday, June 23, 2010

Moving to mandriva?!

Never thought I would be writing this, but I am actually considering moving my Linux boxes (based mainly in OpenSuSE and Fedoras) to Mandriva! During my hey days we always considered Mandrake (it's name then) something of a play distribution or a distribution for Linux beginners and should not be used for 'serious' work.

Fast forward about 10 years, after a name change I don't know why suddenly I felt an urge to pick up the latest version of Mandriva 2010 to give it the proverbial spin. After playing around with the bought version of Mandriva (yes I actually bought a copy!). I really started liking it. Let me just list down a few of the reasons why.


  1. There is a wealth of packages. I was not left wanting for any specific packages. Most of the packages I needed was there. 
  2. For a rpm based distribution the package manager is blindingly fast and contains a couple of things done right I wish was in zypper and yum. One of them being the ability to pass as an argument the bandwidth that is to be consumed by urmpi (their package manager) during updates or installation. This I found to be very useful in my old office who was sharing bandwidth with another company! They also do some smart things to speed things up during updates such as by default not downloading the description of patches unless needed (when clicked on)
  3. The network manager is cool. I like how Mandriva does their network manager. It's independant of the DE. For example, if I am logged into XFCE and wanted to move over to KDE or some other DE, and I am already connected wirelessly, after logging out and in, I am still connected because the network manager is separate from the DE. Oh! How I wish the other distros would do this simple little thing!
  4. Their look and feel is quite standard across all DEs and WMs. Now the one small bug in the ointment is that I found that LXDE, the new favorite new kid on the block does not work correctly.
I am trying my best to find fault with Mandriva 2010 and can find little (The 'little' here would be it does not have a package for chromium-browser!), so I am seriously considering moving over to Mandriva from what I am using now. Just downloaded the Free version and am thinking hard why should I be keeping Fedora 13 on my laptop now, though truth be told Fedora 13 does a lot of things right too and after the little debacle of getting flash-plugin working correctly is sitting happily on my X61 now. Ah ... decisions, decisions!

Tuesday, June 22, 2010

New Book review Django- Django E-Commerce by Jesse Legg
















Folks at Packt sent me another book to review which is Django E-Commerce. Right off the bat I got some comments regarding how relevant this book might be with so many applications based on Django that do ecommerce floating out there.

For me though, I find this book is suited for those people who want to use Django building an Ecommerce site by using the tools provided by a default installation of Django. It also gives insight into how the ecommerce tools are built. It starts from the best place possible which is from a working example.

Each section is explained carefully from the overview to the technical implementation of the module. This is very useful and I learnt a thing or two reading most of the explanation here.

The payment process here employs the 'google checkout' processor to process the payment. What is covered here is also the use of one of Django 'secret sauce' which is views and each section and code is explained. The steps on how to lift a normal Django component to enterprise level functionality is explained starting from using the most basic way of implementation. This approach is taken in explaining the search module and it's great! I like it this way as it's a progression approach and programmers will learn why code and approaches evolve the way they do. Great way of learning! Here too the author explains and shows how to use some of the most famous Django plugins to achieve what we want to do.

Using Sphinx for an E-Commerce site is also used here and the value here is that the example can be easily expanded to create more complex examples or sites. Later in the reporting section integration to salesforce is shown. I really like this as these examples are practical examples that can be used to create a real E-Commerce site that works and avoid walking too much on the academic side of things. This is the main strength of this book. Amazon, JScript and a lot of other tools are also shown.

I will definitely be keeping this book handy on my book shelf for reference in building an E-Commerce app and I highly recommend it.

Check out the book here: http://www.packtpub.com/django-1-2-e-commerce-build-powerful-applications/book?utm_source=blog.lowkster.com&utm_medium=bookrev&utm_content=blog&utm_campaign=mdb_003437

Saturday, May 22, 2010

A Linux type?

As part of what we do, we help business people migrate over from their usually rotten Windows XP, Vista and what ever else incarnation of Redmond OS over to Linux. We found that some people really took to Linux while some got stuck in purgatory complaining constantly in the transition period. I found that certain types of personality as well as expectations makes the whole process smooth and dare I say even enjoyable?

  • I found that the more open the new user is to a new OS, being more open to forget about Windows they are the more enjoyable the process is. "This used to work so much better on my laptop in Windows ..." kinda attitude will almost guarantee a world of pain.
  • Having a positive attitude helps ... as in you are home ... your printer does not work instantly ... instead of just chalking it up to the new OS being bad just give it a whirl and think of the fun of trying out something new will make it enjoyable. 
  • Trusting your new OS as well as your new found friend (me) when it comes to buying peripherals will help during the transition. 
Those with the attitude above really took to Linux like fish to water and it sorta became their bragging rights in among their friends. Remember too that these are pure business people without any prior Linux experience. So it's gratifying to me to over hear them in conversation with their friends "Aiya ... you are still using that slow piece of crap .. see my new Open Source OS! No virus can touch it and it's blazing fast!" It's nice to know we did one for Linux advocacy in our own way as well as fill our pockets up a bit :).

Thursday, May 20, 2010

Another book to review! (Django E-Commerce)

The nice folks at Packt has sent me another book to review. This time the book is Django 1.2 E-Commerce. The sample title looks great which includes setting up an e-commerce site in 30 mins using the usual suspects from the Django framework: Admin, generic views and using Checkout from google. The example looks practical and easy to follow ... makes me like this book already. For those of you who want to get a whiff of what this book is like ... here is a link to the sample chapter.

https://www.packtpub.com/sites/default/files/7009-chapter-2-setting-up-shop-in-30-minutes_0.pdf

Wednesday, May 5, 2010

Repoze BFG

The repoze.bfg Web Application Framework: Version 1.2

I have been trying repoze BFG's tutorials the past few days and I must say that I like it just judging from the tutorials. Firstly I was very surprised the tutorials worked out of the box ... after being hammered around by the tutorials from Grok, so it was a nice surprise. Looking at the examples too it doesn't make my eyes bleed _so_much_ so I am definitely interested to know more about Repoze.

Developed by http://agendaless.com/ , on the whole the project has a good solid feel to it offering tons of documentations on it's site. Of course you cannot run that far away from the mind-melting Zope framework but then hey! trust me, it looks a whole lot better! It says that Repoze is inspired by Zope, Pylons and Django and I would say it shows in the code produced.

According to the site, Repoze is MV rather than MVC as there is not much of a 'Controller' to talk about. I am currently actively looking for a project where I can really put Repoze to the metal to see how it fits me in a project environment.

As someone said long time ago to me ... all frameworks suffer from the same disease ... it can really do the 90% fast and great but it's the last 10% that is going to blast the skin from your bones ... okay so I am paraphrasing, but you get my point. So, I am going to put this one through the paces hopefully initially with a smallish project that is not so heavy with the funky specs with just one or two bumps on the road to stretch the framework a bit.

Thursday, April 15, 2010

PyCon APAC

Well they say that a picture paints a thousand words ... so here we go


I think I might go this year just to see how it is.

Monday, April 12, 2010

Update on grok web development tryout

After dancing around the pale moonlight with a newly slaughtered chicken in my birthday suit, offering fruits to the grok gods, finally today the gods were kind on me and helped me along to find this solution that works! The closest I got the example in the grok book to work is to install the grokproject and start a new project without errors, but when I try to start up the devel server, all sorts of strange manner of monsters jumped out at me.

Just have a look at this : archive.netbsd.se What needs to be done is to edit the paster template and everything will work fine. I guess either this bug has not been looked into or is still an open bug.

Heh! I spoke too soon, I got to the main page of grok management but as soon as I try to do anything, I get this:

"TypeError: character mapping must return integer, None or unicode"

Hmmm ... google gods say this:


Not really a solution


Not much of a solution it seems, just that Python-2.6 is not supported. I am using grokproject, but how can I see what version of grok is grokproject using. As the mail says, errors like this is really really off putting and does not help with building confidence with the project!


Grok 1.0 Web Development

Monday, April 5, 2010

Review of Grok Web Development 1.0 Part 1



I like Zope/Plone. I repeat I really like Zope and Plone. Though here in this blog I might sometimes balk at the monolithic-ness of the 2.x era of them, fundamentally I like the concepts that they put forth. When things like Django, Turbogears rolled around thanks to Ruby On Rails, the call for Zope to recreate itself was sounded and did they respond! Zope3 was almost a ground up rewrite. At that point I had moved on to Django for one of my projects but I looked back longingly sometimes at the useful components put out by Zope. Then someone told me about Grok. I looked at it and liked it alot (okay maybe I still have reservations about Zodb) and it looked to me very much similar to how Django and others were playing the game, except that Grok came to the party with very advanced clubs and spears inherited from it's day in Zope-2.x! So when I got the chance to review the Grok book from Packt, I jumped at it. I wanted to find out what is the innards of Grok and how to or can I deploy an enterprise project using Grok.

The review of this book got very much delayed due to the fact that grok, like all other Zope stuff needed Python2.5 or Python2.4 to get working correctly. Now in this day and age of every distro racing to be the latest, bestest and most up to date, it was a challenge for me to get a Python2.5 or Python2.4 easily. I ended up going the VMWare route and installing a copy of Centos5.4 which still spots Python2.4.3 by default. This probably would be the biggest stumbling block of any newbie trying out the book the first time. The examples all require you to have a copy of Python2.5 which can be a challenge to find or install right. Once I had the components, I started on my way by using easy_install and then virtualenv which is the Python Virtual Environment. Again, these would require a little fore knowledge of Python stuff so this book might not be totally for the newbie programmer who don't know anything about the Python programming language. A bit of introduction to Grok, as far as I can remember. Grok came about when there was a little discord in the community about the monolithic-ness of Zope-2.x, when light frameworks such as Django, Turbo Gears and others started coming on to the scene. You can say that the Grok project was created to allow programmers or fans of Zope to enjoy a modular development environment offering the best of Zope where programmers can now pick and choose pieces of it can apply it to their work. I must say that the pieces of Zope when good is truly good and most often than not I find myself recreating some of the functionality of Zope in my projects using other frameworks. What could have been done is to release a VMware image of a working environment to work on. Definitely a boon in terms of speed up of trying out the examples!

The book starts out the example by using Virtualenv (Python's virtual environment) and easy_install which is a good move as Grok's packages are not readily available and probably installing it would not be the easiest thing to do in the programming world. Getting a relative newbie caught up in installation of Grok when all they want to do is to bring it for a test drive would be painful to say the least. I tried lots of environment including Ubuntu which resulted in errors preventing the example from working until at last I found Centos 64 bit which worked with the examples. The process of finding this out was maddening! Perhaps grok is still under development but what I suspect is that most of grok's dependencies or libraries is still playing catch up with the example in the book. This might be off putting to a Grok newbie venturing into the land of Grok development. The examples were the most enjoyable part of the book where the beginner could feel that they were starting a project from scratch.

The admin tab in the applications for Grok is touched here and covered in passing highlighting all the main features of all the tabs. In the views section, those who are new to Zope Page Templates and the TAL (Template Attribute Language) will get a nice and concise introduction to some of the functionalities of using ZPT with Grok. Those who are Zope / Plone developers could probably skip this section without too much difficultly unless you are like me who want a refresher's course on ZPT. This deep into the book I really like the examples thrown my way and it's really refreshing for me to see that one of my favorite Python application have reinvented themselves and this bodes well for it.

Catch more of this review in part 2....

Saturday, April 3, 2010

Getting mtp device (Sony Walkman) to automount in mandriva 2010 powerpack

Currently I am running Mandriva 2010 powerpack on my laptop. Everything worked correctly and great and there are a lot of things I like about Mandriva. Today while trying to get my Sony walkman to automount as a usb device it just did not work automagically like how it did in my OpenSuSE. I debugged it a bit and found that it was recognized as a usb device but it just did not mounted automatically (I use KDE). Shot up nautilus and everything worked just great.

Being in a frisky mode today, I was undaunted and continued to search around for the solution. Found the solution in a Mandriva forum here:

MTP Solved Forum

A bit outdated yes but I deciphered what I could from there, and found that the solution is to install mtpfs. Just do a 'urpmi mtpfs' as root and your Sony Walkman should automount automagically from thereon after and everything will be hunky dory on your Mandriva baby.

Btw, I am also quite impressed with the number of packages offered in Mandriva. Nearly all of the Python packages I am used to is in here and the package installer is space age fast!

Monday, February 22, 2010

Sneak peak preview of upcoming book

My friends at packt has sent another book for me to review! The Grok-1.0 is up and I have been looking for this as I have been looking for just an excuse to get my elbows dirty up to Python oil again!

You can see a preview of the book here:

Preview

Even better a sample chapter here:

Chapter 5

This is going to be good!