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 fixit.py program provided with this distribution, and be done.

Usage

For the module:

import fixhash
....

For the fixit.py program:

python fixit.py [-r] <directory>

Functions

The following functions are provided in the fixhash module:

initial(v=0)

Initializes the module; obtains the path to the Python executable.  If v is non-zero, will print messages to stderr.
getnfiles()
Returns the number of files modified.
rewritefile(name)
Adds the correct #! line to the beginning of file name if needed, or modifies the existing #! line.
fixdirectory(arg,d,dlist)
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.
fixhash(d,r,v)
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.

Variables

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

Example

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

Previous Page
Table of Contents
Next Page

Main web site:  http://www.pauahtun.org

Valid HTML 4.01 Transitional