import os import argparse import sys os.chdir("../../../..") def dirc(*args): """contents at path pointed to by args if it's a directory or empty list if not""" path = os.path.join(*args) if os.path.isdir(path): return sorted(os.listdir(path)) return [] def le(a, b): c = min(len(a), len(b)) return a[:c] <= b[:c] if __name__ == "__main__": args = sys.argv[1:] start = args[0] if args else "" end = args[1] if len(args) > 1 else "" for d1 in sorted(os.listdir(".")): if not le(start, d1): continue if not le(d1, end): break # if d1 == "other": continue for d2 in dirc(d1): if not le(start, d1 + d2): continue if not le(d1 + d2, end): break print "#", d1, d2 for d3 in dirc(d1, d2): try: pub = dirc(d1, d2, d3, "Public") if pub: print d3, pub except OSError as e: print e