# Author : Scott Hathaway # Version : 0.0.1 # Date : 3/22/2002 # Purpose : This script creates an html report of a website # : that includes the total number of files, the # : total number of files that have another file # : linked to them, and the number that have no links. # Notes : This script takes two command-line arguments as follows - # : site_info.py "c:/path/to/website/" "c:/file/to/write.html" # Credits : DirectoryWalker and normalDate are # : not my scripts. If you know who wrote them, # : please let me know and I will give the proper # : credit. # Misc : More free scripts and programs at - # : www.hcsprogramming.com # : scott@hcsprogramming.com # : Feel free to improve this program and send me the changes. # : I will post them here for others to download. import DirectoryWalker import os import sys from normalDate import ND dwFiles = DirectoryWalker.DirectoryWalker(sys.argv[1]) allFiles=[] checkedFiles=[] unCheckedFiles=[] referencedFiles=[] unReferencedFiles=[] i=1 for file in dwFiles: if os.path.exists(file) and os.path.isfile(file) and os.path.basename(file) != '.' and os.path.basename(file) != '..': file = file.lower() file = file.replace('\\','/') allFiles.append(file) file = str(file) if (file.endswith('html')==1) or (file.endswith('htm')==1) or (file.endswith('asp')==1) or (file.endswith('php')==1) or (file.endswith('js')==1) or (file.endswith('vbs')==1) or (file.endswith('inc')==1) or (file.endswith('css')==1) : checkedFiles.append(file) else: unCheckedFiles.append(file) a = "\n" a += "\nSite Information\n" a += "\n" a += "

Site Information: " + str(sys.argv[1]) + " on " + str(ND()) + "

\n" a += "" a += "\n" a += "\n" a += "\n" b = "
Total Files     " + str(len(allFiles)) + "
Checked Files     " + str(len(checkedFiles)) + "
UnChecked Files     " + str(len(unCheckedFiles)) + "
\n" b += "


\n" b += "File Mapping
\n" t = '' s = '' fc = '' for cFile in checkedFiles: print cFile b += "   " + cFile + "
\n" try: fc = open(cFile,'r').read() except: fc = open(cFile,'r').read() fc = fc.lower() for aFile in allFiles: found = 0 fullName = aFile aFile = os.path.basename(aFile) t = '"' + aFile.lower() s = fc.find(t) if(s>=0): found=1 t = "'" + aFile.lower() s = fc.find(t) if(s>=0): found=1 t = '/' + aFile.lower() s = fc.find(t) if(s>=0): found=1 t = '\\' + aFile.lower() s = fc.find(t) if(s>=0): found=1 if(found==1): if(fullName not in referencedFiles): referencedFiles.append(fullName) b += "      " + fullName + "
\n" b+= "


\n" b += "Unreferenced Files
\n" for aFile in allFiles: found=0 if aFile in referencedFiles: found=1 if found==0: b += "   " + aFile + "
\n" unReferencedFiles.append(aFile) a += "Linked Files     " + str(len(referencedFiles)) + "\n" a += "Unlinked Files     " + str(len(unReferencedFiles)) + "\n" b += "" html = str(a) + str(b) try: fileToSave = sys.argv[2] except: fileToSave = "c:/siteInfo.html" r = open(fileToSave,'w').write(html)