Library wish: rchown and rchmod
Gabriel Ambuehl
gabriel_ambuehl at buz.ch
Sat Sep 29 10:03:29 EDT 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hello,
I'd like to suggest two additional library functions for the os
module:
rchown and rchmod (recursive chown and recursive chmod) (I don't care
for the name but only for the functionality ;-).
Sample implementations
def rchown(dir, uid, gid):
try:
if (os.path.isdir(dir)):
direntries=os.listdir(os.path.abspath(dir))
for direntry in direntries:
direntry=os.path.abspath(direntry)
if (os.path.isdir(direntry)):
os.chown(direntry, uid, gid)
current_wd=os.getcwd()
os.chdir(direntry)
os.rchown(direntry, uid, gid)
os.chdir(current_wd)
else:
os.chown(direntry, uid, gid)
else:
os.chown(dir, uid, gid)
except (IOError, os.error), why:
print "rchown %s: %s" % (str(dir), str(why))
def rchmod(dir, mode):
try:
if (os.path.isdir(dir)):
direntries=os.listdir(os.path.abspath(dir))
for direntry in direntries:
direntry=os.path.abspath(direntry)
if (os.path.isdir(direntry)):
os.chmod(direntry, mode)
current_wd=os.getcwd()
os.chdir(direntry)
rchmod(direntry, mode)
os.chdir(current_wd)
else:
os.chmod(direntry, mode)
else:
os.chmod(direntry, mode)
except (IOError, os.error), why:
print "rchmod %s: %s" % (str(dir), str(why))
Thoughts?
Best regards,
Gabriel
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5i
iQEVAwUBO7XGpcZa2WpymlDxAQG0UQf/XvEjwBatn9jK/otIv7IORAAJrUWcP97g
K+OvuuRZ3zkHGiDAwqsZ4LZrsxR/VotroEvPFYrw+Kp9VGqvXm5Q8dpg+Fpgz+dg
yYa43hAd6UHVWUa9wWVZ1pPdZfO07Sj+Ue3Zsl/NOcrO7uFOUgZVUEp5G5uaG2qd
mIOsBJYEtTS5R0yM40hb/pYeY1EvNhcFFJa83FXgckSwVCi75DGe5E9OtN1yovcO
6r+65crHbtIYD9foto2PJfIoaJ1L4Lhh7dyAgDrAwWZozk+rawodwlzjzSaoa45n
Vv1MlneEDg24HWFwYXbg5L/DpcFssKtcYd8b+EntaDet8mvAAV7Ocg==
=SOX9
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list