Blinking snake

The fixhash module

Fixhash is intended to provide tools to run through all .py files in a cgi-bin directory and make sure that the #! (“shebang”) lines are correct for the Apache webserver, which depends upon the path after the #! being correct.  Naturally, you can use it to check any directory you want.  Using these tools makes the process  of mirroring a website on two or three differing platforms much easier.  For example, I once had my “official” webserver running Apache on Windows NT, but I mirrored the site at home and at work on two different versions of Linux.  The Python executable lived in three different places; using this script, I could drop the whole directory to whatever server I was working on, run the program provided with this distribution, and be done.


For the module:

import fixhash

For the program:

python [-r] <directory>


The following functions are provided in the fixhash module:


Initializes the module; obtains the path to the Python executable.  If v is non-zero, will print messages to stderr.
Returns the number of files modified.
Adds the correct #! line to the beginning of file name if needed, or modifies the existing #! line.
If arg is non-zero, prints messages to stderrd is the directory name, and dlist is the complete list of files in directory d, excluding . and .. (use os.listdir()).  This function runs rewritefile() on every file in the directory that needs it.  Zero-length files are skipped.
This function runs fixdirectory() on each directory in d (a list).  If r is non-zero, os.path.walk() is used to recursively fix the entire tree rooted at each directory in the list.  If v is non-zero, messages are printed to stderr.


Only three variables are found in fixhash.
“#!” + sys.executable
Number of files modified on the current run
The name of the program calling the fixhash module, so that it can avoid fixing that file


An example program is provided with this module,, which fixes the current directory, recursively and verbosely.

Previous Page
Table of Contents
Next Page

Main web site:

Valid HTML 4.01 Transitional