Jump to content
  • Advertisement
Sign in to follow this  
krez

Dependencies Walker for a website

This topic is 2529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!