3 ### utility script for cleaning empty directories
4 ### useful to clean up /var/tmp/bootmedium
8 Usage: $0 dir [ .. dir]
9 scans all provided directories and prunes any empty directory under
10 the arg directories are always preserved
15 ### cleans up a everything under a given root
16 def clean_root (path, cleanRoot = False):
18 if not os.path.isdir(path):
22 files=os.listdir(path)
25 fullpath=os.path.join(path, x)
26 if os.path.isfile(fullpath):
27 # we do not remove files
29 elif os.path.isdir(fullpath):
30 clean_root(fullpath,True)
33 # rescan, and clean if empty
34 files=os.listdir(path)
38 ERROR_STR= """Error removing %(path)s, %(error)s """
44 if dir.index("/") != 0:
45 print "%s: args must be absolute paths"%(sys.argv[0])
46 print "%s: %s ignored"%(sys.argv[0],dir)
49 except OSError, (errno, strerror):
50 print ERROR_STR % {'path' : path, 'error': strerror }
52 if __name__ == '__main__':