Archive for March, 2007

Quick Searches and Answers

Saturday, March 10th, 2007

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but you may still find them useful.

Python Tk GUI designer
A Python GUI builder for Tkinter? I’ll try it next time I need a GUI though I’m pretty happy with PythonCard.

Video does not play in Overlay mode on secondary display
How to make video work on your TV out with Beyond TV. With Vista it was just giving me a black screen.

Lightbox JS v2.0
A classy way to display thumbnails and their full size counter parts on a web site. It even degrades gracefully by simply linking to the image if you don’t have javascript. Of course some UI buffs don’t like “modal” dialogs, but it’s all in good fun.

PEP 333 — WSGI Spec
Have trouble understanding what WSGI is? Even after reading EVERY tutorial on it? Well, try reading the spec, it’s not very long, and by definition it has to give you enough information to implment it, so maybe it’s the answer.

Javascript – How to stop a page loading (ie emulate the stop button)
This link is for Mozilla brands and then use this for IE: document.execCommand(‘Stop’). So you’ll want to use both.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Python – How to Actually Use os.spawn in Windows

Friday, March 9th, 2007

Update: The subprocess module is the way to go for Python 2.4 and later. It aims to handle all your system calling needs, e.g., os.system, os.spawn*, os.popen*, popen2.*, and commands.*

Here’s my new snippet using subprocess to launch/spawn a process and not wait for it:

from subprocess import Popen
Popen([r'C:\Python24\Python.exe','C:\\AUTOMA~1\\AOSWEB\\ACTUAL~1.PY',str(order_no)])
#use win32api.GetShortPathName to get that 'C:\\AUTOMA~1\\AOSWEB\\ACTUAL~1.PY' thing, #Python/Windows aint like spaces ..

Here is my previous method which also seems to work:

Wow, I spent an hour trying to get os.spawn to work in Windows. The documentation does nothing!

Finally I found this thread where Doug Holton has written a nice “wrapper” for os.spawn:

import os

def run (program, *args):
   "Run external program, wait til it quits, and return the exit code"
   #Actually comment out line below on windows, I get attribute error here
   spawn = os.spawnvp #not available on windows though
   if os.name == "nt": spawn = os.spawnv
   return spawn(os.P_WAIT, program, (program,) + args)

def start (program, *args):
   "Start an external program and return immediately, returning proc id"
   #Actually comment out line below on windows, I get attribute error here
   spawn = os.spawnvp #not available on windows though
   if os.name == "nt": spawn = os.spawnv
   return spawn(os.P_NOWAIT, program, (program,) + args)

#example:
errcode = run('cp','index.html','index2.html')
if errcode == 0: #no error
   pid = start('cp','index2.html','index3.html')
else:
   print "error finding or copying the index.html file"

I think Windows commands have always been a sore spot for Python I’m afraid :-( Of course I would guess the blame lies with Windows like everything else in this world though.

[tags]os.spawn, spawn, popen, windows[/tags]

How to get Your Data Out of a Virtual Machine Disk (VMDK file)

Thursday, March 8th, 2007

At least for VMware on Windows they make this nice free disk mount utility for you.

With the VMware DiskMount utility, a VMware virtual disk file can be mounted as a Windows drive letter for read/write access to the files it contains. VMware DiskMount can run on Windows 2000/XP/2003 hosts.

So all you do is download it, install it, and then run some commands like these to mount your virtual disk:

cd "C:\Program Files\VMware\VMware DiskMount Utility"
vmware-mount.exe F: "C:\VM_XPPRO_BACKUP_W_QB7\My_Virtual_Machine.vmdk"

The general syntax is:
VMware-mount [driveletter:] [path-to-virtual-disk] [options]

[tags]VMware, virtual machine, mount, recovery, disk, vmdk[/tags]