This post originated from an RSS feed registered with Python Buzz
by Rand Anderson.
Original Post: Instant Webserver Here
Feed Title: Python Postings
Feed URL: http://www.executableabstractions.com/weblog/Python/rss.xml
Feed Description: On my explorations of python
Pretty funny (maybe profound, actually) how a one-liner using a core package of Python suddenly gets such attention in the community.
As I mentioned the other day, I also found this 'instant webserver' functionality compelling; so much so, I wanted to make it even more accessible to common ad-hoc contexts. Improving accessibility to tools has an exponential (or at least multiplicative) effect on their value to the user.
The following is specific to the Windows platform; but surely a similarly simple (or simpler) solution exists for your favorite Linux distro.
Improved Shell Access
First, create a two-line batch file:
cd %1
python -c "import SimpleHTTPServer; SimpleHTTPServer.test()"
and save it to a folder that is in your system path. I put mine in c:\utils, and named it iws.cmd.
Now, at any shell prompt, I can enter
c:\iws serve-dir
where serve-dir is the name of the directory that I want to serve up via HTTP. For example, to serve up the current working dir, just enter
c:\foo>iws .
Direct Explorer Access
Now provide easy GUI access to this same batch file.
Two options here, one requires registry editing, the other doesn't.
Option #1: No Registry Edit Required
Just create a short-cut in your SendTo folder that points to your iws batch-file, and you're done. Apparently the send-to folder essentially maps the selected element in Explorer as a first parameter to the target.
Option #2: Registry Edit Required
[WARNING/DISCLAIMER: This option requires the use of the Registry Editor (REGEDIT.EXE). Changes made to the Windows registry happen immediately, and no backup is automatically made. Do not edit the Windows registry unless you are confident about doing so.
Microsoft have issued the following warning with respect to the Registry Editor:
"Using Registry Editor incorrectly can cause serious, system-wide problems that may require you to re-install Windows to correct them. Microsoft cannot guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk."]
If you have authorization to edit your registry, and are comfortable with doing so, then you can make the access point slightly cleaner semantically while also requiring less menu navigation. You need to add a new key in 'My Computer\HKEY_CLASSES_ROOT\Folder\shell' named 'Instant Web Server', and under that a key named 'command' with a REG_SZ value that points to your batch file and follows it with a reference to the %L variable. On my machine, this full value looks like this: "c:\utils\iws.cmd" "%L" (all quotes included).
Now in Windows Explorer, right click on any folder...
Sweetness!
Next steps:
Add a line to the iws.cmd file to, after starting the web server, open up a new tab in a current firefox window and navigate to the url