Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dependencies Walker for a website

Started by krez Jan 7, 2012 at 1:16 PM 2 replies 1.7k views
Original Post
krez
krez
Can anyone recommend a program that can scan a directory tree for a website and report which files depend on which others, and which are orphaned? I'm thinking something like Dependency Walker but for PHP and related files? Thus far my google-fu has failed me.

Thanks!
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
the_edd
the_edd
Depends what you mean by "directory tree for a website".

Though slashes appear in a URL, they don't necesarily correspond to path segregations on the server. It's quite common that there is a URL<->server-file-tree correspondance, but even when this is the case, you don't necessarily have permission to go poking around in those directories via your browser (you'll get an appropriate HTTP response telling you so, or a 404, etc, depending on the request handler).

If you have access to the server, I'm sure it would be simple enough to knock-up something with a regex.
krez
krez
Sorry, I meant for the developer of the website, with either access to the server or a local copy. I have inherited a sloppy mess of a website and need to clean things up.

I have played with regex some, but such a thing is beyond my abilities at this time. While it would be good practice to figure it out, I'm more interested in getting the work done, especially if there is some tool freely available to help.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
the_edd
the_edd
It shouldn't take more than 30 minutes to learn how to write an appropriate regex.

Here's some python code that recursively scans a directory for C-style includes.


# Pass the root directory to scan on the command line
import re, os, collections, sys

pj = os.path.join
rgx = re.compile(r'#\s*include\s*[<"](.*)[>"].*')

includes = collections.defaultdict(list)

for path, dirs, files in os.walk(sys.argv[1]):
for f in files:
full = pj(path, f)
with open(full, 'rb') as fd:
for line in fd:
m = rgx.match(line)
if m:
includes[full].append(m.group(1))

for f, incs in includes.iteritems():
print f, 'includes:'
print incs
print '-----'


(The investment evidently pays off rather quickly...)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.