pep381client / scripts / pep381checkfiles

#!/usr/bin/env python
import sys, os, shutil, optparse, hashlib, time
from xml.etree import ElementTree
    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):
    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]
incomplete_packages = set()
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):
    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/'):
        url, md5 = url.split('#')
        url = url[len('../../'):]
        fn = os.path.join(targetdir, 'web', url)
        if not os.path.exists(fn):
            print "Missing file", fn
        if "md5="+hashlib.md5(open(fn,'rb').read()).hexdigest() != md5:
            print "Bad md5", fn

if incomplete_packages:
    s = pep381client.load(targetdir)
    for i in range(10):
            print "Synchronization in progress, waiting"
    # Reload pickled state
    s = pep381client.load(targetdir)
    s.projects_to_do += incomplete_packages
    # claim that a synchronization was aborted and 
    # needs to be restarted
    s.last_started = s.last_completed
    print "Todo list updated; run pep381run now"
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
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.