5 ### utility script for cleaning empty directories
6 ### useful to clean up /var/tmp/bootmedium
10 Usage: $0 dir [ .. dir]
11 scans all provided directories and prunes any empty directory under
12 the arg directories are always preserved
17 ### cleans up a everything under a given root
18 def clean_root (path, cleanRoot = False):
20 if not os.path.isdir(path):
24 files=os.listdir(path)
27 fullpath=os.path.join(path, x)
28 if os.path.isfile(fullpath):
29 # we do not remove files
31 elif os.path.isdir(fullpath):
32 clean_root(fullpath,True)
35 # rescan, and clean if empty
36 files=os.listdir(path)
40 ERROR_STR= """Error removing %(path)s, %(error)s """
46 if dir.index("/") != 0:
47 print "%s: args must be absolute paths"%(sys.argv[0])
48 print "%s: %s ignored"%(sys.argv[0],dir)
51 except OSError, (errno, strerror):
52 print ERROR_STR % {'path' : path, 'error': strerror }
54 if __name__ == '__main__':