diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2010-01-28 00:49:55 +0100 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2010-01-28 00:49:55 +0100 |
commit | 7a4e280313f57f714c499aed2566c93744d60851 (patch) | |
tree | 851c5f33b4664d5708d6da3a6974e5a01eb493f3 /layman/utils.py | |
parent | c654e79fd18adb0e9f1cae6b783f8c81b39dda61 (diff) | |
download | layman-7a4e280313f57f714c499aed2566c93744d60851.tar.gz layman-7a4e280313f57f714c499aed2566c93744d60851.tar.bz2 layman-7a4e280313f57f714c499aed2566c93744d60851.zip |
Delete empty overlay directories
Diffstat (limited to 'layman/utils.py')
-rw-r--r-- | layman/utils.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/layman/utils.py b/layman/utils.py index 0a824f1..62014d9 100644 --- a/layman/utils.py +++ b/layman/utils.py @@ -29,7 +29,8 @@ __version__ = '$Id: utils.py 236 2006-09-05 20:39:37Z wrobel $' # #------------------------------------------------------------------------------- -import types, re +import types, re, os +from layman.debug import OUT #=============================================================================== # @@ -102,6 +103,21 @@ def path(path_elements): return pathname +def delete_empty_directory(mdir): + if os.path.exists(mdir) and not os.listdir(mdir): + # Check for sufficient privileges + if os.access(mdir, os.W_OK): + OUT.info('Deleting _empty_ directory "%s"' % mdir, 2) + try: + os.rmdir(mdir) + except OSError, error: + OUT.warn(str(error)) + else: + OUT.warn('Insufficient permissions to delete _empty_ folder "%s".' % mdir) + import getpass + if getpass.getuser() != 'root': + OUT.warn('Hint: You are not root.') + #=============================================================================== # # Testing |