pep381client / scripts / pep381checkfiles

#!/usr/bin/env python
import sys, os, shutil, optparse
from xml.etree import ElementTree
try:
    import pep381client
except ImportError:
    # See whether we are run out of a source tree
    module_path = os.path.join(os.path.dirname(sys.argv[0]), 
                               '..')
    if os.path.exists(module_path):
        sys.path.append(module_path)
    import pep381client

opts = optparse.OptionParser(usage="Usage: pep381checkfiles <targetdir>")
options, args = opts.parse_args()

if len(args) != 1:
    opts.error("You have to specify a target directory")

targetdir = args[0]
for package in os.listdir(os.path.join(targetdir, 'web', 'simple')):
    dir = os.path.join(targetdir, 'web', 'simple', package)
    if not os.path.isdir(dir):
        continue
    tree = ElementTree.fromstring(open(os.path.join(dir, 'index.html')).read())
    for a in tree.findall(".//a"):
        url = a.attrib['href']
        if not url.startswith('../../packages/'):
            continue
        url, md5 = url.split('#')
        url = url[len('../..'):]
        fn = os.path.join(targetdir, 'web', url)
        if not os.path.exists(fn):
            print "Missing file", fn
            continue
        if "md5="+hashlib.md5(open(fn,'b').read()) != md5:
            print "Bad md5", fn
            continue
    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.