Home

Create Dependency Tree

This is a simple utility written in Python 2.3 that allows you to look at files and see the dependencies that lie therein. It was written using the basic Python distribution and Tkinter is used for the GUI, so this should work on any system that has Python installed. This has been tested on Windows and Knoppix and appears to work equally well in both environments. It was written to work mainly with web files (html, asp, php, etc.) but can theoretically be updated to work with any sort of file you would like. It is released under the MIT license, so feel free to bang away on this as much as you want.

The screen is pretty simple. When you start the program, you are shown a blank screen with the four buttons shown. It also tells you where it will put the output files when you process the files you will select. Do not worry about the output directory existing. If it does not exist, it is created for you.

Using the program

To start, click 'Select Files'. This will bring up a selection screen like so:

You can browse around and select any files you want, adding as you go. If you notice, the extensions available correspond with the .pat files that are located in the directory of the application. More on these later. When you are done adding files, click 'Process Files'. The label at the bottom of the screen that says 'Status' should update with each file that is being processed. When the application is done, it will say 'Status' again. At any time you can clear the entire list by clicking 'Clear List' or select individual items and click 'Clear Item'. Output files are put into the directory specified in the text above the list box. When you open one of the files in the output directory, it should look lik this:

The images can be made to appear by copying collapse.gif and expand.gif into the output directory. When you first open the file, only the top entry will show. Click on it to expand the tree beneath it. When you hover the mouse over one of the entries, it will tell you the line number and show the text of the line from the file above that is referencing the given file. In the case of circular references (often occurs with a page that posts to a page and then redirects back to the page that called it), it will end up failing on processing the page because it will detect that it has already processed the file and will tell you so.

Changing Search Criteria

The types of files and criteria for searching them are controlled by .pat files that reside in the application directory. The pattern for naming these files is <extension>.pat. By default patterns for htm, html, asp and php files are included. If you include a file to be searched (for example, somestuff.txt), then all of the defined patterns will be used to search the file. If the file extension is recognized, only that files patterns are used. The .pat files consist of a regular expression on each line for the desired patterns to look for. Here is the sample php.pat file

include\s*\(\"?(?P<fileName>.*?)\"?\)
header\s*\(\s*"Location:\s*(?P<fileName>.*?)\"?\)
action\s*=\s*\"?(?P<fileName>.*?)(?:\"|\s|\?|;|\+|\n)

This uses Python regular expressions. The important part to allow it to check files on down the tree is ?P<fileName>, which should capture the characters that would make up the file being linked to. The power of using this approach is

The program makes some assumptions about directories to help with processing. It can process ./ and ../ and any file that doesn't have any kind of directory attached to it will assume the file is in the same directory. It does its best to construct paths based on the current directory the file you are processing is in and any related information. If it doesn't find the file, the program will enter the attempted search path in the output file and tell you it failed.

Planned Updates

Availability

Both the source code and a binary (for windows built using py2exe) are available for your use. Any feedback, comments and updates are always welcome. Any suggestions will be integrated at my earliest convenience.

Windows Binary - Simply unzip to a directory of your choice, preserving the directory structure

Source Files - Contains the source files, including the license

Both files contain collapse.gif and expand.gif which should go in the outputfiles directory