Codebase list ros-ros / 40c44bc
enable rosclean on Windows (#198) * enable rosclean on Windows * Fix indent error. * convert long to string for get_human_readable_disk_usage() * On Windows, get disk usage by walking the tree * use rd /s /q to remove directory on Windows (#19) James Xu authored 5 years ago Dirk Thomas committed 5 years ago
1 changed file(s) with 18 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
110110 desc = get_human_readable_disk_usage(d)
111111 print("%s %s"%(desc, label))
112112
113 def _get_disk_usage_by_walking_tree(d):
114 total_size = 0
115 for dirpath, dirnames, filenames in os.walk(d):
116 for f in filenames:
117 fp = os.path.join(dirpath, f)
118 total_size += os.path.getsize(fp)
119 return total_size
120
113121 def get_human_readable_disk_usage(d):
114122 """
115123 Get human-readable disk usage for directory
123131 return subprocess.Popen(['du', '-sh', d], stdout=subprocess.PIPE).communicate()[0].split()[0]
124132 except:
125133 raise CleanupException("rosclean is not supported on this platform")
134 elif platform.system() == 'Windows':
135 total_size = _get_disk_usage_by_walking_tree(d)
136 return "Total Size: " + str(total_size) + " " + d
126137 else:
127138 raise CleanupException("rosclean is not supported on this platform")
128139
133144 :returns: disk usage in bytes (du -b) or (du -A) * 1024, ``int``
134145 :raises: :exc:`CleanupException` If get_disk_usage() cannot be used on this platform
135146 """
147 if platform.system() == 'Windows':
148 return _get_disk_usage_by_walking_tree(d)
149
136150 # only implemented on Linux and FreeBSD for now. Should work on OS X but need to verify first (du is not identical)
137151 cmd = None
138152 unit = 1
200214 break
201215 path = os.path.join(d, f)
202216 log_size -= get_disk_usage(path)
203 cmds = [['rm', '-rf', path]]
217 if platform.system() == 'Windows':
218 cmds = [['rd', '/s', '/q', path]]
219 else:
220 cmds = [['rm', '-rf', path]]
204221 try:
205222 _call(cmds)
206223 except: