Useful python bits.

I haven’t disappeared! I have just been incredibly busy with WWDC and related development work. Unfortunately, our stuff hasn’t been pushed outside of NDA’d channels, so I can’t start swamping my weblog with interesting code snippets related to my day job. I am building up quite the list of “to post” hacks, though.

I have been writing little bits of code to make eliminate repetitive tedium from my world. I’ll share what I can. All scripts are available on my public iDisk. Mount http://idisk.mac.com/bbum/Public/ in the Finder or visit my tedious file download page.

First up, if you use Python to bring sanity to shell scripting like tasks (a wonderful thing), then you likely need to execute lots of external commands in a shell like fashion. Process (formerly popen5) is an absolute god-send. It brings total sanity and a bit of security to invoking external commands from within Python:


pkgs = glob.glob('*.pkg')
for pkg in pkgs:
    process.call(['/usr/sbin/installer', '-pkg', pkg, '-target', '/'])

The above being a snippet from a script called bulk-install.py When invoked (typically by sudo python bulk-install.py it installs all pkgs and tarballs in the current working directory (tarballs are just untarred into /).

Just copy the two scripts into a directory, drop any packages and tarballs into the directory and run the script. It is the first thing I run whenever I install a new system. That way, I’m always guranteed to immediately have PyObjC, the Python bsddb and sqlite modules, Subversion, iPhoto, OCUnit, Keynote, the Python documentation and everything else I need regularly.



Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>