#!/usr/bin/env python import re, sys, os from stat import * import getpass, grp def usage(): usage_str = "Usage: " + sys.argv[0] + """ Looks up each file and subdirectory under owned by the user, and changes its mode to world readable. If the file is executable, then the file/directory will also be made executable. """ sys.stderr.write(usage_str) sys.exit(1) def publ_access(path, uid, prefix): """Make public the directory tree under path. prefix helps in displaying the tree during the recursive calls.""" print prefix, os.path.basename(path) try: stat_return = os.lstat(path) except OSError, detail: print >> sys.stderr, "lstat ", path, " failed: ", \ detail.strerror, "\n" return if uid == stat_return[ST_UID]: mode = stat_return[ST_MODE] executable = mode & 0100 if os.path.isdir(path) or executable: # or # if ST_ISDIR(mode): newmode = mode | 0555 else: newmode = mode | 0444 try: os.chmod(path, newmode) except OSError, detail: sys.stderr.write("chmod " + path + " failed: " + detail.strerror + "\n") return if os.path.isdir(path): for file in os.listdir(path): publ_access(os.path.join(path, file), uid, prefix + " ") "main" argc = len(sys.argv) if 2 < argc : usage() uid = os.getuid() path = sys.argv[1] publ_access(path, uid, "")